Requiring via `<` does not work.
JonasDoe opened this issue · comments
Taking your example,
const program=new Command('test-required').option('-p, --pizza-type <TYPE>', 'type of pizza')
program.parse()
won't throw an Error
. I've checked, this.required = flags.includes('<')
in the Option
constructor is set to true
, but it seems this value isn't evaluated anywhere (I just set breakpoints at all reading accesses, and none of them was triggered).
Command#requiredOption
is working though.
-p, --pizza-type <TYPE>
means if the option is used, an option value is required.
% node index.js
% node index.js --pizza-type
error: option '-p, --pizza-type <TYPE>' argument missing
-p, --pizza-type <TYPE>
means if the option is used, an option value is required.% node index.js % node index.js --pizza-type error: option '-p, --pizza-type <TYPE>' argument missing
Ooooh, I see - thanks for the clarification!
Sorry for the derailment, but how can I render a new Option
as mandatory then? I can't use requiredOption()
b/c I want to set an env alternative to it (i.e. .addOption(new Option(...).env(...))
, but I don't see a way make this object mandatory, - if <TYPE>
isn't meant for that.
See Option.makeOptionMandatory()
.
Specify a required (mandatory) option using the
Option
method.makeOptionMandatory()
. This matches theCommand
method .requiredOption().
I see! Thank you for your time!