Giter Site home page Giter Site logo

Comments (10)

mitsuhiko avatar mitsuhiko commented on August 25, 2024 1

Have a look at the link I sent before. This is how you can do it now:

CONTEXT_SETTINGS = dict(help_option_names=['-h'])

@click.group(context_settings=CONTEXT_SETTINGS)
@click.pass_context
def cli(context):
    ....

from click.

techtonik avatar techtonik commented on August 25, 2024 1

Is it possible to setup it once globally instead of bloating every decorator?

from click.

techtonik avatar techtonik commented on August 25, 2024 1

@mitsuhiko @click.group(context_settings=CONTEXT_SETTINGS) is undocumented https://click.palletsprojects.com/en/7.x/api/#click.Group

from click.

mitsuhiko avatar mitsuhiko commented on August 25, 2024

No, i intentionally did not make it a default because -h should not be the help option. You can manually make it the default by removing the help option with a parameter and adding it back with the help_option decorator and by passing in the arguments manually.

from click.

hyao avatar hyao commented on August 25, 2024

Thanks for the clarification!

from click.

boosh avatar boosh commented on August 25, 2024

How do you remove the default '--help' option? I've added @click.help_option('-h', '--help') to my commands, but this just adds an additional help option instead of overriding the default.

from click.

mitsuhiko avatar mitsuhiko commented on August 25, 2024

No, it did not add to the default, it changed the default. If you just want '-h' then just list -h:

@click.help_option('-h')

Note though that with click 2.0 there are better ways:

http://click.pocoo.org/documentation/#help-parameter-customization

from click.

boosh avatar boosh commented on August 25, 2024

I'm trying to get '-h' and '--help' to work. Here's my code:

@click.group()
@click.help_option('-h', '--help')
@click.pass_context
def cli(context):
    ....

If I run 'myapp -h' I get:

Usage: myapp [OPTIONS] COMMAND [ARGS]...

  ...

Options:
  -h, --help                 Show this message and exit.
  --help                     Show this message and exit.

Commands:
    ...

I'm staying on click 1.1 until 2.0 is in pypi. How can I remove the duplicate message for just '--help'?

Great library BTW, thanks!

from click.

boosh avatar boosh commented on August 25, 2024

I tried it but got an error:

  ...
  File "cli.py", line 20, in <module>
    @click.pass_context
  File "/venv/lib/python2.7/site-packages/click/decorators.py", line 110, in decorator
    return _make_command(f, name, attrs, cls)
  File "/venv/lib/python2.7/site-packages/click/decorators.py", line 84, in _make_command
    callback=f, params=params, **attrs)
  File "/venv/lib/python2.7/site-packages/click/core.py", line 646, in __init__
    MultiCommand.__init__(self, name, **attrs)
  File "/venv/lib/python2.7/site-packages/click/core.py", line 549, in __init__
    Command.__init__(self, name, **attrs)
TypeError: __init__() got an unexpected keyword argument 'context_settings'

from click.

boosh avatar boosh commented on August 25, 2024

Not to worry. I see 2.0 is in pypi now. I've upgraded and your instructions work. Thanks.

from click.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.