Generates usage spec for CLIs written with Typer
Project description
usage-spec-typer
Generates usage spec for CLIs written with Typer.
Install
pip install usage-spec-typer
Usage
import typer
from typer_usage import generate
app = typer.Typer(help="My CLI tool")
@app.command()
def hello(name: str = typer.Argument(help="Your name")):
"""Say hello"""
@app.command()
def build(
output: str = typer.Option("dist", help="Output directory"),
verbose: bool = typer.Option(False, help="Enable verbose output"),
):
"""Build the project"""
print(generate(app, "mycli"))
API
generate(app, bin_name=None)
Generates a usage spec in KDL format from a Typer Typer app.
generate_kdl(app, bin_name=None)
Alias for generate().
generate_json(app, bin_name=None)
Generates a usage spec in JSON format.
convert_root(app, bin_name=None)
Converts a Typer Typer app to the Spec data structure.
Supported Features
| Typer Feature | Usage Spec Mapping |
|---|---|
app.info.name / bin_name |
name / bin |
app.info.help |
about |
typer.Option() |
flag |
typer.Argument() |
arg |
typer.Option(..., help=) |
Flag help |
typer.Argument(..., help=) |
Arg help |
typer.Option(...) (ellipsis) |
flag required=#true |
bool type options |
Boolean flag (no arg) |
--flag/--no-flag |
negate |
count=True |
count=#true |
type=click.Choice() |
choices |
default=... |
default |
hidden=True |
hide=#true |
envvar="..." |
env |
app.add_typer() |
cmd (recursive) |
| Subcommand groups | subcommand_required=#true |
| Single command app | Treated as root-level |
--install-completion / --show-completion |
Filtered out |
License
MIT
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 usage_spec_typer-1.0.0.tar.gz.
File metadata
- Download URL: usage_spec_typer-1.0.0.tar.gz
- Upload date:
- Size: 6.7 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.7.14
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
41f88376f28b4701448cd0a576be8eab481201ac59eb5e7df62f404a96bfe324
|
|
| MD5 |
ef495585d50caec3486286af2c850bf8
|
|
| BLAKE2b-256 |
a69383d83bc9920a87851a73511103c7acb78bb1f7e03ee73c635140ab1c7d13
|
File details
Details for the file usage_spec_typer-1.0.0-py3-none-any.whl.
File metadata
- Download URL: usage_spec_typer-1.0.0-py3-none-any.whl
- Upload date:
- Size: 4.0 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.7.14
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
7a09f4fa8216c95a7a2b217a3ae1c12cda4612784b18bc0ebaa628484ce399f6
|
|
| MD5 |
650dd90c0bbefd6de53f9d4efb7dda92
|
|
| BLAKE2b-256 |
1f93a800caec8686ab6b2dee1f4c4987c9c9e96cbd9143c71bf536262c525de0
|