You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Is there any way to (re-)parse options based on conditions? I'm thinking of something like
program.option('--interactive')program.parse();letopts=program.opts()if(opts.interactive){// options are optional here}else{// if condition is false, fallback to required options insteadprogram.requiredOption('--requiredOption')program.parse();opts=program.opts()// use conditional opts}
Currently, when trying to run this, I'm getting error: unknown option '--requiredOption' because the option isn't added at the time of the first parsing.
EDIT: One workaround may be to declare all options (even the conditionally required) as optional ahead of time and 'validate' them when needed conditionally with exiting with .help() if they are missing.
The text was updated successfully, but these errors were encountered:
There isn't a way to reparse as such. I recommend you create a new Command for each parse to avoid left over state.
Parsing twice, in the first parse you might set .allowUnknownOption() and leave out some options, or at least don't make them "required" as you suggested. If first parse discovers not interactive, then parse again with the full set of options (and errors for unknown).
(If there are not other options and --interative is basically alone when used, you could even check for it yourself.)
Is there any way to (re-)parse options based on conditions? I'm thinking of something like
Currently, when trying to run this, I'm getting
error: unknown option '--requiredOption'
because the option isn't added at the time of the first parsing.EDIT: One workaround may be to declare all options (even the conditionally required) as optional ahead of time and 'validate' them when needed conditionally with exiting with
.help()
if they are missing.The text was updated successfully, but these errors were encountered: