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

Generated help with aliased group shows abbreviated command in usage #1422

Closed
dvstans opened this issue Nov 14, 2019 · 4 comments · Fixed by #1615
Closed

Generated help with aliased group shows abbreviated command in usage #1422

dvstans opened this issue Nov 14, 2019 · 4 comments · Fixed by #1615
Milestone

Comments

@dvstans
Copy link

dvstans commented Nov 14, 2019

The typical AliasGroup class overrides the get_command method and returns a matching sub command; however, when help is displayed, the usage information shows the matched abbreviated subcommand instead of the full subcommand name. After debugging, I found that the context.info_name contains the the abbreviated sub command name. I think when a sub-command context is being created, it should use the full command name for this field rather than what the user typed.

@dvstans
Copy link
Author

dvstans commented Nov 14, 2019

I believe line 1280 in core.py should be:

    return cmd.name, cmd, args[1:]

instead of:

    return cmd_name, cmd, args[1:]

@ovezovs
Copy link
Contributor

ovezovs commented Jun 30, 2020

In an attempt to reproduce this issue, I have tried the following example:

# main.py
class AliasedGroup(click.Group):
    def get_command(self, ctx, cmd_name):
        rv = click.Group.get_command(self, ctx, cmd_name)
        if rv is not None:
            return rv
        matches = [x for x in self.list_commands(ctx)
                   if x.startswith(cmd_name)]
        if not matches:
            return None
        elif len(matches) == 1:
            return click.Group.get_command(self, ctx, matches[0])
        ctx.fail('Too many matches: %s' % ', '.join(sorted(matches)))

@click.command(cls=AliasedGroup)
def cli():
    pass
@cli.command()
def push():
    click.echo('this is push')
@cli.command()
def pop():
    click.echo('this is pop')

if __name__ == '__main__':
    cli()
$ python main.py pu --help
Usage: main.py push [OPTIONS]

Options:
  --help  Show this message and exit.

Based on the above input/output, I am getting the full name of the push subcommand in the Usage part. Therefore, I was not able to reproduce the issue, @davidism.

@davidism
Copy link
Member

After triple checking, the example does reproduce the issue, there was some confusion over a few things being worked on at the same time.

@davidism davidism added this to the 8.0.0 milestone Jun 30, 2020
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Nov 13, 2020
@davidism
Copy link
Member

Reverted in #1915, see #1895

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 a pull request may close this issue.

3 participants