Decorator-based CLI framework with rich output
pip install philiprehberger-cli-builderDecorator-based CLI framework with rich output.
pip install philiprehberger-cli-builder
from philiprehberger_cli_builder import CLI, arg, option
cli = CLI(name="myapp", version="1.0.0")
@cli.command()
@arg("name", help="Your name")
@option("--greeting", "-g", default="Hello", help="Greeting to use")
def greet(name: str, greeting: str):
"""Greet someone by name."""
cli.success(f"{greeting}, {name}!")
@cli.command()
@option("--format", "-f", default="table", choices=["json", "table"])
def status(format: str):
"""Show system status."""
data = [{"service": "api", "status": "up"}, {"service": "db", "status": "up"}]
if format == "json":
cli.json(data)
else:
cli.table(data, headers=["Service", "Status"])
cli.run()
cli.success("Done!") # ✓ Done!
cli.error("Failed") # ✗ Failed
cli.warn("Careful") # ! Careful
cli.info("Note") # ℹ Note
cli.json(data) # Pretty-printed JSON
cli.table(data, headers) # Rich table
cli.progress(items) # Progress bar
@cli.command(name="list", aliases=["ls", "l"])
def list_things():
"""List all things."""
...
# All three invocations call list_things:
# myapp list
# myapp ls
# myapp l
| Decorator | Description |
|---|---|
@cli.command() | Register a command |
@arg(name) | Positional argument |
@option(--name, -n) | Named option with optional short form |
| Function / Class | Description |
|---|---|
CLI(name, version, description) | Decorator-based CLI framework with command(), run(), and output helpers |
cli.command(name=None, aliases=None) | Register a command with optional name and aliases |
arg(name, help, type) | Decorator to define a positional argument on a command |
option(name, short, help, type, default, choices, is_flag) | Decorator to define a named option on a command |
pip install -e .
python -m pytest tests/ -v
If you find this project useful: