Skip to main content

Generates usage spec for CLIs written with argparse

Project description

usage-spec-argparse

Generates usage spec for CLIs written with argparse.

Install

pip install usage-spec-argparse

Usage

import argparse
from argparse_usage import generate

parser = argparse.ArgumentParser(prog="mycli", description="My CLI tool")
parser.add_argument("-v", "--verbose", action="store_true", help="Enable verbose output")
parser.add_argument("-f", "--file", help="Input file")
parser.add_argument("--no-color", action="store_false", help="Disable colored output")

print(generate(parser))

API

generate(parser, bin_name=None)

Generates a usage spec in KDL format from an argparse.ArgumentParser.

generate_kdl(parser, bin_name=None)

Alias for generate().

generate_json(parser, bin_name=None)

Generates a usage spec in JSON format.

convert_root(parser, bin_name=None)

Converts an argparse.ArgumentParser to the Spec data structure.

Supported Features

argparse Feature Usage Spec Mapping
prog name / bin
--version action version
description about
epilog long_about
add_argument() (optional) flag
add_argument() (positional) arg
required=True flag required=#true
action="store_true"/"store_false" Boolean flag (no arg)
action="store_false" negate
action="count" count=#true
nargs="?" required=#false
nargs="*"/"+" var=#true
choices=[...] choices
default=... default
help=SUPPRESS hide=#true
add_subparsers() cmd (recursive)
Non-runnable subcommand groups subcommand_required=#true

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_argparse-1.1.0.tar.gz (7.2 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_argparse-1.1.0-py3-none-any.whl (4.5 kB view details)

Uploaded Python 3

File details

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

File metadata

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

File hashes

Hashes for usage_spec_argparse-1.1.0.tar.gz
Algorithm Hash digest
SHA256 83f4a85b872db9a38bb75234005b2246546818f46a75d0c3a0e71f4005342daa
MD5 5622c5dfca5697dc2e82d7ea7b53d6ac
BLAKE2b-256 3b4ac80015bfc69165102e9321f854d9b81c47f38435ffb56364d5b73d0895a3

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for usage_spec_argparse-1.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 24ff805347f0247af2e1e5ac7741bbe16eeb8dc15b9a0978c926b74d953bbdfe
MD5 43a6a33dbc280e9217d8850b484af930
BLAKE2b-256 bc5bf36dbffcea4e19ad2a5cb781e115b592319ac5b0b3285564bd6dc03c93b0

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