forked from tj/commander.js
-
-
Notifications
You must be signed in to change notification settings - Fork 1
/
args.literal.test.js
27 lines (24 loc) · 1.18 KB
/
args.literal.test.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
const commander = require('../');
// Utility Conventions: http://pubs.opengroup.org/onlinepubs/9699919799/basedefs/V1_chap12.html#tag_12_02
//
// 12.2 Utility Syntax Guidelines, Guideline 10:
// The first -- argument that is not an option-argument should be accepted as a delimiter indicating the end of options. Any following arguments should be treated as operands, even if they begin with the '-' character.
test('when arguments includes -- then stop processing options', () => {
const program = new commander.Command();
program
.option('-f, --foo', 'add some foo')
.option('-b, --bar', 'add some bar');
program.parse(['node', 'test', '--foo', '--', '--bar', 'baz']);
// More than one assert, ported from legacy test
expect(program.foo).toBe(true);
expect(program.bar).toBeUndefined();
expect(program.args).toEqual(['--bar', 'baz']);
});
test('when arguments include -- then more literals are passed-through as args', () => {
const program = new commander.Command();
program
.option('-f, --foo', 'add some foo')
.option('-b, --bar', 'add some bar');
program.parse(['node', 'test', '--', 'cmd', '--', '--arg']);
expect(program.args).toEqual(['cmd', '--', '--arg']);
});