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: check for more usage errors #1978

Closed
shadowspawn opened this issue Aug 23, 2023 · 7 comments
Closed

Poll: check for more usage errors #1978

shadowspawn opened this issue Aug 23, 2023 · 7 comments

Comments

@shadowspawn
Copy link
Collaborator

shadowspawn commented Aug 23, 2023

Commander could check for more usage errors. These are probably a win for new programs and people new to Commander, but may mean more work when upgrading Commander in an old program (to fix problems that had not been noticed previously).

Have a look and upvote 👍 errors you wish Commander would check for, and downvote 👎 errors that would get in the way of how you are using Commander or you wouldn't want to fix when upgrading.

@shadowspawn
Copy link
Collaborator Author

shadowspawn commented Aug 23, 2023

  1. Calling program.parse() when an action handler or hook is async . Should be calling program.parseAsync() if any action handler or hook is async.

Note: this error can not be detected except during parsing, so may not show up on all calls.

program
   .action(async() => { console.log('async'); })

program.parse(); // oops, should be `program.parseAsync()`

@shadowspawn
Copy link
Collaborator Author

shadowspawn commented Aug 23, 2023

  1. Adding options with overlapping flags.
program
   .option('-p, --print')
   .option('-p, --port'); // oops, already using '-p'

@shadowspawn
Copy link
Collaborator Author

  1. Adding commands with overlapping names.
program.command('runnable')
   .alias('run')
   // more configuration

program.command('run') // oops, already using 'run'
   // more configuration

@shadowspawn
Copy link
Collaborator Author

shadowspawn commented Aug 23, 2023

  1. Calling .parse() more than once. Parse leaves behind state, so the intention is make a new program for every parse.
program.parse(['--port', '80'], { from: 'user' });
assert_deep_equal(program.opts(), { port: 80 });
program.parse(['--name', 'foo'], { from: 'user' });
assert_deep_equal(program.opts(), { name: 'foo' }); // oops, also has port from first parse

@shadowspawn
Copy link
Collaborator Author

shadowspawn commented Aug 23, 2023

  1. Calling .parse() on a subcommand.

This isn't technically wrong, but probably a mistake.

program.command('sub')
   .action(() => { console.log('Thanks for calling subcommand'); })
   .parse(); // oops, should be calling `program.parse()`

@shadowspawn shadowspawn pinned this issue Aug 23, 2023
@shadowspawn
Copy link
Collaborator Author

shadowspawn commented Aug 24, 2023

  1. Enforce format of option flags.
program
   .option('-en', '--environment') // oops, short option should be a single character
   .option('-h, -?, --help'); // oops, short or long or both, but not more than one of each

@shadowspawn
Copy link
Collaborator Author

Not much feedback on this. Numbers at 21 Jan 2024: 2 3 3 1 1 1

Adding check for conflicting commands (#2059) and options (#2055) in Command v12.

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

1 participant