parseArgs with type: "boolean" and default: true does not allow a false value
Consider the following example:
import { parseArgs } from 'node:util' const options = { foo: { type: 'boolean', short: 'f', default: true }, }; function parseAndLog (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.