click
click copied to clipboard
return exit 1 if group gets no command
fixes #1394 fixes #1486
Command
can also have no_args_is_help
. I think the error code should be 2 instead of 1 to match other usage errors.
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
: https://github.com/pallets/click/blob/0ad4e7985a919041ec590a4d672afb44f05dd162/src/click/core.py#L1398-L1407
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.
Ironically, I just closed #1323 which discussed how the processing pipeline needs a rewrite, and then re-discovered that this PR demonstrates the issue.
Pushed a new implementation that uses a new NoArgsIsHelpError
to match how other usage messages are handled. This doesn't fix the processing issue.
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.