clipstick icon indicating copy to clipboard operation
clipstick copied to clipboard

Add the ability to create aliases for subcommands

Open richieadler opened this issue 6 months ago • 0 comments

In this case:

# clipstick_cmds.py
from clipstick import parse
from pydantic import BaseModel


class AlfaCmd(BaseModel):
    """Hacer cosas de alfa"""

    uno: str
    """Parámetro para alfa"""

    def run(self):
        print(f"alfa {self.uno}")


class BetaCmd(BaseModel):
    """Hacer cosas de beta"""

    dos: str
    """Parámetro para beta"""

    def run(self):
        print(f"beta {self.dos}")


class CmdApp(BaseModel):
    """Herramienta de test"""
    subcmd: AlfaCmd | BetaCmd

    def run(self):
        self.subcmd.run()

if __name__ == "__main__":
    app = parse(CmdApp)
    app.run()

the resulting app returns this to the help request:

$ python clipstick_cmds.py -h

Usage: clipstick_cmds.py [Subcommands]

Herramienta de test

Subcommands:
    alfa-cmd             Hacer cosas de alfa
    beta-cmd             Hacer cosas de beta

The command name is taken from the class name. It would be useful to have the ability to add one or more shorter or different alias(es) to the commands.

richieadler avatar Aug 15 '24 15:08 richieadler