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
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
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
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
83f4a85b872db9a38bb75234005b2246546818f46a75d0c3a0e71f4005342daa
|
|
| MD5 |
5622c5dfca5697dc2e82d7ea7b53d6ac
|
|
| BLAKE2b-256 |
3b4ac80015bfc69165102e9321f854d9b81c47f38435ffb56364d5b73d0895a3
|
File details
Details for the file usage_spec_argparse-1.1.0-py3-none-any.whl.
File metadata
- Download URL: usage_spec_argparse-1.1.0-py3-none-any.whl
- Upload date:
- Size: 4.5 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.7.14
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
24ff805347f0247af2e1e5ac7741bbe16eeb8dc15b9a0978c926b74d953bbdfe
|
|
| MD5 |
43a6a33dbc280e9217d8850b484af930
|
|
| BLAKE2b-256 |
bc5bf36dbffcea4e19ad2a5cb781e115b592319ac5b0b3285564bd6dc03c93b0
|