{ "info": { "author": "Sune Debel", "author_email": "sad@archii.ai", "bugtrack_url": null, "classifiers": [ "Programming Language :: Python :: 3", "Programming Language :: Python :: 3.6", "Programming Language :: Python :: 3.7" ], "description": "# `main_dec`\n\nA small library for painless commandline argument parsing in python.\n## Install\n\n`> pip install main-dec`\n\n## Quickstart\n```python\n# my_cli.py\n\nfrom typing import Tuple\n\nfrom main_dec import main\n\n\n@main\ndef run(required_str: str, optional_int=1, optional_tuple: Tuple[int, ...]=()):\n \"\"\"\n A small example cli\n \n :param required_str: a required str\n :param optional_int: an optional int\n :param optional_tuple: an optional tuple\n \"\"\"\n print('required_str', required_str)\n print('optional_int', optional_int)\n print('optional_tuple', optional_tuple)\n```\n\n```console\n> python -m my_cli -h\nusage: my_cli [-h] [--optional-tuple OPTIONAL_TUPLE [OPTIONAL_TUPLE ...]] [--optional-int OPTIONAL_INT] required_str\n\nA small example cli\n\npositional arguments:\n required_str a required str\n\noptional arguments:\n -h, --help show this help message and exit\n --optional-tuple OPTIONAL_TUPLE [OPTIONAL_TUPLE ...]\n an optional tuple\n --optional-int OPTIONAL_INT\n an optional int\n\n> python -m my_cli arg --optional-int 2 --optional-tuple 1 2 3\nrequired_str arg\noptional_int 2\noptional_tuple (1, 2, 3)\n```\n\n## Required and optional arguments\n\nPositional arguments to your function will be parsed as required arguments to your cli.\nOptional arguments to your function will be parsed as optional arguments.\n```python\n# my_cli.py\n\nfrom main_dec import main\n\n\n@main\ndef run(required_arg: str, optional_arg=''):\n pass\n```\n\n```console\n> python -m my_cli -h\nusage: my_cli [-h] [--optional-arg OPTIONAL_ARG] required_arg\n\npositional arguments:\n required_arg\n\noptional arguments:\n -h, --help show this help message and exit\n --optional-arg\n```\n\n## Flags\nOptional `bool` arguments are parsed as flags, such that passing them\non the commandline \"flips\" their\ntruthiness.\n\n```python\n# my_cli.py\n\nfrom main_dec import main\n\n@main\ndef run(positive_flag=False, negative_flag=True):\n print('positive_flag', positive_flag)\n print('negative_flag', negative_flag)\n```\n```console\n> python -m my_cli --postive-flag --negative-flag\npositive_flag True\nnegative_flag False\n```\n## Type conversions\nPEP484 annotated arguments and arguments with default values will have their\ntypes converted before they are passed to your function.\n```python\n# my_cli.py\n\nfrom typing import Tuple \n\nfrom main_dec import main\n\n\n@main\ndef run(required_float: float, optional_tuple: Tuple[float, ...] = ()):\n print('required_float', required_float)\n print('optional_tuple', optional_tuple)\n```\n```console\n> python -m my_cli 1 --optional-tuple 2 3 4\nrequired_float 1.0\noptional_tuple (2.0, 3.0, 4.0)\n```\nCurrently supported types are `str`, `bytes`, `int`, `float`, `list` (including `typing.List`), `tuple` \n(including `typing.Tuple`) and `Enum`. `str` is the default type\nfor arguments that are not annotated and do not have a default value.\n## Tuple arguments\nTuple arguments can either be parsed as varied length tuples, or fixed length tuples.\n\nFixed length tuples are arguments that are annotated without `...` as a type variable,\nor arguments with default values with mixed types\n\n```python\n# my_cli.py\n\nfrom typing import Tuple\n\nfrom main_dec import main\n\n\n@main\ndef run(fixed_length_tuple1: Tuple[int, int], fixed_length_tuple2=(1, 'arg')):\n pass\n```\n\n```console\n> python -m my_cli -h\nusage: my_cli [-h] [--fixed-length-tuple2 FIXED_LENGTH_TUPLE2 FIXED_LENGTH_TUPLE2] fixed_length_tuple1 fixed_length_tuple1\n\npositional arguments:\n fixed_length_tuple1\n\noptional arguments:\n -h, --help show this help message and exit\n --fixed-length-tuple2 FIXED_LENGTH_TUPLE2 FIXED_LENGTH_TUPLE2\n```\n\nVaried length tuples are arguments that\n\n- Are annotated with `...` as a type variable (e.g `Tuple[int, ...]`)\n- Are annotated simply with `Tuple` or `tuple`\n- Have a tuple as a default value with homogeneous types (e.g `(1, 2)`)\n## Enum arguments\nArguments annotated with`Enum`, or with a default `Enum` type, can be used\nto enforce that an argument must have certain values.\n\n```python\n# my_cli.py\n\nfrom enum import Enum\n\nfrom main_dec import main\n\nclass Choice(Enum):\n first = 1\n second = 2\n\n@main\ndef run(argument_with_choices: Choice):\n print('argument_with_choices', argument_with_choices)\n```\n```console\n> python -b my_cli -h\nusage: my_cli [-h] {first,second}\n\npositional arguments:\n {first,second}\n\noptional arguments:\n -h, --help show this help message and exit\n \n> python -m my_cli second\nargument_with_choices Choice.second\n```\n\nThis can be combined with generic types such as `typing.Tuple` and `typing.List`, as well\nas arguments with default arguments that are `tuple` or `list` types with `Enum` elements. \n\n## CLI Documentation\nDoc strings in ReST or Google style are parsed and used to create usage\nand help messages\n```python\n# my_cli.py\n\nfrom main_dec import main\n\n@main\ndef run(arg: str):\n \"\"\"\n An example cli\n \n :param arg: A required argument\n \"\"\"\n```\n\n```console\n> python -m my_cli -h\nusage: my_cli [-h] arg\n\nAn example cli\n\npositional arguments:\n arg A required argument\n\noptional arguments:\n -h, --help show this help message and exit\n```", "description_content_type": "text/markdown", "docs_url": null, "download_url": "", "downloads": { "last_day": -1, "last_month": -1, "last_week": -1 }, "home_page": "https://github.com/suned/main-dec", "keywords": "", "license": "", "maintainer": "Sune Debel", "maintainer_email": "sad@archii.ai", "name": "main-dec", "package_url": "https://pypi.org/project/main-dec/", "platform": "", "project_url": "https://pypi.org/project/main-dec/", "project_urls": { "Homepage": "https://github.com/suned/main-dec" }, "release_url": "https://pypi.org/project/main-dec/0.1.1/", "requires_dist": [ "stringcase (>=1.2,<2.0)", "docstring-parser (>=0.3.0,<0.4.0)" ], "requires_python": ">=3.6,<4.0", "summary": "A tiny library for creating CLIs", "version": "0.1.1" }, "last_serial": 5453660, "releases": { "0.1.0": [ { "comment_text": "", "digests": { "md5": "42356d686960d97f906c55e5033d4714", "sha256": "9b00a5b7cf7aeb3656c3a697492ae364e4d61391d6c1e1d645da87db87e3815f" }, "downloads": -1, "filename": "main_dec-0.1.0-py3-none-any.whl", "has_sig": false, "md5_digest": "42356d686960d97f906c55e5033d4714", "packagetype": "bdist_wheel", "python_version": "py3", "requires_python": ">=3.6,<4.0", "size": 2889, "upload_time": "2019-06-26T20:32:21", "url": "https://files.pythonhosted.org/packages/8b/10/d194a7e599b53153a4df1f2e6198d4f36b08bf5fd9f188be581db5531fc3/main_dec-0.1.0-py3-none-any.whl" }, { "comment_text": "", "digests": { "md5": "6986ad6a9d021096273e5769fb3ab022", "sha256": "de30ea2e3c7ba84a60a30232aca8fca7d04d022484425db11fceeca6e569c96a" }, "downloads": -1, "filename": "main-dec-0.1.0.tar.gz", "has_sig": false, "md5_digest": "6986ad6a9d021096273e5769fb3ab022", "packagetype": "sdist", "python_version": "source", "requires_python": ">=3.6,<4.0", "size": 2666, "upload_time": "2019-06-26T20:32:19", "url": "https://files.pythonhosted.org/packages/ea/43/e1b02030d2a609ca23b86c37acbfaa59d8ea8c84d944a5510776afbd86cb/main-dec-0.1.0.tar.gz" } ], "0.1.1": [ { "comment_text": "", "digests": { "md5": "ad83af5d8308f11f31e2e7cd81c275b6", "sha256": "1117b0f3c470b5f2b6d33667a1e6e6b1980d204cfaaab493c8fae4991725d1e5" }, "downloads": -1, "filename": "main_dec-0.1.1-py3-none-any.whl", "has_sig": false, "md5_digest": "ad83af5d8308f11f31e2e7cd81c275b6", "packagetype": "bdist_wheel", "python_version": "py3", "requires_python": ">=3.6,<4.0", "size": 4391, "upload_time": "2019-06-26T20:40:09", "url": "https://files.pythonhosted.org/packages/2c/86/90e3ffae09ef9a78516751b10bd8c646769cfc35afef1823f77176818b0f/main_dec-0.1.1-py3-none-any.whl" }, { "comment_text": "", "digests": { "md5": "39b5ee1eaf4d14061f5b62092fbb4090", "sha256": "e64316e9d98f3f5f3f9d319f5a41dbc137d02014263783a7d90ba7d8030e0105" }, "downloads": -1, "filename": "main-dec-0.1.1.tar.gz", "has_sig": false, "md5_digest": "39b5ee1eaf4d14061f5b62092fbb4090", "packagetype": "sdist", "python_version": "source", "requires_python": ">=3.6,<4.0", "size": 4889, "upload_time": "2019-06-26T20:40:07", "url": "https://files.pythonhosted.org/packages/fc/73/5b9026d27e3bec95fe4089237f1cec172c648430f907a93c49d93a75f1d5/main-dec-0.1.1.tar.gz" } ] }, "urls": [ { "comment_text": "", "digests": { "md5": "ad83af5d8308f11f31e2e7cd81c275b6", "sha256": "1117b0f3c470b5f2b6d33667a1e6e6b1980d204cfaaab493c8fae4991725d1e5" }, "downloads": -1, "filename": "main_dec-0.1.1-py3-none-any.whl", "has_sig": false, "md5_digest": "ad83af5d8308f11f31e2e7cd81c275b6", "packagetype": "bdist_wheel", "python_version": "py3", "requires_python": ">=3.6,<4.0", "size": 4391, "upload_time": "2019-06-26T20:40:09", "url": "https://files.pythonhosted.org/packages/2c/86/90e3ffae09ef9a78516751b10bd8c646769cfc35afef1823f77176818b0f/main_dec-0.1.1-py3-none-any.whl" }, { "comment_text": "", "digests": { "md5": "39b5ee1eaf4d14061f5b62092fbb4090", "sha256": "e64316e9d98f3f5f3f9d319f5a41dbc137d02014263783a7d90ba7d8030e0105" }, "downloads": -1, "filename": "main-dec-0.1.1.tar.gz", "has_sig": false, "md5_digest": "39b5ee1eaf4d14061f5b62092fbb4090", "packagetype": "sdist", "python_version": "source", "requires_python": ">=3.6,<4.0", "size": 4889, "upload_time": "2019-06-26T20:40:07", "url": "https://files.pythonhosted.org/packages/fc/73/5b9026d27e3bec95fe4089237f1cec172c648430f907a93c49d93a75f1d5/main-dec-0.1.1.tar.gz" } ] }