Skip to content

Commit

Permalink
Allow args after and between options
Browse files Browse the repository at this point in the history
  • Loading branch information
lahmatiy committed Dec 12, 2021
1 parent 4152aef commit 21e2702
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 2 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
## next

- Allowed args after and between options

## 3.0.0-beta.1

- Restored wrongly removed `Command#extend()`
Expand Down
3 changes: 1 addition & 2 deletions lib/parse-argv.js
Original file line number Diff line number Diff line change
Expand Up @@ -131,8 +131,7 @@ module.exports = function parseArgv(command, argv, context, suggestMode) {
};
break;
} else {
if (rawOptions.length !== 0 ||
context.args.length >= command.params.maxCount) {
if (context.args.length >= command.params.maxCount) {
throw new CliError(`Unknown command: ${token}`);
}

Expand Down
15 changes: 15 additions & 0 deletions test/command-args-and-options.js
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,21 @@ describe('command run', function() {
});
});

it('args & options before', function() {
const actual = command.run(['--foo', '--bar', '123', 'qux']);

assert.deepStrictEqual(actual, {
commandPath: ['test'],
options: {
__proto__: null,
foo: true,
bar: 123
},
args: ['qux'],
literalArgs: null
});
});

it('args & literal args', function() {
const actual = command.run(['qux', '--', '--one', '--two', '123']);

Expand Down

0 comments on commit 21e2702

Please sign in to comment.