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.0.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.0.0-py3-none-any.whl (4.5 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: usage_spec_argparse-1.0.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.0.0.tar.gz
Algorithm Hash digest
SHA256 e62ff4f87c0f4ec1eb5cfbe6467d464619b2079cbceeba9d81af69903975b2f5
MD5 fb6ba9e628660e4ef8fb3877ba5f186e
BLAKE2b-256 2da9f2ee87efc857af4a222c78c8e93d90cc28edc02c7488db144a905dd2bc4d

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for usage_spec_argparse-1.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 6c2755eb59e9e1f8ad67b6d843fd8c0b15c9dbed0f1e216a28852ac8d774e57a
MD5 bf9746de61382adb7cb28fa73cb00f96
BLAKE2b-256 9d44eb45764f9c56b9d618daf3f3ea555dd7b289cca084201962e61a74a652c6

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