Comments (10)
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.
Is it possible to setup it once globally instead of bloating every decorator?
from click.
@mitsuhiko @click.group(context_settings=CONTEXT_SETTINGS)
is undocumented https://click.palletsprojects.com/en/7.x/api/#click.Group
from click.
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.
Thanks for the clarification!
from click.
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.
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.
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.
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.
Not to worry. I see 2.0 is in pypi now. I've upgraded and your instructions work. Thanks.
from click.
Related Issues (20)
- Docs wrongly links PRs and Issues to flask
- The type hint for the filename parameter to open_file is incomplete HOT 1
- Missing reset on should_strip_ansi causing cascading issues during other tests
- Custom type called twice with prompt HOT 2
- Display exception notes when raising `ClickException` HOT 2
- Optionally expand global variables in parameters? HOT 2
- click.Path(resolve_path=True) crash on non-Path HOT 2
- partially initialized module 'click' has no attribute 'command' (most likely due to a circular import)
- Modifying default_map in callback behaves differently between click 7.1.2 and 8.0.0
- `flag_value` is not taken into account with `envvar`
- Click does not detect duplicate option flags HOT 2
- Cursor Keys show escape characters like ^[[D when inputting missing options HOT 2
- get_parameter_source does not work with invoke or forward
- calling with no args should print help HOT 1
- List of commands when creating a concrete class from `click.MultiCommand` does not display any commands in the CLI. HOT 1
- document how to create a standalone application HOT 2
- CliRunner.invoke doesn't capture stdout from logging HOT 1
- Way to render CLI usage examples in docstrings HOT 3
- Provide suggestions for misspelled subcommands
- double-dash handling does not support wrapper scripts. HOT 3
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from click.