# simple-cli-args
A python main method decorator.<br>
An enhancement of the `argparse` package for its simplest usages.<br>
**Requires python 3.6 or higher.**
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.<br>
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 `python3`
python3 -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: green
#### Decorate a main class
If main functionality is built into a class, the decorator can be used for its contructor `__init__` method, as well as for the class itself, like in the example below.
#!/usr/bin/env python3
from simple_cli_args import cli_args
@cli_args
class Main:
def __init__(self, apple, banana, cucumber='green'):
self.fruits = apple, banana, cucumber
def show(self):
print("Our fruits are:", *self.fruits)
if __name__ == '__main__':
main = Main() # without arguments given, those will be read from the CLI
main.show()
Raw data
{
"_id": null,
"home_page": "https://github.com/zellerede/simple-cli-args",
"name": "simple-cli-args",
"maintainer": "",
"docs_url": null,
"requires_python": "",
"maintainer_email": "",
"keywords": "argparse cli cli-args cli_args simple-cli-args simple_cli_args",
"author": "Bertalan Pecsi",
"author_email": "zellerede@gmail.com",
"download_url": "https://files.pythonhosted.org/packages/16/86/0553d2b15ebc07f840525f033d31ec600174c70f4e0cb78d4fd463371a24/simple_cli_args-1.2.tar.gz",
"platform": null,
"description": "# simple-cli-args\nA python main method decorator.<br>\nAn enhancement of the `argparse` package for its simplest usages.<br>\n**Requires python 3.6 or higher.**\n\nThe ordinary arguments become positional, the arguments with default value become named argument for the CLI, \nwith a possibility of abbreviations, as `argparse` provides it.<br>\nHelp option (`-h` or `--help`) is automatically generated with its text taken from the docstrings.\n\n### Install\n\n#### Using pip\n pip install simple_cli_args\n\nor, with your intended python command in place of `python3`\n\n python3 -m pip install simple_cli_args\n\n#### Using setuptools\nSimply issue in the main directory of the cloned git repository:\n\n ./setup.py install\n\n### Usage\nAssume the content of *my_cli.py* is:\n\n #!/usr/bin/env python3\n from simple_cli_args import cli_args\n \n @cli_args\n def main(apple, banana, cucumber='green'):\n print(\"Our fruits are:\", apple, banana, cucumber)\n \n if __name__ == '__main__':\n main() # without arguments given, those will be read from the CLI\n\nThen, we get the following printouts:\n\n $ ./my_cli.py red yellow\n Our fruits are: red yellow green\n\n $ ./my_cli.py red yellow --cucumber=purple\n Our fruits are: red yellow purple\n\n $ ./my_cli.py red yellow -c nice\n Our fruits are: red yellow nice\n\n $ ./my_cli.py red\n usage: my_cli.py [-h] [--cucumber | -c CUCUMBER] apple banana\n my_cli.py: error: the following arguments are required: banana\n\n $ ./my_cli.py --help\n usage: my_cli.py [-h] [--cucumber | -c CUCUMBER] apple banana\n \n positional arguments:\n apple\n banana\n \n optional arguments:\n -h, --help show this help message and exit\n --cucumber | -c CUCUMBER\n default: green\n \n#### Decorate a main class\n\nIf main functionality is built into a class, the decorator can be used for its contructor `__init__` method, as well as for the class itself, like in the example below.\n\n #!/usr/bin/env python3\n from simple_cli_args import cli_args\n \n @cli_args\n class Main:\n def __init__(self, apple, banana, cucumber='green'):\n self.fruits = apple, banana, cucumber\n def show(self):\n print(\"Our fruits are:\", *self.fruits)\n \n if __name__ == '__main__':\n main = Main() # without arguments given, those will be read from the CLI\n main.show()\n\n\n\n",
"bugtrack_url": null,
"license": "",
"summary": "An enhancement of argparse package for its simplest usages",
"version": "1.2",
"project_urls": {
"Homepage": "https://github.com/zellerede/simple-cli-args"
},
"split_keywords": [
"argparse",
"cli",
"cli-args",
"cli_args",
"simple-cli-args",
"simple_cli_args"
],
"urls": [
{
"comment_text": "",
"digests": {
"blake2b_256": "16860553d2b15ebc07f840525f033d31ec600174c70f4e0cb78d4fd463371a24",
"md5": "553660032eeeb5824575c024c862e221",
"sha256": "b9d51edac50f22dc34bd3d4691fcdce087110c6c7a8cd9460e595a061e1a292b"
},
"downloads": -1,
"filename": "simple_cli_args-1.2.tar.gz",
"has_sig": false,
"md5_digest": "553660032eeeb5824575c024c862e221",
"packagetype": "sdist",
"python_version": "source",
"requires_python": null,
"size": 5905,
"upload_time": "2023-11-10T11:35:58",
"upload_time_iso_8601": "2023-11-10T11:35:58.691125Z",
"url": "https://files.pythonhosted.org/packages/16/86/0553d2b15ebc07f840525f033d31ec600174c70f4e0cb78d4fd463371a24/simple_cli_args-1.2.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2023-11-10 11:35:58",
"github": true,
"gitlab": false,
"bitbucket": false,
"codeberg": false,
"github_user": "zellerede",
"github_project": "simple-cli-args",
"travis_ci": false,
"coveralls": false,
"github_actions": false,
"lcname": "simple-cli-args"
}