clize icon indicating copy to clipboard operation
clize copied to clipboard

Allow the creation of command aliases

Open richieadler opened this issue 5 years ago • 4 comments

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 avatar Aug 22 '20 00:08 richieadler

@epsy any chance of visiting this?

richieadler avatar Oct 14 '21 19:10 richieadler

In 4.1.1 this works, but not in later versions.

richieadler avatar Feb 13 '22 16:02 richieadler

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.)

epsy avatar Feb 14 '22 03:02 epsy

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.

richieadler avatar Feb 14 '22 23:02 richieadler