Skip to main content

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

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

Introspecting registered commands

cli = CLI(name="myapp")

@cli.command()
def foo():
    ...

@cli.command(aliases=["b"])
def bar():
    ...

cli.list_commands()       # ["bar", "foo"] — sorted primary names, aliases excluded
cli.has_command("foo")    # True
cli.has_command("b")      # True — alias match
cli.has_command("missing")  # False

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
cli.list_commands() Return sorted list of registered primary command names (aliases excluded)
cli.has_command(name) Return True if name matches a registered command or alias
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:

⭐ Star the repo

🐛 Report issues

💡 Suggest features

❤️ Sponsor development

🌐 All Open Source Projects

💻 GitHub Profile

🔗 LinkedIn Profile

License

MIT

Release files for philiprehberger-cli-builder 0.3.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for philiprehberger-cli-builder 0.3.0
File Size Uploaded
philiprehberger_cli_builder-0.3.0.tar.gz 178.3 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for philiprehberger-cli-builder 0.3.0
File Interpreter ABI Platform
philiprehberger_cli_builder-0.3.0-py3-none-any.whl Python 3 none any Details

Total release size: 184.7 kB

Release files / philiprehberger_cli_builder-0.3.0.tar.gz

Download URL philiprehberger_cli_builder-0.3.0.tar.gz
Size 178.3 kB
Tags Source
SHA-256 checksum
How to use checksums
f380242a1b46fe858ca82a45899a7c66e321abeb0b0404a91dc1cbd44893da02
BLAKE2b-256 checksum
How to use checksums
eaecdcc2222958a5c0ed797af658ad4fe188da1e1f91da8e80814928615ca830
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.12.13

Release files / philiprehberger_cli_builder-0.3.0-py3-none-any.whl

Download URL philiprehberger_cli_builder-0.3.0-py3-none-any.whl
Size 6.4 kB
Tags Python 3
SHA-256 checksum
How to use checksums
5a0a8fb1b204cd5474e35a0703568876a46386551dd720245afac37dcaed2423
BLAKE2b-256 checksum
How to use checksums
286a9debc203d67d980b35b41d9485116b3cba7866c44033c3049ff6010acc46
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.12.13

Release history Release notifications | RSS feed

This release

0.3.0 This release

2 release files

0.2.0

2 release files

0.1.9

2 release files

0.1.8

2 release files

0.1.7

2 release files

0.1.6

2 release files

0.1.5

2 release files

0.1.4

2 release files

0.1.3

2 release files

0.1.2

2 release files

0.1.1

2 release files

0.1.0

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page