Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow boolean default for flag option #987

Merged
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion Readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -101,8 +101,9 @@ cheese: stilton

You can specify a boolean option long name with a leading `no-` to set the option value to false when used.
Defined alone this also makes the option true by default.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In rereading this and the edits, I'm not sure we're using consistent vocabulary on this specific line; i.e. it can be unclear whether "define" (or "specify", "add", "set", etc.) means "when defining the program" or "when invoking the program via the CLI."

It could just be that the sentence is slightly awkwardly worded (and sorry to comment on something that isn't a change in this commit).

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree with the awkward and potential for misinterpretation. I have struggled with the wording a couple of times, but at least we do have examples to consult. I'm not planning to have another go in this PR.

If you define `foo` first, adding `--no-foo` does not change the default value.

If you define `--foo` first, adding `--no-foo` does not change the default value from what it would
otherwise be. You can specify a default boolean value for a boolean flag and it can be overridden on command line.

```js
const program = require('commander');
Expand Down