Decorator-based CLI framework with rich output
Project description
philiprehberger-cli-builder
Decorator-based CLI framework with rich output.
Installation
pip install philiprehberger-cli-builder
Usage
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()
Output Helpers
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
Command Aliases
@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
Decorators
| Decorator | Description |
|---|---|
@cli.command() |
Register a command |
@arg(name) |
Positional argument |
@option(--name, -n) |
Named option with optional short form |
API
| 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 |
Development
pip install -e .
python -m pytest tests/ -v
Support
If you find this project useful:
License
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file philiprehberger_cli_builder-0.2.0.tar.gz.
File metadata
- Download URL: philiprehberger_cli_builder-0.2.0.tar.gz
- Upload date:
- Size: 7.3 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.12.13
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
bfd48d05d550655cd9473ec7414fb981a22539416582757ad58ecc3badeafc33
|
|
| MD5 |
bdd7a1d10d280d2d66ad10700ff40f57
|
|
| BLAKE2b-256 |
60bc0feeb7cc36bb7add6d32a31c6eba3b51ef0d35f9f97a5561ac7d203df97f
|
File details
Details for the file philiprehberger_cli_builder-0.2.0-py3-none-any.whl.
File metadata
- Download URL: philiprehberger_cli_builder-0.2.0-py3-none-any.whl
- Upload date:
- Size: 6.0 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.12.13
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
8e1aaaefba390c5344b0998a109456f185c2b1ac26b17c223ca6e03a6c739101
|
|
| MD5 |
10744bb7e847ebe4cbdad30e238b97fb
|
|
| BLAKE2b-256 |
6dc940f5d069320139ccd3c2dd307eebf0c77e674a5604d3fbb36ac4e541a35f
|