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

help not resolving automatically #2819

Open
Rowlando13 opened this issue Dec 15, 2024 · 0 comments
Open

help not resolving automatically #2819

Rowlando13 opened this issue Dec 15, 2024 · 0 comments
Labels

Comments

@Rowlando13
Copy link
Collaborator

Rowlando13 commented Dec 15, 2024

From the docs:

The help parameter is implemented in Click in a very special manner. Unlike regular parameters it’s automatically added by Click for any command and it performs automatic conflict resolution. By default it’s called --help, but this can be changed. If a command itself implements a parameter with the same name, the default help parameter stops accepting it. There is a context setting that can be used to override the names of the help parameters called help_option_names.

What is wrong:
Help does not automatically resolve if there is an arg or kwarg called help. In the sample the file is called help.py

import click

# This works 
@click.command()
@click.argument('helps')
def this_works(helps):
    print(helps)

# > python -m help this
# this

# > python -m help --help
# Usage: help.py [OPTIONS] HELPS

# Options:
#   --help  Show this message and exit.

# This does not work
@click.command()
@click.argument('help')
def this_does_not_work(help):
    print(help)

# > python -m help this
# Usage: help.py [OPTIONS] HELP
# Try 'help.py --help' for help.

# Error: Invalid value for '--help': 'this' is not a valid boolean.

# > python -m help --help
# Usage: help.py [OPTIONS] HELP
# Try 'help.py --help' for help.

# Error: Missing argument 'HELP'.

# This does not work
@click.command()
@click.option('--help', default='this_2')
def this_does_not_work_also(help='this_2'):
    print(help)

# > python -m help 
# None

# > python -m help --help
# Error: Option '--help' requires an argument.

if __name__ == '__main__':
    #this_works()
    #this_does_not_work()
    this_does_not_work_also()

  • Python version: 3.10.15
  • Click version: 8.1.7
@Rowlando13 Rowlando13 added the bug label Dec 15, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant