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

Aliases not added if Group is initialized with a list of commands #172

Closed
ououmania opened this issue Dec 18, 2023 · 2 comments · Fixed by #173
Closed

Aliases not added if Group is initialized with a list of commands #172

ououmania opened this issue Dec 18, 2023 · 2 comments · Fixed by #173
Labels
bug Something isn't working

Comments

@ououmania
Copy link

ououmania commented Dec 18, 2023

Bug description
The subcommands' aliases are not added if a cloup.Group is instantiated directly with subcommands.

To Reproduce
The following snippet can be used to show the problem.

import cloup

@cloup.command(aliases=["t"])
def cmd():
    pass


cloup.Group("cli", show_subcommand_aliases=True, commands=[cmd])()

Save it in cloup_test.py and run the script. An error message will be printed.

Usage: cloup_test.py [OPTIONS] COMMAND [ARGS]...
Try 'cloup_test.py --help' for help.

Error: No such command 't'.

Possible solution
Init alias2name correctly in cloup.Group.init

def __init__(
  self, *args: Any, show_subcommand_aliases: Optional[bool] = None, **kwargs: Any
):
  super().__init__(*args, **kwargs)
  self.show_subcommand_aliases = show_subcommand_aliases
  self.alias2name: Dict[str, str] = {}

  # Add the following lines to initialize the alias dictionary.
  **for name, cmd in self.commands.items():
    for alias in getattr(cmd, 'aliases', []):
      self.alias2name[alias] = name**
@ououmania ououmania added the enhancement New feature or request label Dec 18, 2023
@janluke janluke changed the title Aliaes not added if cloup.Group is initialized with a list of commands Aliases not added if cloup.Group is initialized with a list of commands Dec 18, 2023
@janluke janluke changed the title Aliases not added if cloup.Group is initialized with a list of commands Aliases not added if Group is initialized with a list of commands Dec 18, 2023
@janluke
Copy link
Owner

janluke commented Dec 18, 2023

Hi @ououmania, thanks for reporting. This looks like a bug, I'll look into it when I have time. Can you please file this issue as a bug and re-describe it in the following format to add clarity and ease my testing? You can leave your current snippet as proposed solution at the end of the issue. Always start a bug with a reproducible example. Thank you.

Bug description

A clear and concise description of what the bug is.

To Reproduce

Steps to reproduce the behavior:

  1. Go to '...'
  2. Click on '....'
  3. Scroll down to '....'
  4. See error

Expected behavior

Delete this section if the expected behavior is obvious.

@janluke janluke added bug Something isn't working and removed enhancement New feature or request labels Dec 18, 2023
@ououmania
Copy link
Author

Hi @ououmania, thanks for reporting. This looks like a bug, I'll look into it when I have time. Can you please file this issue as a bug and re-describe it in the following format to add clarity and ease my testing? You can leave your current snippet as proposed solution at the end of the issue. Always start a bug with a reproducible example. Thank you.

Bug description

A clear and concise description of what the bug is.

To Reproduce

Steps to reproduce the behavior:

  1. Go to '...'
  2. Click on '....'
  3. Scroll down to '....'
  4. See error

Expected behavior

Delete this section if the expected behavior is obvious.

Thanks for your reply. Sure. I've updated the comment.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants