click icon indicating copy to clipboard operation
click copied to clipboard

return exit 1 if group gets no command

Open fdavis opened this issue 4 years ago • 5 comments

fixes #1394 fixes #1486

fdavis avatar Mar 06 '20 22:03 fdavis

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 avatar Aug 13 '20 01:08 davidism

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.

davidism avatar Aug 13 '20 17:08 davidism

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 avatar Aug 13 '20 20:08 davidism

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 avatar Aug 13 '20 20:08 davidism

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 avatar Feb 22 '22 21:02 davidism