Skip to content

Commit

Permalink
rename to halt-at-non-option
Browse files Browse the repository at this point in the history
  • Loading branch information
wmertens committed Oct 9, 2018
1 parent 84df080 commit b43685c
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 13 deletions.
14 changes: 7 additions & 7 deletions README.md
Expand Up @@ -319,25 +319,25 @@ node example.js -a 1 -c 2
{ _: [], a: 1, b: undefined, c: 2 }
```
### stop at unknown
### halt at non-option
* default: `false`.
* key: `stop-at-unknown`.
* key: `halt-at-non-option`.
Should parsing stop at the first unknown argument?
Should parsing stop at the first text argument? This is similar to how e.g. `ssh` parses its command line.
_If disabled:_
```sh
node example.js -a b -x y
{ _: [ 'b', 'y' ], a: true, x: true }
node example.js -a run b -x y
{ _: [ 'run', 'b', 'y' ], a: true, x: true }
```
_If enabled:_
```sh
node example.js -a b -x y
{ _: [ 'b', '-x', 'y' ], a: true }
node example.js -a run b -x y
{ _: [ 'run', 'b', '-x', 'y' ], a: true }
```
## Special Thanks
Expand Down
4 changes: 2 additions & 2 deletions index.js
Expand Up @@ -22,7 +22,7 @@ function parse (args, opts) {
'populate--': false,
'combine-arrays': false,
'set-placeholder-key': false,
'stop-at-unknown': false
'halt-at-non-option': false
}, opts.configuration)
var defaults = opts.default || {}
var configObjects = opts.configObjects || []
Expand Down Expand Up @@ -282,7 +282,7 @@ function parse (args, opts) {
} else if (arg === '--') {
notFlags = args.slice(i + 1)
break
} else if (configuration['stop-at-unknown']) {
} else if (configuration['halt-at-non-option']) {
notFlags = args.slice(i)
break
} else {
Expand Down
20 changes: 16 additions & 4 deletions test/yargs-parser.js
Expand Up @@ -2384,25 +2384,37 @@ describe('yargs-parser', function () {
})
})

describe('stop-at-unknown', function () {
describe('halt-at-non-option', function () {
it('gets the entire rest of line', function () {
var parse = parser(['--foo', './file.js', '--foo', '--bar'], {
configuration: {'stop-at-unknown': true},
configuration: { 'halt-at-non-option': true },
boolean: ['foo', 'bar']
})
parse.should.deep.equal({foo: true, _: ['./file.js', '--foo', '--bar']})
parse.should.deep.equal({ foo: true, _: ['./file.js', '--foo', '--bar'] })
})

it('is not influenced by --', function () {
var parse = parser(
['--foo', './file.js', '--foo', '--', 'barbar', '--bar'],
{configuration: {'stop-at-unknown': true}, boolean: ['foo', 'bar']}
{ configuration: { 'halt-at-non-option': true }, boolean: ['foo', 'bar'] }
)
parse.should.deep.equal({
foo: true,
_: ['./file.js', '--foo', '--', 'barbar', '--bar']
})
})

it('is not influenced by unknown options', function () {
var parse = parser(
['-v', '--long', 'arg', './file.js', '--foo', '--', 'barbar'],
{ configuration: { 'halt-at-non-option': true }, boolean: ['foo'] }
)
parse.should.deep.equal({
v: true,
long: 'arg',
_: ['./file.js', '--foo', '--', 'barbar']
})
})
})
})

Expand Down

0 comments on commit b43685c

Please sign in to comment.