An enhancement of argparse package for its simplest usages
Project description
simple-cli-args
A python main method decorator.
An enhancement of the argparse
package for its simplest usages.
The ordinary arguments become positional, the arguments with default value become named argument for the CLI,
with a possibility of abbreviations, as argparse
provides it.
Help option (-h
or --help
) is automatically generated with its text taken from the docstrings.
Install
Using pip
pip install simple_cli_args
or, with your intended python command in place of python
python -m pip install simple_cli_args
Using setuptools
Simply issue in the main directory of the cloned git repository:
./setup.py install
Usage
Assume the content of my_cli.py is:
#!/usr/bin/env python3
from simple_cli_args import cli_args
@cli_args
def main(apple, banana, cucumber='green'):
print("Our fruits are:", apple, banana, cucumber)
if __name__ == '__main__':
main() # without arguments given, those will be read from the CLI
Then, we get the following printouts:
$ ./my_cli.py red yellow
Our fruits are: red yellow green
$ ./my_cli.py red yellow --cucumber=purple
Our fruits are: red yellow purple
$ ./my_cli.py red yellow -c nice
Our fruits are: red yellow nice
$ ./my_cli.py red
usage: my_cli.py [-h] [--cucumber | -c CUCUMBER] apple banana
my_cli.py: error: the following arguments are required: banana
$ ./my_cli.py --help
usage: my_cli.py [-h] [--cucumber | -c CUCUMBER] apple banana
positional arguments:
apple
banana
optional arguments:
-h, --help show this help message and exit
--cucumber | -c CUCUMBER
default: 42
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distributions
No source distribution files available for this release.See tutorial on generating distribution archives.
Built Distributions
simple_cli_args-0.1-py3.7.egg
(5.2 kB
view hashes)
simple_cli_args-0.1-py3.5.egg
(2.8 kB
view hashes)
Close
Hashes for simple_cli_args-0.1-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | f88522f017d1915c23ed10ffb1fe40c6648e23f59f0010f667eb311367dbf84d |
|
MD5 | bd75a1f68f457fff34b4134ae96cb079 |
|
BLAKE2b-256 | 58680ee470a91e11b8e03692168f45b834adecbb0e55bdbffeb14dce50d7395d |