CLI
An extremely easy to use library to generate python CLIs from functions through introspection.
Automatically generate the equivalent of this:
import argparse
parser = argparse.ArgumentParser(description="Generate a cryptographic token with a given entropy.")
parser.add_argument('method', nargs='?', default='xkcd', choices=('xkcd', 'short'))
parser.add_argument('entropy', nargs='?', default=70, type=int)
args = parser.parse_args()
if args.method == 'xkcd':
print(xkcd(args.entropy))
else:
print(alphanumeric(args.entropy))
from this:
from cli import Choice, cli
def token(method:Choice('xkcd', 'short')='xkcd', entropy=70):
"Generate a cryptographic token with a given entropy."
if method == 'xkcd':
return xkcd(entropy)
else:
return alphanumeric(entropy)
cli(token)()
Keyword arguments (optional or mandatory) are supported as is one varargs argument per function. Arguments will be automatically converted into the type of their default argument (if it is not None) or their type annotation.
You can even generate CLIs for a whole module (or any other object with function attributes):
import example
from cli import cli
# convert_numbers automatically converts strings to int, float or complex so
# you don't have to annotate all the functions in a module. YMMV.
cli(example, convert_numbers=True)()
# You can get a reference to the current module with sys.modules[__name__]
Code quality
The code is very short, clearly documented inline and all advertised features are tested.
Reference
def example(positional, arguments):
pass
def defaults(normally_one=1):
pass
def typed(positional:bool, positional2:int):
pass
def keyword(positional, *, keyword1=False, keyword2='default_filename'):
pass
def mandatory_keywords(positional, *, keyword1, keyword2):
pass
def varargs(pos1, pos2, *rest):
pass
def choice_from_list(person:Choice('Ann', 'Bob', 'Charlie'))
pass
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 cmcaine-cli-0.0.1.tar.gz.
File metadata
- Download URL: cmcaine-cli-0.0.1.tar.gz
- Upload date:
- Size: 3.9 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via:
twine/1.13.0 pkginfo/1.5.0.1 requests/2.21.0 setuptools/41.0.1 requests-toolbelt/0.9.1 tqdm/4.28.1 CPython/3.7.3
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
f635c9d36f5a244ea49545558cdbd82bd9a974f32ad8f65ff3b5e10ebd7252b8
|
|
| MD5 |
346bae35c46d2105c2889bff6f3668e9
|
|
| BLAKE2b-256 |
0e212e63ad0516c9fc37d3ad61e11db8ceaf13c233609afdff90d5ec887d3cd8
|
File details
Details for the file cmcaine_cli-0.0.1-py3-none-any.whl.
File metadata
- Download URL: cmcaine_cli-0.0.1-py3-none-any.whl
- Upload date:
- Size: 4.4 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via:
twine/1.13.0 pkginfo/1.5.0.1 requests/2.21.0 setuptools/41.0.1 requests-toolbelt/0.9.1 tqdm/4.28.1 CPython/3.7.3
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
07c02b53dc7d5527c10ef1b3a658e481836bb23cb2b408fef7fcf29e8cd29c29
|
|
| MD5 |
0632cf3a495b4f0dff4dbb7834b3d132
|
|
| BLAKE2b-256 |
317af450d62d889174b6888d2f75f654cfba8bf9d382206ead2a2c15f4993496
|