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

Add no_args_is_help to click.Command #1167

Merged
merged 2 commits into from Nov 30, 2018
Merged

Conversation

@sirosen
Copy link
Contributor

@sirosen sirosen commented Nov 10, 2018

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.

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
@sirosen sirosen force-pushed the sirosen:no-args-help-command branch from db7e9bf to 624a328 Nov 10, 2018
@sirosen sirosen changed the base branch from master to 7.x Nov 10, 2018
@sirosen
Copy link
Contributor Author

@sirosen sirosen commented Nov 29, 2018

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.

@davidism
Copy link
Member

@davidism davidism commented Nov 29, 2018

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.

@sirosen sirosen force-pushed the sirosen:no-args-help-command branch from 624a328 to 02ba36f Nov 30, 2018
@sirosen
Copy link
Contributor Author

@sirosen sirosen commented Nov 30, 2018

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.

@davidism davidism added this to the 7.1 milestone Nov 30, 2018
@davidism davidism merged commit 43eb54d into pallets:7.x Nov 30, 2018
2 checks passed
2 checks passed
continuous-integration/appveyor/pr AppVeyor build succeeded
Details
continuous-integration/travis-ci/pr The Travis CI build passed
Details
@sirosen sirosen deleted the sirosen:no-args-help-command branch Dec 1, 2018
@jcrotts jcrotts mentioned this pull request Dec 7, 2018
@simonkeng
Copy link

@simonkeng simonkeng commented Oct 19, 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!

@sirosen
Copy link
Contributor Author

@sirosen sirosen commented Oct 21, 2019

@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.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Nov 13, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Linked issues

Successfully merging this pull request may close these issues.

None yet

3 participants