Newsletter
TechAnV Blog
Get updates on security engineering, Rust, eBPF, and DevSecOps. No spam, unsubscribe anytime.
Check your inbox and click the confirmation link to complete your subscription.
Understanding option names in Click#
I hit a bug today where I had defined a Click option called open but in doing so I replaced the Python bulit-in open() function:
1@click.command()2# ...3@click.option("-o", "--open", is_flag=True, help="Open Datasette in your web browser")4def my_command(open):5 # Now open() is no longer availableThis inspired me to finally figure out how Click function argument names work. It’s documented here: https://click.palletsprojects.com/en/7.x/options/#name-your-options
Short version: you can do this:
1@click.command()2# ...3@click.option("-o", "--open", "open_browser", is_flag=True, help="Open Datasette in your web browser")4def my_command(open_browser):5 # Now open() can be used safelyClick will use the positional argument without any hyphen prefixes as the name of the argument. If none is provided it will use the first -- one. If that’s not defined it will use the -o one - all with the hypens stripped.
Newsletter
TechAnV Blog
Get updates on security engineering, Rust, eBPF, and DevSecOps. No spam, unsubscribe anytime.
Check your inbox and click the confirmation link to complete your subscription.