Skip to content
Myr

Fix: Long-only flags would not take values

Before adoption: this commit came in with the history the project adopted, so no landing records it.

For '--longflag [value]', '--longflag' was being mistaken for the short option, and '[value]' as the long option. This patch fixes this by checking if the second flag argument starts with [ or < which indicates a value being expected.

authored by Felix Geisendörfer · committed by Felix Geisendörfer · parent d3deb36 · Browse files · 2 files+14 added−1 removed
This commit

State

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Diff stats

2 files+14 added−1 removed

  • tests:+13 added−0 removed
  • other:+1 added−1 removed

2 files+14 added−1 removed

modified:lib/commander.js+1 added-1 removed
43 unmodified lines
44 this.required = ~flags.indexOf('<');45 this.optional = ~flags.indexOf('[');46 this.bool = !~flags.indexOf('-no-');47 flags = flags.split(/[ ,|]+/);48 if (flags.length > 1) this.short = flags.shift();48 if (flags.length > 1 && !/^[[<]/.test(flags[1])) this.short = flags.shift();49 this.long = flags.shift();50 this.description = description;51}52
856 unmodified lines
added:test/test.options.large-only-with-value.js+13 added