Consider the following example:
import{parseArgs}from'node:util'constoptions={foo: {type: 'boolean',short: 'f',default: true},};functionparseAndLog(args,options){console.log('---');try{console.log('args:',args);const{
values,
positionals,}=parseArgs({ args, options });console.log(values,positionals);}catch(e){console.error(e);}}parseAndLog(['--foo','false'],options);parseAndLog(['--no-foo'],options);How can somebody add a flag that can be defaulted as true, but allow a --no flag to set it to false? I imagine that a type: "boolean" setting would add both --flag and --no-flag.
Consider the following example:
How can somebody add a flag that can be defaulted as
true, but allow a--noflag to set it to false? I imagine that atype: "boolean"setting would add both--flagand--no-flag.