{ "info": { "author": "garenchan", "author_email": "1412950785@qq.com", "bugtrack_url": null, "classifiers": [ "License :: OSI Approved :: BSD License", "Operating System :: OS Independent", "Programming Language :: Python :: 3", "Programming Language :: Python :: 3.3", "Programming Language :: Python :: 3.4", "Programming Language :: Python :: 3.5", "Programming Language :: Python :: 3.6", "Programming Language :: Python :: Implementation :: CPython", "Programming Language :: Python :: Implementation :: PyPy" ], "description": "# PyCLI\nA Tiny Python CLI Library Based On `argparse`, make it easier for us to add subcommands.\n\nIf you use argparse to parse arguments, and you are very upset about adding subcommands and their handlers, then PyCLI is what you want.\n\n[![Build Status](https://api.travis-ci.org/garenchan/pycli.svg?branch=master)](https://travis-ci.org/garenchan/pycli)\n\n## Demo\n\nHere is the simplest demo for pycli.\n\n```\n# demo.py\nfrom pycli import CLI\n\ncli = CLI(prog=\"app\", version=\"v1.0.0\")\n\n@cli.command\ndef add(x, y):\n \"\"\"get sum of two numbers\"\"\"\n return x + y\n\nprint(cli.run())\n```\n\nThen we run it to get help information, a subcommand named `add` is added:\n```\n$ python demo.py -h\nusage: app [-h] [-v] {add} ...\n\noptional arguments:\n -h, --help show this help message and exit\n -v, --version show program's version number and exit\n\nsubcommands:\n {add}\n```\n\nNext we lookup the help information of the subcommand, two positional arguments are added:\n```\n$ python demo.py add -h\nusage: app add [-h] x y\n\nget sum of two numbers\n\npositional arguments:\n x\n y\n\noptional arguments:\n -h, --help show this help message and exit\n```\n\nWe use the subcommand to get sum of two numbers, the output we expected is 3, but 12 is given, so we need to specify the type of arguments:\n```\n$ python demo.py add 1 2\n12\n```\n\n## Argument Type\n\nBy default, type of arguments is `str`, we can change it by function annotation.\n\nWe specify argument `x` and `y` of type int:\n\n```\n# demo.py\nfrom pycli import CLI\n\ncli = CLI(prog=\"app\", version=\"v1.0.0\")\n\n@cli.command\ndef add(x: int, y: int):\n \"\"\"get sum of two numbers\"\"\"\n return x + y\n\nprint(cli.run())\n```\n\nWe run the subcommand to get sum of 1 and 2, now result 3 is given:\n\n```\n# python demo.py add 1 2\n3\n```\n\n## Default Argument\n\nSome arguments may have default values, so we can make it optional and no need to pass them while run.\n\n```\n# demo.py\nfrom pycli import CLI\n\ncli = CLI(prog=\"app\", version=\"v1.0.0\")\n\n@cli.command\ndef add(x: int, y: int = 3):\n \"\"\"get sum of two numbers\"\"\"\n return x + y\n\nprint(cli.run())\n```\n\nWe lookup the help information of the subcommand, `y` becomes a optional argument:\n\n```\n$ python demo.py add -h\nusage: app add [-h] [--y Y] x\n\nget sum of two numbers\n\npositional arguments:\n x type: \n\noptional arguments:\n -h, --help show this help message and exit\n --y Y type: (default: 3)\n```\n\n## List Argument\n\nSometimes we may need a list argument, for example, specifying multiple configuration files:\n\n```\n# demo.py\nfrom pycli import CLI\n\ncli = CLI(prog=\"app\", version=\"v1.0.0\")\n\n@cli.command\ndef init(conf_files: list):\n \"\"\"Initialize system\"\"\"\n\n # do something here\n return conf_files\n\nprint(cli.run())\n```\n\nNow we can pass multiple values to the same argument, and a list of string will return:\n\n```\n$ python demo.py init --conf-files a.ini --conf-files b.ini\n['a.ini', 'b.ini']\n```\n\n## Bool Argument\n\nSometimes we need a argument as a switch, we can speficy its type as bool and give it a default value True/False.\n\nIf we pass it when run, its value will be switched:\n\n```\n# demo.py\nimport queue\nfrom pycli import CLI\n\ncli = CLI(prog=\"app\", version=\"v1.0.0\")\nq = queue.Queue()\n\n@cli.command\ndef get(block: bool = True):\n \"\"\"get a item\"\"\"\n\n return q.get(block)\n\nprint(cli.run())\n```\n\n## Custom Subcommand\n\nBy default, PyCLI use function name or object's class name as subcommand title, and use docstring as subcommand description.\n\nYou can custom them as you wish:\n\n```\n# demo.py\nfrom pycli import CLI\n\ncli = CLI(prog=\"app\", version=\"v1.0.0\")\n\n@cli.command_with_args(title=\"sum\", description=\"Sum of two integers\")\ndef add(x: int, y: int):\n \"\"\"get sum of two numbers\"\"\"\n return x + y\n\nprint(cli.run())\n```\n\nNow a subcommand named `sum` is added as follow:\n\n```\n$ python demo.py sum -h\nusage: app sum [-h] x y\n\nSum of two integers\n\npositional arguments:\n x type: \n y type: \n\noptional arguments:\n -h, --help show this help message and exit\n```\n\n## Integration With Argparse\n\n`pycli.CLI` is a subclass of `argparse.ArgumentParser`, so it has some APIs as `ArgumentParser`.\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://github.com/garenchan/pycli", "keywords": "", "license": "BSD", "maintainer": "", "maintainer_email": "", "name": "py3cli", "package_url": "https://pypi.org/project/py3cli/", "platform": "", "project_url": "https://pypi.org/project/py3cli/", "project_urls": { "Homepage": "https://github.com/garenchan/pycli" }, "release_url": "https://pypi.org/project/py3cli/1.0.1/", "requires_dist": null, "requires_python": "", "summary": "A Tiny Python CLI Library Based On argparse", "version": "1.0.1" }, "last_serial": 4029112, "releases": { "1.0.1": [ { "comment_text": "", "digests": { "md5": "a6afe4a07ea46db3bcaa37bdd4005d8c", "sha256": "3605d3371eadacd5b2223e0f266783ce0d6e6e4795f62e6b77867d58c032eb04" }, "downloads": -1, "filename": "py3cli-1.0.1-py3-none-any.whl", "has_sig": false, "md5_digest": "a6afe4a07ea46db3bcaa37bdd4005d8c", "packagetype": "bdist_wheel", "python_version": "py3", "requires_python": null, "size": 6635, "upload_time": "2018-07-04T07:27:18", "url": "https://files.pythonhosted.org/packages/ec/2a/8f4969fac653dcc1739d563679fad0b29f5b4a37ade3846dbc20640e48ef/py3cli-1.0.1-py3-none-any.whl" }, { "comment_text": "", "digests": { "md5": "cfc114a9d426f297f5df6fcddfe1417c", "sha256": "df2cac3ac85b480ecdb4cfc813fa98e42a2d98fb133f73b6c5be8e211b73f7fc" }, "downloads": -1, "filename": "py3cli-1.0.1.tar.gz", "has_sig": false, "md5_digest": "cfc114a9d426f297f5df6fcddfe1417c", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 10391, "upload_time": "2018-07-04T07:27:20", "url": "https://files.pythonhosted.org/packages/9e/87/9b48c74d6654a673d93048f17c8246b30fff02dd671faee7ef3005d0cbec/py3cli-1.0.1.tar.gz" } ] }, "urls": [ { "comment_text": "", "digests": { "md5": "a6afe4a07ea46db3bcaa37bdd4005d8c", "sha256": "3605d3371eadacd5b2223e0f266783ce0d6e6e4795f62e6b77867d58c032eb04" }, "downloads": -1, "filename": "py3cli-1.0.1-py3-none-any.whl", "has_sig": false, "md5_digest": "a6afe4a07ea46db3bcaa37bdd4005d8c", "packagetype": "bdist_wheel", "python_version": "py3", "requires_python": null, "size": 6635, "upload_time": "2018-07-04T07:27:18", "url": "https://files.pythonhosted.org/packages/ec/2a/8f4969fac653dcc1739d563679fad0b29f5b4a37ade3846dbc20640e48ef/py3cli-1.0.1-py3-none-any.whl" }, { "comment_text": "", "digests": { "md5": "cfc114a9d426f297f5df6fcddfe1417c", "sha256": "df2cac3ac85b480ecdb4cfc813fa98e42a2d98fb133f73b6c5be8e211b73f7fc" }, "downloads": -1, "filename": "py3cli-1.0.1.tar.gz", "has_sig": false, "md5_digest": "cfc114a9d426f297f5df6fcddfe1417c", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 10391, "upload_time": "2018-07-04T07:27:20", "url": "https://files.pythonhosted.org/packages/9e/87/9b48c74d6654a673d93048f17c8246b30fff02dd671faee7ef3005d0cbec/py3cli-1.0.1.tar.gz" } ] }