sander76 / clipstick

create cli applications using pydantic models
https://sander76.github.io/clipstick/
MIT License
27 stars 3 forks source link

Add the ability to create aliases for subcommands #62

Open richieadler opened 2 months ago

richieadler commented 2 months ago

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.