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
Release files for usage-spec-argparse 1.2.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| usage_spec_argparse-1.2.0.tar.gz | 7.3 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| usage_spec_argparse-1.2.0-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 11.8 kB
Release files / usage_spec_argparse-1.2.0.tar.gz
| Download URL | usage_spec_argparse-1.2.0.tar.gz |
|---|---|
| Size | 7.3 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
d384d073fd7357119abeba01f8f275e5e3a6d2eeae0150ffaca9dab7342e91bb
|
|
BLAKE2b-256 checksum How to use checksums |
537f8d2c0a19e03091ecb22fcd6abc3fc60199053544058583caaaca8e46de7b
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
uv/0.7.14
|
Release files / usage_spec_argparse-1.2.0-py3-none-any.whl
| Download URL | usage_spec_argparse-1.2.0-py3-none-any.whl |
|---|---|
| Size | 4.5 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
54b7834e4d8a36a09328f7be5f241cc801b6f069a12577df044b894da8574454
|
|
BLAKE2b-256 checksum How to use checksums |
c2f5f8a597b0f4f1b3052fd3d909170614854517124aa3d2d8f7c4798f6bffce
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
uv/0.7.14
|