Open Tarasaur opened 6 years ago
Hi!
I am unable to successfully model a complex command using a sequence of positional arguments followed by a long option flag.
Example usage I want to achieve:
myScript fancyEntry 3 fancyChoice --entryFlag
I have something like the following:
exports.command = 'myScript <entryName> <entryNumber> [entryChoice] [entryFlag]';
exports.builder = (yargs) => yargs .positional('entryName', { alias: 'eName', type: 'string' }) .positional('entryNumber', { alias: 'eNumber', type: 'number' }) .positional('entryChoice', { alias: 'eChoice', choices: ['plainChoice', 'fancyChoice'], default: 'plainChoice', type: 'string' }) .option('entryFlag', { type: 'boolean' });
exports.handler = (argv) => { if (argv.entryFlag) { // Do something } else { // Do something else } }
However, when running my command, argv.entryFlag always seems to be false, even when it is present in my command.
argv.entryFlag
I tried explicitly assigning arguments and triggering the value in roundabout ways, such as:
myScript fancyEntry 3 "fancyChoice" --entryFlag
myScript fancyEntry 3 entryChoice="fancyChoice" --entryFlag
myScript fancyEntry 3 entryChoice="fancyChoice" --entryFlag=true
myScript fancyEntry 3 entryChoice="fancyChoice" true
No luck, though.
I would love for --entryFlag to behave like --verbose in that it is an optional argument, and if present, its value is true.
--entryFlag
--verbose
true
Have I grossly misconfigured something?
Same problem here
Hi!
I am unable to successfully model a complex command using a sequence of positional arguments followed by a long option flag.
Example usage I want to achieve:
I have something like the following:
However, when running my command,
argv.entryFlag
always seems to be false, even when it is present in my command.I tried explicitly assigning arguments and triggering the value in roundabout ways, such as:
No luck, though.
I would love for
--entryFlag
to behave like--verbose
in that it is an optional argument, and if present, its value istrue
.Have I grossly misconfigured something?