Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Feature] Tagline in help text #2337

Open
bojavou opened this issue Jun 10, 2023 · 5 comments
Open

[Feature] Tagline in help text #2337

bojavou opened this issue Jun 10, 2023 · 5 comments

Comments

@bojavou
Copy link

bojavou commented Jun 10, 2023

Hello! I'd like to include a tagline in the help text. Maybe with a description function.

yargs(..)
  .scriptName('gadget')
  .description('Never eat a pirate. He'll spend the rest of his after hunting you.')
gadget <command>

Never eat a pirate. He'll spend the rest of his afterlife hunting you.

Commands:
  gadget mix   Mix it up well
  gadget stir  Stir a little

Options:
  --help     Show help                                                 [boolean]
  --version  Show version number                                       [boolean]

Not enough non-option arguments: got 0, need at least 1

You can kind of do it with usage(), but it shows up in the commands list which I don't want.

yargs(..)
    .scriptName('gadget')
    .usage('$0 <command>', 'Never eat a pirate. The indigestion is terrible.')
gadget <command>

Never eat a pirate. The indigestion is terrible.

Commands:
  gadget <command>     Never eat a pirate. The indigestion is terrible.[default]
  gadget mix           Mix it up well
  gadget stir          Stir a little

Options:
  --help     Show help                                                 [boolean]
  --version  Show version number                                       [boolean]

Not enough non-option arguments: got 0, need at least 1

The epilog is also nice but it puts it at the end. I'd rather it have right up at the top as a nice header.

yargs(..)
  .scriptName('gadget')
  .epilog('Never eat a pirate. Zombies are much tastier.')
gadget <command>

Commands:
  gadget mix   Mix it up well
  gadget stir  Stir a little

Options:
  --help     Show help                                                 [boolean]
  --version  Show version number                                       [boolean]

Never eat a pirate. Zombies are much tastier.

Not enough non-option arguments: got 0, need at least 1
bojavou added a commit to bojavou/yargs that referenced this issue Jun 10, 2023
@bojavou
Copy link
Author

bojavou commented Jun 10, 2023

Submitted some code in #2338, to give it something real for discussion.

@shadowspawn
Copy link
Member

My initial impression is that usage() is the right method for setting the command usage and description.

But .usage() is also used as an alias for ".command()` and setting the default command, as you discovered.

I wonder if the default-command behaviour should only be triggered if there is a builder or handler? (Would this break any reasonable legacy use cases?)

@shadowspawn
Copy link
Member

shadowspawn commented Jun 11, 2023

Having second thoughts about overloading .usage()! It might fit into the existing api but is not a direct match for the goal.

A method called .desc() or .description() would be more explicit. In practice it will usually only be called on the top-level command since the methods for creating subcommands have a description parameter.

desc is not as nice to read, but matches the property name when a subcommand is created using a json description. (The property exported from a module used with .commandDir() is describe, but .describe() is used for describing options and positionals.)

(I need to do some more reading in the existing API to get a better idea of the existing patterns.)

@shadowspawn
Copy link
Member

desc is not as nice to read, but matches the property name when a subcommand is created using a json description.

Red herring, the code supports desc or describe or description! Ref: #917

@shadowspawn
Copy link
Member

shadowspawn commented Jun 11, 2023

I do see the subcommand description displayed in subcommand help in a very simple test program, but the description goes away when I add a custom usage. I see in #1830 (comment) that the subcommand description is actually not intended to be displayed in the subcommand help. So this is in line with what you thought, that the description is intended to appear in the list of subcommands.

I note that a few of the example files put extra lines into the usage string. So that looks like the simple and historical work-around.

.usage('Count the lines in a file.\nUsage: $0')

(Rather more complicated question than I expected!)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants