Skip to main content

Decorator-based CLI framework with rich output

Project description

philiprehberger-cli-builder

Tests PyPI version Last updated

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

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
arg(name, help, type) Decorator to define a positional argument on a command
option(name, short, help, 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:

Star the repo

🐛 Report issues

💡 Suggest features

❤️ Sponsor development

🌐 All Open Source Projects

💻 GitHub Profile

🔗 LinkedIn Profile

License

MIT

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

philiprehberger_cli_builder-0.1.10.tar.gz (6.3 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

philiprehberger_cli_builder-0.1.10-py3-none-any.whl (5.7 kB view details)

Uploaded Python 3

File details

Details for the file philiprehberger_cli_builder-0.1.10.tar.gz.

File metadata

File hashes

Hashes for philiprehberger_cli_builder-0.1.10.tar.gz
Algorithm Hash digest
SHA256 a596285f37c693156c72fd699f26fb72f1e214a41e1a7963831188292e0ba268
MD5 792b04d7de962df1371f6b4b98c396b8
BLAKE2b-256 c05f1a25fde149a57f7c94b17effba995c5d9e46c2fda9a4c171e73cbe1c7e64

See more details on using hashes here.

File details

Details for the file philiprehberger_cli_builder-0.1.10-py3-none-any.whl.

File metadata

File hashes

Hashes for philiprehberger_cli_builder-0.1.10-py3-none-any.whl
Algorithm Hash digest
SHA256 91faaf13a86c8264d8749f16d8bc0edd22efe96c2f7faa66fe3f04db28832aab
MD5 f6e31c6861f41da69538545327a79a4f
BLAKE2b-256 3e507ae32c232ade54ad53a0788b8a10170654914c963be6a38b5111235ee813

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page