Skip to content

Adding negative option makes Commander.js to return "true" when option is not specified #979

@slavafomin

Description

@slavafomin

Hello!

I'm encountering yet another strange behavior of Commander.js.

When I add the following option:
command.option('--clean', 'cleans the destination build directory');

And then run my program this way: program, the Commander returns clean option as undefined.

However, when I add an additional negative option:

command.option(`--clean`, 'cleans the destination build directory');
command.option(`--no-clean`, 'prevents cleaning the destination directory');

It starts to return true for the clean option when executed the same as above instead of the undefined.

Why is that? I want the option to be always undefined if it's not specified via CLI.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions