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

Support for descriptions for command arguments #1333

Closed
crfrolik opened this issue Aug 18, 2020 · 3 comments
Closed

Support for descriptions for command arguments #1333

crfrolik opened this issue Aug 18, 2020 · 3 comments

Comments

@crfrolik
Copy link

crfrolik commented Aug 18, 2020

Is it possible to add a description to each command argument that will automatically be shown in the help?

This is currently possible for options, e.g.:

program
  .option('-d, --debug', 'output extra debugging')
  .option('-s, --small', 'small pizza size')
  .option('-p, --pizza-type <type>', 'flavour of pizza');

However, I don't see a way to do it for commands.

program
  .command('clone <source> [destination]')
  .description('clone a repository into a newly created directory')
  .action((source, destination) => {
    console.log('clone command called');
  });

Completely fabricated idea of how this might be done:

program
  .command('clone <source> [destination]')
  .description('clone a repository into a newly created directory')
  .commandArgument("source", "A URL that indicates the source for the clone operation")
  .commandArgument("destination", "A directory to clone into")
  .action((source, destination) => {
    console.log('clone command called');
  });
@shadowspawn
Copy link
Collaborator

It is possible! The .description() method allows a second parameter with descriptions of the command arguments.
The parameter is a hash with key of the argument name and value of the description. Using this adds an "Arguments:" section in the built-in help.

program
  .arguments('<file>')
  .description('print target file', {
    file: 'file to process'
  });

@crfrolik
Copy link
Author

Oh, this is awesome! Thanks for the quick response!

@shadowspawn
Copy link
Collaborator

Documented in Commander v6.2.0

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

No branches or pull requests

2 participants