Comments (8)
@untitaker IMO, maybe Click
does not have alias
idea. But If we can use -l
why we use --list
?
And if you have used argparse
, you know --help
in @click.option('-h', '--help', is_flag=True, ...)
is equal to dest
in argparse
;
As the issue you mentioned above, you can handle ctx.format_help()
with str
operation very easily:
def print_help(ctx, value):
if not value:
return
lines = ctx.format_help().replace('-h', '--help/-h')
print '\n'.join(lines.split('\n')[:-1])
ctx.exit()
Hope this will help!
from click.
You can remove the default help option through a parameter already. I don't think this feature is necessary.
from click.
the parameter @mitsuhiko is referencing is the add_help_option
which is passed to @click.group
(and similar decorators) like so: @click.group(add_help_option=False)
from click.
I don't want to remove the help option, i want to create an alias for it. I currently don't think writing around 20 lines of code to remove the help option and add it again (this time with an alias) is very convenient.
from click.
untitaker, the following is a snippet that aliases --help
to --wtf
:
@click.group(add_help_option=False)
@click.help_option('-w', '--wtf')
def command_a():
pass
Unfortunately, it doesn't seem sub-commands inherit this behavior; so if you have a subcommand you have to do:
@command_a.command(add_help_option=False)
@click.help_option('-w', '--wtf')
def subcommand():
pass
So if you have 10 commands you do have to add 20 lines of code :(. I'm sure there's a better way, perhaps by creating a custom command class that inherits from the base command and have it do this automatically; but I haven't dug into the code enough to figure that out.
from click.
I can see this being annoying. Contemplating special casing help here.
from click.
Maybe we could fix this particular "stage" of the problem:
However, click then doesn't recognize -h as an alias for --help and shows
this ugly help output for those options:
-h Show this message and exit.
--help Show this message and exit.
And make click recognize two options to be the same when the function names are the same.
from click.
I implemented this through a completely different system now. You can do this now:
DEFAULTS = dict(help_option_names=['-h', '--help'])
@click.command(context_defaults=DEFAULTS)
def cli():
pass
All commands below that command will then have -h
and --help
as help options. In case of a conflict the conflicting value is removed.
from click.
Related Issues (20)
- Revisiting stderr flush in CLIRunner
- feature: allow substituting command_path in command help and epilog text
- Wront Usage when running a module with python -m HOT 1
- format_help_text does not format text in a group HOT 5
- Conditionally apply options to input
- Click performance is poor HOT 1
- Request to document some basic features explicitly HOT 2
- show envvar in error hint HOT 3
- Broken message about invalid argument value for template "File ... is a directory" HOT 1
- Missing return value in context manager example (Managing resources)?
- zsh completion still misbehaving in the presence of `:`
- Setting color=True in runner.invoke on windows strips ansi codes HOT 2
- Better i18n with gettext: use class-based API
- Broken code example in docs under Advanced Patterns
- Utility to introspect known command arguments HOT 3
- Autocorrect wrong/misspelled option with the suggested unique possibility. HOT 1
- 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
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.