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.2.0.tar.gz (6.8 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.2.0-py3-none-any.whl (4.0 kB view details)

Uploaded Python 3

File details

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

File metadata

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

File hashes

Hashes for usage_spec_typer-1.2.0.tar.gz
Algorithm Hash digest
SHA256 c827e804b4816bdcd9ddaaf9342b20c50a72733df680f378704b0e69b37cfe6d
MD5 6f8173e2f72a5ac162768b450236e50a
BLAKE2b-256 00f2ceeef6f0fb21e120c21e72939a6538b69601702cd5b211e66b27c45f4185

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for usage_spec_typer-1.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 c2ee798940296d711f3b86817f728a2baf0ab8c7b803bb6a7dc7d4bf771cb183
MD5 845a5008ba0a837e6ed6b3002a85b26d
BLAKE2b-256 e90a4d7c0ba395035e02334650469e4f3c79c614de8d5cfd6e016858b80dbe55

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