Aliases

Aliases let one command respond to more than one CLI name.

from interfacy import Interfacy


def build(release: bool = False) -> str:
    """Compile the project."""
    return "release" if release else "debug"


parser = Interfacy(print_result=True)
parser.add_command(build, aliases=("b",))
parser.run()
$ python project.py build
$ python project.py b

The canonical name is still build. The alias is only another way to select it from the command line.

Group aliases

CommandGroup also accepts aliases.

from interfacy import CommandGroup

ops = CommandGroup("operations", aliases=("ops",))

And commands inside groups can have aliases:

ops.add_command(build, aliases=("b",))
$ python app.py ops b

Name translation

Python names are translated to kebab-case by default.

def show_status() -> str:
    """Show status."""
    return "ok"
$ python app.py show-status

If you need stable public names that are different from Python names, prefer name= and aliases= over renaming the Python function only for CLI aesthetics.

parser.add_command(show_status, name="status", aliases=("st",))