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

Documentation -- alias of second option, confusing order #2625

Open
zerothi opened this issue Oct 13, 2023 · 0 comments
Open

Documentation -- alias of second option, confusing order #2625

zerothi opened this issue Oct 13, 2023 · 0 comments

Comments

@zerothi
Copy link

zerothi commented Oct 13, 2023

This is mainly a problem of the documentation:

See here: https://click.palletsprojects.com/en/8.1.x/options/#boolean-flags

I find this:

If you want to define an alias for the second option only, then you will need to use leading whitespace to disambiguate the format string:

Example:

import sys

@click.command()
@click.option('--shout/--no-shout', ' /-S', default=False)
def info(shout):
    rv = sys.platform
    if shout:
        rv = rv.upper() + '!!!!111'
    click.echo(rv)

info --help
Usage: info [OPTIONS]

Options:
  --shout / -S, --no-shout
  --help                    Show this message and exit.

Perhaps it's getting late here, but.. I understand it like this:

  • we want to alias the 2nd option, i.e. --no-shout.
  • to me the empty space before ' /-S' would mean that there is no short-hand for --shout but -S for --no-shout (that may be weird, but that's how I read it...)
  • How can one then create a shorthand for --no-shout, but not --shout?

I have tried:

@click.option('--shout/--no-shout', '-S/ ', default=False)
 
$> info --help
  -S, --shout / --no-shout

Which is ok, but still a bit weird.
It seems it can only be used to select the order of the short-hand function for the documentation.
Perhaps this is intended, but I find the above quite confusing?

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

No branches or pull requests

1 participant