-
-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Closed
Description
new Command()
.passThroughOptions()
.command('sub')
.passThroughOptions();Running this code results in the following error:
Error: passThroughOptions can not be used without turning on enablePositionalOptions for
parent command(s)
at Command.passThroughOptions (lib/command.js:739:13)
But actually, using passThroughOptions on a subcommand whose parent also uses it should be okay because passThroughOptions makes options positional just like enablePositionalOptions. That is demonstrated by the following snippet
const program = new Command()
.passThroughOptions()
.option('-x');
const sub = program.command('sub')
.option('-x');
program.parse(['sub', '-x'], { from: 'user' });
console.log(program.opts()); // {}
console.log(sub.opts()); // { x: true }and explained by the fact passThroughOptions is included in the check in lib/command.js, line 1522.
So is there any point in requiring enablePositionalOptions when passThroughOptions which too has the needed effect is already on?
My suggestion is
- either not to throw the error when the parent command uses
passThroughOptions, - or to change the semantics for
passThroughOptionsso that there is no functionality overlap withenablePositionalOptions.
The latter idea introduces a breaking change but could be justified by some absurd use cases like
# --verbose to be passed through due to using passThroughOptions
node program --trace curl --verbose https://github.com/
# --verbose to be consumed by program command due to not using enablePositionalOptions
node program utility-subcommand --verboseReactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels