{ "info": { "author": "Ali Rasim Kocal", "author_email": "arkocal@gmail.com", "bugtrack_url": null, "classifiers": [ "License :: OSI Approved :: MIT License", "Operating System :: OS Independent", "Programming Language :: Python :: 3" ], "description": "# cmdmenu\n\n`cmdmenu` is a simple library based on `argparse` for automatically creating command line interfaces\nconsisting of levels of hierarchy (like git) and linking them to functions.\n\n## Installation\n\nRun `pip install cmdmenu`\n\n## Usage\n\nSee `/examples` for full exampes.\n\n### Adding commands\n\nUse the `cmdmenu.add_command` function for adding commands.\n\n```python\nimport argparse\nimport cmdmenu\n\ndef echo(message):\n print(message)\n\ndef mirror_echo(message):\n print(message[::-1])\n\nparser = argparse.ArgumentParser(\"An example application\")\nsubparsers = parser.add_subparsers()\n\ncmdmenu.add_command(subparsers, echo)\ncmdmenu.parse_and_run_with(parser)\n```\n\nRun like this.\n```\n$ python main.py echo Hello\nHello\n$ python main.py mirror_echo Hello\nolleH\n```\n\nYou can add a help message and a description to your commands using the\n`cmdmenu_function` decorator. If you only specify one parameter, it will be used for both,\notherwise, the first one is the short help message, the second one is the description.\n\nYou can also add a string annotation to function parameters to generate help message\n\n```python\n@cmdmenu.cmdmenu_function(\"Echo to terminal\", \"Longer description of echo\")\ndef echo(message: \"Message to echo\"):\n print(message)\n```\n\n```\n$ python main.py --help\nusage: An example application [-h] {echo,mirror_echo} ...\n\npositional arguments:\n {echo,mirror_echo}\n echo Echo to terminal\n mirror_echo Echo reversed\n\noptional arguments:\n -h, --help show this help message and exit\n$ python main.py echo --help\nusage: An example application echo [-h] message\n\nLonger description of echo\n\npositional arguments:\n message Message to echo\n\noptional arguments:\n -h, --help show this help message and exit\n```\n\n#### Default values\n`cmdmenu` respects parameter default values. If a parameter has a default value, a flag will\nbe created for it. You can override the flag name using a dictionary annotation (see below) with the\n`name` parameter.\n\n```python\n@cmdmenu.cmdmenu_function(\"Print a hello world message\")\ndef hello(name=None):\n if name is None:\n print(\"Hello, World!\")\n else:\n print(\"Hello, {}\".format(name))\n```\n\n```\n$ python main.py hello\nHello, World!\n$ python main.py hello --name Ali\nHello, Ali!\n```\n\n\n#### More annotations\nYou can pass a dictionary as parameter annotation, the arguments are then passed to `argparse`.\nSee `add_command` docstring for more details.\n\n```python\n@cmdmenu.cmdmenu_function(\"Print sum of given numbers\")\ndef add_numbers(numbers: {\"help\": \"Numbers to sum up\",\n \"nargs\": \"+\", \"type\":int}):\n print(sum(numbers))\n```\n\n```\n$ python main.py add_numbers 1 2 3\n6\n```\n\n### Adding modules\n\nYou can all functions marked by the `cmdmenu_function` in a module (and its submodules)\nusing the `add_module` function.\n\nYou can save the functions from previous example in my_commands.py, and run the following\n\n```python\nimport argparse\nimport cmdmenu\n\nimport my_commands\n\nif __name__ == \"__main__\":\n parser = argparse.ArgumentParser(\"An example application\")\n subparsers = parser.add_subparsers()\n\n cmdmenu.add_module(subparsers, my_commands, toplevel=True)\n cmdmenu.parse_and_run_with(parser)\n```\n\nThis will create an identical program. The `toplevel=True` parameter indicates that the functions\nshould be added directly without creating an editional level.\n\nBy default `add_module` adds all the submodules of given module, which contain a variable called\n`CMDMENU_META`.\n\nTake the following structure as\nan example:\n```\nmain.py\nfakegit\n __init__.py -> defines add, rm\n remote.py -> defines add rename\n my_addon/\n\tfeatures -> defines foo, bar\n\titems -> defines baz\n```\n\nBy adding fakegit as a toplevel, you get the following commands, each with positional and keyword\narguments as defined by the functions:\n```\npython main.py add\npython main.py rm\npython main.py remote add\npython main.py remote rename\npython main.py my_addon features foo\npython main.py my_addon features bar\npython main.py items baz\n```\n\nSubmodule menu behaviour and documentation can be configured with a `CMDMENU_META` dictionary.\nSee `add_module` docstring for details.\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/arkocal/pycmdmenu.git", "keywords": "", "license": "", "maintainer": "", "maintainer_email": "", "name": "cmdmenu", "package_url": "https://pypi.org/project/cmdmenu/", "platform": "", "project_url": "https://pypi.org/project/cmdmenu/", "project_urls": { "Homepage": "https://github.com/arkocal/pycmdmenu.git" }, "release_url": "https://pypi.org/project/cmdmenu/0.1.1/", "requires_dist": null, "requires_python": "", "summary": "A library for creating hierarchical command line arg menus.", "version": "0.1.1" }, "last_serial": 4339876, "releases": { "0.1": [ { "comment_text": "", "digests": { "md5": "d6efbb45afa0c91308b6668e5a0d895c", "sha256": "be9c2b679542795a6b5a804e6953b37baabfd223c55dda339455831974f33d43" }, "downloads": -1, "filename": "cmdmenu-0.1-py3-none-any.whl", "has_sig": false, "md5_digest": "d6efbb45afa0c91308b6668e5a0d895c", "packagetype": "bdist_wheel", "python_version": "py3", "requires_python": null, "size": 4862, "upload_time": "2018-09-29T12:28:48", "url": "https://files.pythonhosted.org/packages/66/1f/8d4964a125d21f1fa5f4b8773d4ada25e6435bcc25c0be1e84a4ec97682b/cmdmenu-0.1-py3-none-any.whl" }, { "comment_text": "", "digests": { "md5": "7e1cf3c33bc418988eaac94d337b7898", "sha256": "673c99e2e9599d83ce12fe09b4ae737688c7b57c0b5888f66dbb3ee9c48cfed2" }, "downloads": -1, "filename": "cmdmenu-0.1.tar.gz", "has_sig": false, "md5_digest": "7e1cf3c33bc418988eaac94d337b7898", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 4871, "upload_time": "2018-09-29T12:28:49", "url": "https://files.pythonhosted.org/packages/52/e6/844baf4405b6cccffce92f1d60428b43ad2db3bbbc91bd62b50e85f6b766/cmdmenu-0.1.tar.gz" } ], "0.1.1": [ { "comment_text": "", "digests": { "md5": "b42db1a9d6dcfd6977a2c29159cdd398", "sha256": "d0a5aeaf4a5a734f4c2d6fe816e8fe021193d4dc67fa748f4aad277819852636" }, "downloads": -1, "filename": "cmdmenu-0.1.1-py3-none-any.whl", "has_sig": false, "md5_digest": "b42db1a9d6dcfd6977a2c29159cdd398", "packagetype": "bdist_wheel", "python_version": "py3", "requires_python": null, "size": 5118, "upload_time": "2018-10-04T11:21:11", "url": "https://files.pythonhosted.org/packages/c7/0c/5565f45a75183c6536526ca9e0a99bb994aa3369d6120fdd7b69ca705583/cmdmenu-0.1.1-py3-none-any.whl" }, { "comment_text": "", "digests": { "md5": "0282d92f9edf94d77ef180bf89313e2a", "sha256": "2447405c39cf9d633ea1fd2bab76235d286feeae5895ea6eea70042d4b84161d" }, "downloads": -1, "filename": "cmdmenu-0.1.1.tar.gz", "has_sig": false, "md5_digest": "0282d92f9edf94d77ef180bf89313e2a", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 5100, "upload_time": "2018-10-04T11:21:13", "url": "https://files.pythonhosted.org/packages/5c/3a/e9ac97e10bd45160e3bb2d1833c5cdd6c2d7d201b25c23ebb97f1bb56157/cmdmenu-0.1.1.tar.gz" } ] }, "urls": [ { "comment_text": "", "digests": { "md5": "b42db1a9d6dcfd6977a2c29159cdd398", "sha256": "d0a5aeaf4a5a734f4c2d6fe816e8fe021193d4dc67fa748f4aad277819852636" }, "downloads": -1, "filename": "cmdmenu-0.1.1-py3-none-any.whl", "has_sig": false, "md5_digest": "b42db1a9d6dcfd6977a2c29159cdd398", "packagetype": "bdist_wheel", "python_version": "py3", "requires_python": null, "size": 5118, "upload_time": "2018-10-04T11:21:11", "url": "https://files.pythonhosted.org/packages/c7/0c/5565f45a75183c6536526ca9e0a99bb994aa3369d6120fdd7b69ca705583/cmdmenu-0.1.1-py3-none-any.whl" }, { "comment_text": "", "digests": { "md5": "0282d92f9edf94d77ef180bf89313e2a", "sha256": "2447405c39cf9d633ea1fd2bab76235d286feeae5895ea6eea70042d4b84161d" }, "downloads": -1, "filename": "cmdmenu-0.1.1.tar.gz", "has_sig": false, "md5_digest": "0282d92f9edf94d77ef180bf89313e2a", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 5100, "upload_time": "2018-10-04T11:21:13", "url": "https://files.pythonhosted.org/packages/5c/3a/e9ac97e10bd45160e3bb2d1833c5cdd6c2d7d201b25c23ebb97f1bb56157/cmdmenu-0.1.1.tar.gz" } ] }