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

Poll: change api for adding command arguments? #1471

Closed
shadowspawn opened this issue Feb 13, 2021 · 5 comments
Closed

Poll: change api for adding command arguments? #1471

shadowspawn opened this issue Feb 13, 2021 · 5 comments

Comments

@shadowspawn
Copy link
Collaborator

shadowspawn commented Feb 13, 2021

The syntax for adding command arguments which have help descriptions is quite different from the rest of the API, and arguments and options are added quite differently although they could be similar. (Prompted by discussion about offering .choices() for arguments in #1458.)

A couple of questions for feedback via reactions or comments.

@shadowspawn
Copy link
Collaborator Author

shadowspawn commented Feb 13, 2021

  1. Argument descriptions. Current syntax:
program
  .arguments('<username> [password]')
  .description('test command', {
    username: 'user to login',
    password: 'password for user, if required'
  })

Suggested syntax:

program
  .description('test command')
  .argument('<username>', 'user to login')
  .argument('[password]', 'password for user, if required')

Should .argument(usage, description) replace the use of .description(cmdDesc, argsDesc) for specifying help for command-arguments? 👍 👎

@shadowspawn
Copy link
Collaborator Author

shadowspawn commented Feb 13, 2021

  1. Adding arguments. Current syntax:
program
  .arguments('<cmd> [args]');

Suggested syntax:

program
  .argument('<cmd>')
  .argument('[args]');

Should .argument() replace the use of .arguments() for adding command-arguments? 👍 👎

@shadowspawn shadowspawn pinned this issue Feb 13, 2021
@shadowspawn shadowspawn unpinned this issue Mar 13, 2021
@shadowspawn
Copy link
Collaborator Author

Not huge numbers, but unanimous positive response after a month. (Thanks for feedback.)

  1. 8 👍
  2. 5 👍

@NicolasThierion
Copy link

NicolasThierion commented Jun 21, 2021

I found I can coerce options with a function as a third parameter.
Is there any plan to allow argument corecion the same way with this new syntax ?

Eg:

program
  .argument('<username>', 'user to login', (value) => value.toLowerCase())

@shadowspawn
Copy link
Collaborator Author

shadowspawn commented Jun 21, 2021

Yes, planned and done. .argument() supports coercion (custom processing) and default value, following same pattern as .option(). Will be released in Commander v8.

#1508

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