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

Uploaded Python 3

File details

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

File metadata

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

File hashes

Hashes for usage_spec_argparse-1.2.0.tar.gz
Algorithm Hash digest
SHA256 d384d073fd7357119abeba01f8f275e5e3a6d2eeae0150ffaca9dab7342e91bb
MD5 87526aeeb9da3883ec4fa9027163c538
BLAKE2b-256 537f8d2c0a19e03091ecb22fcd6abc3fc60199053544058583caaaca8e46de7b

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for usage_spec_argparse-1.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 54b7834e4d8a36a09328f7be5f241cc801b6f069a12577df044b894da8574454
MD5 7af534f21003ba3354921182ae80be57
BLAKE2b-256 c2f5f8a597b0f4f1b3052fd3d909170614854517124aa3d2d8f7c4798f6bffce

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