Skip to content

Commit f575021

Browse files
authored
docs: ordering of positional and option does not matter (#46)
* docs: ordering of positional and option does not matter * Add test to match README FAQ
1 parent 3dc361c commit f575021

2 files changed

Lines changed: 13 additions & 1 deletion

File tree

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -150,7 +150,7 @@ const { flags, values, positionals } = parseArgs(argv, options);
150150
### F.A.Qs
151151

152152
- Is `cmd --foo=bar baz` the same as `cmd baz --foo=bar`?
153-
- Yes, if `withValue: ['foo']`, otherwise no
153+
- yes
154154
- Does the parser execute a function?
155155
- no
156156
- Does the parser execute one of several functions, depending on input?

test/index.js

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -228,6 +228,18 @@ test('args are passed "withValue" and "multiples"', function(t) {
228228
t.end();
229229
});
230230

231+
test('order of option and positional does not matter (per README)', function(t) {
232+
const passedArgs1 = ['--foo=bar', 'baz'];
233+
const passedArgs2 = ['baz', '--foo=bar'];
234+
const passedOptions = { withValue: ['foo'] };
235+
const expected = { flags: { foo: true }, values: { foo: 'bar' }, positionals: ['baz'] };
236+
237+
t.deepEqual(parseArgs(passedArgs1, passedOptions), expected, 'option then positional');
238+
t.deepEqual(parseArgs(passedArgs2, passedOptions), expected, 'positional then option');
239+
240+
t.end();
241+
});
242+
231243
test('correct default args when use node -p', function(t) {
232244
const holdArgv = process.argv;
233245
process.argv = [process.argv0, '--foo'];

0 commit comments

Comments
 (0)