quick and easy command-line interfaces
Project description
pyminiCLI
the quickest and simplest way to specify command-line interfaces for python scripts and apps.
how it works
simply call minicli.command on a function in your script, and its positional arguments will be interpereted as command-line positionals, its keywords as command-line options, and its docstring used to supplement the usage in --help
If you provide type-hints for any of the arguments, the command-line inputs will be converted to this type for you.
in example.py:
from minicli import command
def a_function(positional1, a_float: float, *args, keyword_only, kwarg='blarg'):
"""
A description of the command
Arguments:
positional1 (integer): the first positional argument
a_float (float): e.g. 1.5
*args: any number of other arguments
keyword_only: non-optional -- argument (a number)
kwarg: an option
"""
print("Hello!")
print('I recieved positional: ', positional1)
print("I converted this for you:", a_float, type(a_float))
print('required keyword: ', keyword_only)
print('other positionals: ', *args)
print('my options are: ', kwarg)
return
command(a_function)
# should have usage, followed by docstring as help
# all positionals should be passed in order
# all options as keywords
the result:
$ python example.py a 1.43 b c d e --keyword_only b --kwarg z
Hello!
I recieved positional: a
I converted this for you: 1.43 <class 'float'>
required keyword: b
other positionals: b c d e
my options are: z
$ python example.py --help
usage: positional1 a_float <args... > [--keyword_only <value> (required)] [--kwarg <value>]
A description of the command
Arguments:
positional1 (integer): the first positional argument
a_float (float): e.g. 1.5
*args: any number of other arguments
keyword_only: non-optional -- argument (a number)
kwarg: an option
Contributing
If you would like to add to pyminiCLI:
- make an issue explaining what improvment you would like to make
- create a pull request
see below for ideas for what to improve
To do
- boolean options
- error incorrectly lists varargs as required
- one-letter flags
- multiple named commands in the same python app
- include type hints in --help
- automatically include defaults in doc
- still work if options provided before positionals
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 Distributions
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 pyminiCLI-0.3.1-py3-none-any.whl.
File metadata
- Download URL: pyminiCLI-0.3.1-py3-none-any.whl
- Upload date:
- Size: 4.3 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.2.0 pkginfo/1.6.1 requests/2.24.0 setuptools/44.0.0 requests-toolbelt/0.9.1 tqdm/4.49.0 CPython/3.8.10
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
7c6df7cd87145a4fd6c18374f4678405d938f16a946a7aa3b1a5c22f8ab5abe7
|
|
| MD5 |
ff386567bde03761e352ffc6717f72c4
|
|
| BLAKE2b-256 |
6800a1a6ec460d53fbcfdd056cbf2d6f4346e0cf11353160191324ccde06fca5
|