Skip to main content

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


Download files

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

Source Distribution

usage_spec_typer-1.1.0.tar.gz (6.7 kB view details)

Uploaded Source

Built Distribution

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

usage_spec_typer-1.1.0-py3-none-any.whl (4.0 kB view details)

Uploaded Python 3

File details

Details for the file usage_spec_typer-1.1.0.tar.gz.

File metadata

  • Download URL: usage_spec_typer-1.1.0.tar.gz
  • Upload date:
  • Size: 6.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.7.14

File hashes

Hashes for usage_spec_typer-1.1.0.tar.gz
Algorithm Hash digest
SHA256 828788e6a2b5d16b04a3621ce4de7597b5689344a82e4adf7af356c4068b7627
MD5 af38bd738a8187c35f7a4705ffb01cae
BLAKE2b-256 1f27fcd7b8428c116bb320c4370541396e20b85eca7d4c18e787c8738921f3a7

See more details on using hashes here.

File details

Details for the file usage_spec_typer-1.1.0-py3-none-any.whl.

File metadata

File hashes

Hashes for usage_spec_typer-1.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 06500bbe3d34c0ea66a3ea6bb914ae0987948d00c9b1623d5f98814e8cad1d6e
MD5 ba7bc0de422df3f50c642e89c5c5060d
BLAKE2b-256 9e41b70da03c9a5c978def29d883fe76ea8277d332904d85e639b0d0056f1239

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