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

Allow the creation of command aliases #60

Open
richieadler opened this issue Aug 22, 2020 · 4 comments
Open

Allow the creation of command aliases #60

richieadler opened this issue Aug 22, 2020 · 4 comments

Comments

@richieadler
Copy link

In many cases, several names are needed to invoke the same command.

It would be nice to have a way to specify an alias for a command, and have the alias mentioned in the help, without the need to define repeated entries in a command dictionary, and without the redefined function appearing several times in the help message.

For instance, doing this:

# 1.py
import clize

def foo():
    "Function foo"
    pass

def bar():
    "Function bar"
    pass


if __name__ == '__main__':
    clize.run(dict(foo=foo, bar=bar, foo2=foo))

produces

Usage: 1.py command [args...]

Commands:
  foo    Function foo
  bar    Function bar
  foo2   Function foo

The desired outcome (by whatever method is implemented) would be more like

Usage: 1.py command [args...]

Commands:
  foo    Function foo (alias: foo2)
  bar    Function bar
@richieadler
Copy link
Author

@epsy any chance of visiting this?

@richieadler
Copy link
Author

In 4.1.1 this works, but not in later versions.

@epsy
Copy link
Owner

epsy commented Feb 14, 2022

That's odd, I thought it wasn't released yet? On a modified version of examples/multicommand.py I get this when running it on 4.1.1, 4.1.2, 4.2.0, and 4.2.1:

$ python3 -m examples.multicommands_double_spell --help
Usage: python3 -m examples.multicommands_double_spell command [args...]

A reliable to-do list utility.

Store entries at your own risk.

Commands:
  add    Adds an entry to the to-do list.
  show   Lists the existing entries.
  list   Lists the existing entries.

It works on master, were you perhaps running a custom version?

(I'm sorry releasing the next full version is taking so long, I'm trying to get the project in tip-top shape to support Python 3.10 and get ready for 3.11.)

@richieadler
Copy link
Author

That's weird, the [tool.poetry.dependencies] section of my pyproject.toml contains:

clize = {git = "https://github.com/epsy/clize.git", rev = "4.1.1"}

it a separate assignment to a new entry for the same function results in an alias.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
2 participants