Skip to content

git-style subcommands mess up argument order when using boolean flags #508

Closed
@mal

Description

@mal

index.js

var command = require('commander')

var cmd = command
  .command('hello', 'description')
  .parse(process.argv)

index-hello.js

var command = require('commander')

var cmd = command
  .option('--dry-run', 'prints actions, but takes none')
  .parse(process.argv)

console.log('opts', cmd.opts())
console.log('args', cmd.args)

output

$ node index.js hello 1 2 --dry-run 3 4 5 6
opts { dryRun: true }
args [ '1', '2', '4', '5', '6', '3' ]

Note how 3 has been shifted to the end. This really messes with you when working with subcommands that expect a specific argument ordering.

Found and tested against commander@2.9.0

Activity

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

Metadata

Metadata

Assignees

Labels

bugCommander is not working as intended

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions