GeezerVison is showing github.com — Add no_args_is_help to click.Command by sirosen · Pull Request #1167 · pallets/click
Conversation
sirosen
commented
Nov 10, 2018
•
edited
Loading
Uh oh!
There was an error while loading. Please reload this page.
The functionality for no_args_is_help, available on MultiCommands, can easily be added on Commands as well. The result is not much more code, and a more consistent interface between MultiCommands and Commands.
It's also nice to be able to write a click command foo and then just hit foo for help, regardless of whether its a Group or Command.
closes #1156
Will add changelog edit in a moment, after this PR is assigned a number.
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
blaiszik, ryanchard, simonkeng, and mbhall88 reacted with thumbs up emoji
The functionality for no_args_is_help, available on MultiCommands, can
easily be added on Commands as well. The result is not much more code,
and a more consistent interface between MultiCommands and Commands.
It's also nice to be able to write a click command `foo` and then just
hit `foo` for help, regardless of whether its a Group or Command.
closes pallets#1156
|
I just had a coworker ask me about this feature (unaware of this PR), so I guess that's a 👍 from somewhere for this feature.
In #1156 I said I wasn't sure we needed this, but maybe I'm changing my tune on it. Seems easy for click to do, and confusing for people new to the framework.
|
blaiszik, ryanchard, and simonkeng reacted with thumbs up emoji
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
|
Looks good to me.
Should there be a check that there is at least one required arg? Otherwise you wouldn't actually be able to run the command. Guess at that point you should have just not set no_args_is_help though.
|
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
|
Yeah, I think "just don't try to do that" is a reasonable stance.
I wouldn't check for a required arg, since someone might have a command which takes a bunch of options which determine its behavior. e.g. command --mode1 and command --mode2 are valid, but command on its own is not.
I noticed a small typo in my changelog entry, which I just amended. That's why there's a fresh commit.
|
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
This was referenced Mar 14, 2019
|
Hi, do developers need to wait for the 7.1 release to use this feature? Or is there a branch I can switch to in order to have access to this earlier? I'm using Click==7.0 via pip but I would build it from the GitHub repo instead if I can access no_args_is_help without waiting for the 7.1 release.
Thanks!
|
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
|
@simonkeng, if you want to use this ahead of the 7.1 release, you could install from the 7.x branch directly or even from a specific commit on said branch.
I don't recommend this, but it works and you can do it. It's just a "buyer beware" situation.
There are a few ways to install from GitHub with pip, but here's one which doesn't require you to have git installed on the target platform:
pip install https://github.com/pallets/click/archive/7.x.tar.gz
or
pip install https://github.com/pallets/click/archive/6245807b95a01ff3538f06bcc93e38042474aca9.tar.gz
You might be better served (until 7.1 releases) by just printing the helptext yourself with
# TODO: remove after click 7.1 releases and use no_args_is_help instead
if not (arg1 or arg2):
click.echo(ctx.get_help(), color=ctx.color)
if you pass the context to your commands.
If I needed this behavior in my own tools, I'd probably opt for explicitly printing help myself.
|
simonkeng and IanGabes reacted with thumbs up emoji
simonkeng, IanGabes, and mbhall88 reacted with heart emoji
All reactions
-
👍
2 reactions
-
❤️
3 reactions
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Assignees
No one assigned
Labels
parsing
Parsing, parameters, commands, chaining, context
Development
Successfully merging this pull request may close these issues.
Uh oh!
There was an error while loading. Please reload this page.
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
|