Skip to content

Show flag name instead of True/False with Boolean flags#1617

Merged
davidism merged 1 commit into
pallets:masterfrom
MLH-Fellowship:issue1538
Aug 7, 2020
Merged

Show flag name instead of True/False with Boolean flags#1617
davidism merged 1 commit into
pallets:masterfrom
MLH-Fellowship:issue1538

Conversation

@ovezovs
Copy link
Copy Markdown
Contributor

@ovezovs ovezovs commented Jul 1, 2020

Fixes #1538

@ovezovs
Copy link
Copy Markdown
Contributor Author

ovezovs commented Jul 1, 2020

@davidism, I have one major question regarding this fix: Should we show the flag names only for boolean flags or any? For example, test_global_show_default expects default on the help flag line to be false. For now, I did a workaround to not display the default flag name when it is help. I am not sure if that's a bad thing.

Copy link
Copy Markdown

@juped juped left a comment

Choose a reason for hiding this comment

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

I recommend splitting the history into maybe two commits (one something like "Display flag name instead of True/False for default in help" and one "Add test [...]"), or maybe just one

Comment thread src/click/core.py Outdated
@davidism
Copy link
Copy Markdown
Member

davidism commented Jul 1, 2020

Unless the test is particularly complex, I usually just roll it into the code commit. Same for multiple code and cleanup commits into a single commit.

@davidism davidism added this to the 8.0.0 milestone Aug 7, 2020
@davidism davidism added the f:help feature: help text label Aug 7, 2020
@davidism
Copy link
Copy Markdown
Member

davidism commented Aug 7, 2020

Updated the implementation so that it checks that the boolean flag actually has separate flags for True and False. It selects them from self.opts and self.secondary_opts instead of rv, since rv will have , joined alternative names together. That would cause the following:

@click.option("--cache/--no-cache", "--c/--nc", show_default=True)
[default: no-cache, --nc]

Now it outputs only no-cache.

Updated the test to check when default is True and False, and added a second test for when there's only one name.

@davidism davidism merged commit 66172ef into pallets:master Aug 7, 2020
@davidism davidism deleted the issue1538 branch August 7, 2020 14:54
@ovezovs
Copy link
Copy Markdown
Contributor Author

ovezovs commented Aug 9, 2020

Updated the implementation so that it checks that the boolean flag actually has separate flags for True and False. It selects them from self.opts and self.secondary_opts instead of rv, since rv will have , joined alternative names together. That would cause the following:

@click.option("--cache/--no-cache", "--c/--nc", show_default=True)
[default: no-cache, --nc]

Now it outputs only no-cache.

Updated the test to check when default is True and False, and added a second test for when there's only one name.

Thank you so much for the feedback!

@github-actions github-actions Bot locked as resolved and limited conversation to collaborators Nov 13, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

f:help feature: help text

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Improvement for show_default showing in case of a flag the name instead of True/False

3 participants