Skip to content

Poll: check for more usage errors #1978

Closed

Description

@shadowspawn

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.

Activity

  1. shadowspawn commented on Aug 23, 2023

    @shadowspawn
    CollaboratorAuthor
    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()`
    
  2. shadowspawn commented on Aug 23, 2023

    @shadowspawn
    CollaboratorAuthor
    1. Adding options with overlapping flags.
    program
       .option('-p, --print')
       .option('-p, --port'); // oops, already using '-p'
    
  3. shadowspawn commented on Aug 23, 2023

    @shadowspawn
    CollaboratorAuthor
    1. Adding commands with overlapping names.
    program.command('runnable')
       .alias('run')
       // more configuration
    
    program.command('run') // oops, already using 'run'
       // more configuration
    
  4. shadowspawn commented on Aug 23, 2023

    @shadowspawn
    CollaboratorAuthor
    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
    
  5. shadowspawn commented on Aug 23, 2023

    @shadowspawn
    CollaboratorAuthor
    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()`
    
  6. pinned this issue on Aug 23, 2023
  7. shadowspawn commented on Aug 24, 2023

    @shadowspawn
    CollaboratorAuthor
    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
    
  8. unpinned this issue on Jan 20, 2024
  9. shadowspawn commented on Jan 20, 2024

    @shadowspawn
    CollaboratorAuthor

    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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions