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

Automatically support --no prefix for boolean flags. #89

Merged
merged 1 commit into from
Apr 17, 2020
Merged

Conversation

olafurpg
Copy link
Member

Previously, if you had boolean flag like sources: Boolean with default
value true then there was no way for cli users to set the value to
false because --sources can only set the boolean to true. Now, users
can pass the flag --no-sources to make the boolean value false.

This diff ended up being trickier to implement than I expected because
we need to make sure that it's still OK to name fields with a --no-
prefix, such as noSources: Boolean. This feature is implemented in a
fully backwards compatible way by always trying first to use the default
parsing logic and only falling back to guessing the addition or removal
of the --no- prefix. This means that a boolean flag named noSources: Boolean can also be overriden with the --sources flag.

Previously, if you had boolean flag like `sources: Boolean` with default
value true then there was no way for cli users to set the value to
false because `--sources` can only set the boolean to true. Now, users
can pass the flag `--no-sources` to make the boolean value false.

This diff ended up being trickier to implement than I expected because
we need to make sure that it's still OK to name fields with a `--no-`
prefix, such as `noSources: Boolean`. This feature is implemented in a
fully backwards compatible way by always trying first to use the default
parsing logic and only falling back to guessing the addition or removal
of the `--no-` prefix. This means that a boolean flag named `noSources:
Boolean` can also be overriden with the `--sources` flag.
@olafurpg olafurpg merged commit 62477af into master Apr 17, 2020
@olafurpg olafurpg deleted the clis branch April 17, 2020 10:18
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant