Skip to content

Conversation

fdavis
Copy link
Contributor

@fdavis fdavis commented Mar 6, 2020

fixes #1394
fixes #1486

@davidism
Copy link
Member

Command can also have no_args_is_help. I think the error code should be 2 instead of 1 to match other usage errors.

@davidism davidism self-assigned this Aug 13, 2020
@davidism
Copy link
Member

Changing this caused a test to fail, but it seems to be revealing something weird about the processing, not a problem with this change. The following causes an exit code of 2, even though --help was passed so it should result in 0.

import click

@click.group()
@click.argument("obj")
def cli(obj):
    click.echo(f"obj={obj}")

@cli.command()
def move():
    click.echo("move")

cli(["obj1", "--help"])

The problem is caused here in MultiCommand.resolve_command:

click/src/click/core.py

Lines 1398 to 1407 in 0ad4e79

# If we don't find the command we want to show an error message
# to the user that it was not provided. However, there is
# something else we should do: if the first argument looks like
# an option we want to kick off parsing again for arguments to
# resolve things like --help which now should go to the main
# place.
if cmd is None and not ctx.resilient_parsing:
if split_opt(cmd_name)[0]:
self.parse_args(ctx, ctx.args)
ctx.fail(f"No such command '{original_cmd_name}'.")

ctx.args is empty at this point, which causes the no_args_is_help behavior. Since that matched the actual --help behavior before, the issue wasn't caught. Seems like it might be related to #473.

@davidism
Copy link
Member

Ironically, I just closed #1323 which discussed how the processing pipeline needs a rewrite, and then re-discovered that this PR demonstrates the issue.

@davidism davidism force-pushed the fdavis-1486 branch 2 times, most recently from 36f9993 to 9b38044 Compare August 13, 2020 20:21
@davidism
Copy link
Member

Pushed a new implementation that uses a new NoArgsIsHelpError to match how other usage messages are handled. This doesn't fix the processing issue.

@davidism davidism added this to the 9.0.0 milestone Aug 13, 2020
@davidism davidism removed their assignment Aug 13, 2020
@davidism
Copy link
Member

davidism commented Feb 22, 2022

I started looking into this before 8.1, and it's too complex to disentangle the pipeline issues right now. I have plans for the parser/pipeline, so I'll come back to this then.

@davidism davidism removed this from the 8.1.0 milestone Feb 22, 2022
@davidism davidism mentioned this pull request Feb 27, 2022
@AndreasBackx AndreasBackx changed the title return exit 1 if group gets no command Help shown via no_args_is_help results in exit code 2, was 0 Oct 26, 2024
@AndreasBackx AndreasBackx added this to the 8.2.0 milestone Oct 26, 2024
@AndreasBackx AndreasBackx mentioned this pull request Oct 26, 2024
34 tasks
…gs which lead to

args being empty -> --help leading to exit code 2 instead of 0.

* Added PR to CHANGES.
* Fixed typing.
* Fixed test to be up to date with rebased changes.
@AndreasBackx AndreasBackx merged commit d8763b9 into pallets:main Nov 3, 2024
12 checks passed
@benjaoming
Copy link

Nice one @AndreasBackx 🙌

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

Successfully merging this pull request may close these issues.

Not specifying a group's command exits with code 0 Command w/o args displaying usage should return non-zero
4 participants