Description
What is the problem this feature will solve?
It's not unusual for command-line options to have optional arguments. For example, git
has --color[=<when>]
: If an argument is provided, it's used, but if --color
is given without an argument, that argument defaults to always
.
parseArgs()
does not support this kind of optional argument. Either the option's type is boolean
and any argument throws an error; or it's string
and a missing argument throws an error.
What is the feature you are proposing to solve the problem?
Add a field to the option definition so that a string
option is allowed to have no argument, and use a default value in that case. For example, the --color[=<when>]
case could look like this:
{
color: {
type: 'string',
valueIfNoArgument: 'always',
}
}
Probably someone can think of a better name for this field.
What alternatives have you considered?
The alternative is to disable strict mode, and manually process the tokens
array. However, this is a lot of boilerplate, and requires reimplementing the checks for which options are valid, making it error-prone.