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

skipping metavars for flags #100

Merged
merged 3 commits into from
Jan 18, 2023
Merged

skipping metavars for flags #100

merged 3 commits into from
Jan 18, 2023

Conversation

likewei92
Copy link
Contributor

@likewei92 likewei92 commented Jan 18, 2023

See this example script for click feature switches (adapted from https://click.palletsprojects.com/en/8.1.x/options/#feature-switches)

import sys
import rich_click as click


@click.command()
@click.option("--upper", "transformation", flag_value="upper", default=True, help="upper case")
@click.option("--lower", "transformation", flag_value="lower", help="lower case")
def info(transformation):
    click.echo(getattr(sys.platform, transformation)())


if __name__ == "__main__":
    info()

Before, rich-click would print this as help text:

 Usage: test.py [OPTIONS]                                 
                                                          
╭─ Options ──────────────────────────────────────────────╮
│ --upper    TEXT  upper case                            │
│ --lower    TEXT  lower case                            │
│ --help           Show this message and exit.           │
╰────────────────────────────────────────────────────────╯

but there is no input for the --upper and --lower flags. I believe all flags should not print metavars information. With this fix, we get:

 Usage: test.py [OPTIONS]                                 
                                                          
╭─ Options ──────────────────────────────────────────────╮
│ --upper      upper case                                │
│ --lower      lower case                                │
│ --help       Show this message and exit.               │
╰────────────────────────────────────────────────────────╯

Copy link
Owner

@ewels ewels left a comment

Choose a reason for hiding this comment

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

Nice, thanks!

@ewels ewels merged commit e0bc003 into ewels:main Jan 18, 2023
@likewei92
Copy link
Contributor Author

@ewels do you mind making a new (minor version) release?

@ewels
Copy link
Owner

ewels commented Jan 19, 2023

Yeah of course, now done: https://pypi.org/project/rich-click/1.6.1/

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.

None yet

2 participants