{ "info": { "author": "valtron", "author_email": "", "bugtrack_url": null, "classifiers": [ "License :: OSI Approved :: MIT License", "Operating System :: OS Independent", "Programming Language :: Python :: 3.5", "Programming Language :: Python :: 3.6", "Programming Language :: Python :: 3.7", "Programming Language :: Python :: 3 :: Only" ], "description": "# FunCLI [![PyPI](https://img.shields.io/pypi/pyversions/funcli.svg?style=plastic)](https://gitlab.com/valtron/funcli)\n\nAutomatically generate a simple CLI.\n\n## Installation\n\n```\npip install funcli\n```\n\n## Basic Usage\n\n```python\ndef main(*args: int):\n\tprint(\"Sum:\", sum(args))\n\nif __name__ == '__main__':\n\timport funcli\n\tfuncli.main()\n\n# $ python sum.py 1 2 3\n# Sum: 6\n```\n\n`--help` is autogenerated by the backend (argparse):\n\n```\n$ python sum.py -h\nusage: sum.py [-h] [args [args ...]]\n\npositional arguments:\n\targs\n\noptional arguments:\n\t-h, --help show this help message and exit\n```\n\n## Advanced Usage\n\n```python\nfrom typing import Optional, List\n\ndef foo(): pass\ndef bleep(): pass\ndef bloop(a, b: int = 0, *c: str, d: Optional[List[float]] = None):\n\tprint(\"Args:\", a, b, c, d)\n\nif __name__ == '__main__':\n\timport funcli\n\tfuncli.main({ 'foo': foo, 'bar': { bleep, bloop } })\n\n# $ python advanced.py bar bloop arg0 c0 c1 --b=987 --d 42 -0.3\n# Args: arg0 987 ('c0', 'c1'), [42, -0.3]\n```\n\n## Reference\n\n```python\nfuncli.main(spec = None)\n```\n\nSugar. `spec` defaults to the `main` function from the caller's scope.\nCalls `funcli.run` on `spec`, and calls `sys.exit` with the return value.\n\n```python\nfuncli.run(spec, args = None, converters = None)\n```\n\n- `spec` is either a callable, a sequence of callables, or a dict mapping strings to nested `specs`\n- `args` default to `sys.argv[1:]`\n- `converters` is a mapping from types (or whatever you want to use as annotations) to a function that parses a command line argument\n\nGiven functions `foo`, `bar`, `baz`, here are some sample invocations:\n\n```python\nfuncli.run(foo, ['arg0']) # Calls foo('arg0')\nfuncli.run({ foo, bar }, ['bar', 'arg0']) # Calls bar('arg0')\nfuncli.run({ 'beep': foo, 'bloop': [bar, baz] }, ['beep', 'arg0']) # Calls foo('arg0')\nfuncli.run({ 'beep': foo, 'bloop': [bar, baz] }, ['bloop', 'bar', 'arg0']) # Calls bar('arg0')\n```\n\n### `bool` arguments\n\nNon-optional bool values should be passed as `True` and `False` on the command line.\nOptional bool values, on the other hand, must be omitted.\n\n```python\ndef f(warnings: bool = False): ...\nfuncli.run(f, ['--warnings']) # f(warnings = True)\n```\n\n*Note:* currently, if the default value is `True`, there is no way to pass `False`.\n\n### Converters\n\nBuilt-in converters handle `int`, `float`, `bool`, and `pathlib.Path`. Unannotated args are kept as a `str`.\nBasic sequence types (`list`/`List[T]`, `set`/`Set[T]`, `tuple`/`Tuple[T, ...]`, `Iterable[T]`, `Sequence[T]`) are supported, but only as optional arguments, e.g.:\n\n```python\ndef f(mylist: List[int] = []): ...\nfuncli.run(f, ['--mylist', '1', '2']) # f([1, 2])\n```\n\n`Optional[T]` is supported, but there's currently no way to explicitly pass `None` values.\n\n### Notes\n\nBecause of `argparse` limitations:\n- `**kwargs` aren't supported; if your function has them, they'll always be empty\n- optional arguments cannot be positional; `f(a = 'default')` has to be invoked as `python foo.py --a=nondefault`\n\n\n", "description_content_type": "text/markdown", "docs_url": null, "download_url": "", "downloads": { "last_day": -1, "last_month": -1, "last_week": -1 }, "home_page": "https://gitlab.com/valtron/funcli", "keywords": "", "license": "", "maintainer": "", "maintainer_email": "", "name": "funcli", "package_url": "https://pypi.org/project/funcli/", "platform": "", "project_url": "https://pypi.org/project/funcli/", "project_urls": { "Homepage": "https://gitlab.com/valtron/funcli" }, "release_url": "https://pypi.org/project/funcli/0.4.0/", "requires_dist": null, "requires_python": ">=3.5", "summary": "Automatically generate a simple CLI.", "version": "0.4.0" }, "last_serial": 4591952, "releases": { "0.1.0": [ { "comment_text": "", "digests": { "md5": "84ec405f2656ea68207719a81e0f3d49", "sha256": "d25c86ca8d1f996a593316a98249f00f6c6e8bf1da1a46c84bae2b9b6ef9b52d" }, "downloads": -1, "filename": "funcli-0.1.0.tar.gz", "has_sig": false, "md5_digest": "84ec405f2656ea68207719a81e0f3d49", "packagetype": "sdist", "python_version": "source", "requires_python": ">=3.5", "size": 1841, "upload_time": "2018-08-20T19:32:39", "url": "https://files.pythonhosted.org/packages/cc/6c/b0f6a8874f7a6478889d1cd7ef1a72d8598a8a26b056f866f91b6aee16af/funcli-0.1.0.tar.gz" } ], "0.1.1": [ { "comment_text": "", "digests": { "md5": "2b4e8af363bd6b4d35c405bdaf6245f2", "sha256": "a08850d7b9d39e08301e72bed7102e9a6c5a5b334240cc22114b33bf22d4af8c" }, "downloads": -1, "filename": "funcli-0.1.1.tar.gz", "has_sig": false, "md5_digest": "2b4e8af363bd6b4d35c405bdaf6245f2", "packagetype": "sdist", "python_version": "source", "requires_python": ">=3.6", "size": 3025, "upload_time": "2018-08-20T19:39:03", "url": "https://files.pythonhosted.org/packages/b2/9a/a65fa1da24b2eec97c6a82ad4413675405e6ed17d991243fb8da5cc97cb2/funcli-0.1.1.tar.gz" } ], "0.1.2": [ { "comment_text": "", "digests": { "md5": "79b7a57a37399b248fcc6602e7e2d0ba", "sha256": "cb85a84a005417d47d80ce4a3b62a204977c14e188b964ec70f2194a5e98dec1" }, "downloads": -1, "filename": "funcli-0.1.2.tar.gz", "has_sig": false, "md5_digest": "79b7a57a37399b248fcc6602e7e2d0ba", "packagetype": "sdist", "python_version": "source", "requires_python": ">=3.6", "size": 3290, "upload_time": "2018-08-20T19:45:14", "url": "https://files.pythonhosted.org/packages/82/3c/0378b555099b1d246a3d1150abc95c4363c9771d51bc6b82ea83a9b3e70a/funcli-0.1.2.tar.gz" } ], "0.2.0": [ { "comment_text": "", "digests": { "md5": "0b99b433cac713dde31ce0f4fd1911c9", "sha256": "bd4b98909382d62278529565630e5244a8bfed5d1f03533d0862c94bdc36d4f1" }, "downloads": -1, "filename": "funcli-0.2.0.tar.gz", "has_sig": false, "md5_digest": "0b99b433cac713dde31ce0f4fd1911c9", "packagetype": "sdist", "python_version": "source", "requires_python": ">=3.5", "size": 3754, "upload_time": "2018-08-21T04:01:40", "url": "https://files.pythonhosted.org/packages/a3/45/d37e8a6d17ae2fa37cb418748b00ed2e060c7ce9d22a11dbc841c044b182/funcli-0.2.0.tar.gz" } ], "0.3.0": [ { "comment_text": "", "digests": { "md5": "ef90d578a95e14a88493daedcd89bc00", "sha256": "0bf5841d237f1410c68d04181482ab599c37e62bbb1e92b537258f6f70c89f67" }, "downloads": -1, "filename": "funcli-0.3.0-py3-none-any.whl", "has_sig": false, "md5_digest": "ef90d578a95e14a88493daedcd89bc00", "packagetype": "bdist_wheel", "python_version": "py3", "requires_python": ">=3.5", "size": 4396, "upload_time": "2018-08-21T22:15:33", "url": "https://files.pythonhosted.org/packages/5a/45/577c411954933ba543f67325b306a1a0363b7d92c9823494ca7656b689ce/funcli-0.3.0-py3-none-any.whl" } ], "0.4.0": [ { "comment_text": "", "digests": { "md5": "c8e010932f06b333bbad41341cd59416", "sha256": "fc2fb9efdf48a2a87a4cfa6a3a699a8a33332166d650d2220330b6f550cec6e7" }, "downloads": -1, "filename": "funcli-0.4.0-py3-none-any.whl", "has_sig": false, "md5_digest": "c8e010932f06b333bbad41341cd59416", "packagetype": "bdist_wheel", "python_version": "py3", "requires_python": ">=3.5", "size": 5389, "upload_time": "2018-12-12T22:02:13", "url": "https://files.pythonhosted.org/packages/cc/a3/28fdd091ba61e409371735a0dea7318a05fe87c6c4d32e28500f236346a0/funcli-0.4.0-py3-none-any.whl" } ] }, "urls": [ { "comment_text": "", "digests": { "md5": "c8e010932f06b333bbad41341cd59416", "sha256": "fc2fb9efdf48a2a87a4cfa6a3a699a8a33332166d650d2220330b6f550cec6e7" }, "downloads": -1, "filename": "funcli-0.4.0-py3-none-any.whl", "has_sig": false, "md5_digest": "c8e010932f06b333bbad41341cd59416", "packagetype": "bdist_wheel", "python_version": "py3", "requires_python": ">=3.5", "size": 5389, "upload_time": "2018-12-12T22:02:13", "url": "https://files.pythonhosted.org/packages/cc/a3/28fdd091ba61e409371735a0dea7318a05fe87c6c4d32e28500f236346a0/funcli-0.4.0-py3-none-any.whl" } ] }