node
                                
                                
                                
                                    node copied to clipboard
                            
                            
                            
                        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.
I see many node configuration use this bidirectional flag format, I'm willing to implement it in parseArgs 
The bidirectional flag format is really common here because it allows to change the default of the flag in a follow-up major.
This can be done using the tokens array, though it does require about a dozen lines of boilerplate.
In fact, the same example of adding support for negation from the parseArgs repo (linked above) is also used as the example use of tokens in the Node.js documentation:
- https://nodejs.org/docs/latest/api/util.html#parseargs-tokens
 
Fixed by https://github.com/nodejs/node/pull/53107, presumably?
Fixed by https://github.com/nodejs/node/pull/53107, presumably?
I believe that was the intent, so I've closed this