{ "info": { "author": "plausibility", "author_email": "chris@gibsonsec.org", "bugtrack_url": null, "classifiers": [ "Development Status :: 4 - Beta", "Intended Audience :: Developers", "License :: OSI Approved :: MIT License", "Operating System :: OS Independent", "Programming Language :: Python :: 2", "Programming Language :: Python :: 3" ], "description": "rcmd.py\n=======\n\nSort of like Python's built in \"cmd\" module, but with regex handlers.\n\n## Basic usage\n\n```python\n# -*- coding: utf-8 -*-\nfrom rcmd import Rcmd\n\nr = Rcmd(__name__)\n\n# Note: this will match \"foo!\", and \"foober\" - use \"foo$\" if you want\n# to avoid this sort of stuff. Regexes are like that, yeah?\n@r.command(r\"foo\")\ndef foo(args):\n print(\"Foo!\")\n\n@r.command(r\"\\d+!\", with_cmd=True)\ndef fact(args, cmd):\n print(cmd[:-1] + \"?\")\n\nr.loop()\n```\n\n## Registering various handlers\n\nRcmd has a few handlers you can override (through decorators, of course!).\n\n```python\n@r.emptyline\ndef emptyline():\n # Called when the user doesn't type anything.\n pass\n\n@r.default\ndef default(line):\n # Called when nothing matches the user's line.\n pass\n\n@r.bang\ndef bang(args):\n # Called when the user types \"! [stuff]\".\n # Convenience since this is a handy addition.\n pass\n\n@r.question\ndef question(args):\n # Called when the user types \"? [stuff]\"\n # Convenience since this is a handy addition.\n pass\n\n@r.precmd\ndef precmd(line):\n # Allows you to modify a line before it passes through\n # the parser and matchers.\n return line\n\n@r.postcmd\ndef postcmd(stop, results, line):\n # `stop` -> truthy values mean we'll stop next loop.\n # `results` -> list of results any matching commands returned\n # `line` -> the line the user entered\n return stop, results\n\n@r.preloop\ndef preloop():\n # Called before the initial command loop starts.\n pass\n\n@r.postloop\ndef postloop():\n # Called after the command loop finishes.\n pass\n```\n\n## Example `help` command\n\nThis isn't built in because to each his own - you might want different things to me, so here's a basic structure you can work with. \nThis will let people do `help` and `help thing` (with optional `?` alias to help), and prints the `__doc__` of each command handler that _thing_ matches.\n\n```python\n@r.question\n@r.command(r\"help$\")\ndef help(args):\n def tidy_regex(regex):\n return regex.lstrip(\"^\").rstrip(\"$\")\n\n def create_help(regex, functions, matching=None):\n if matching is not None and not regex.match(matching):\n return None\n out = [\">>> {0}\".format(tidy_regex(regex.pattern))]\n for i, function in enumerate(functions, 1):\n if function.__doc__:\n out.append(textwrap.dedent(function.__doc__))\n else:\n out.append(\"{0}. No help provided. :( ({1})\".format(i, function.__name__))\n out.append(\"\")\n return \"\\n\".join(out)\n\n # No arguments provided, just list things.\n if not args or len(args) != 1:\n for regex, functions in r.handlers.iteritems():\n print(create_help(regex, functions))\n return\n\n # Do a search for matching handlers.\n cmd, matched = args[0], True\n print('\"{0}\" would run:\\n'.format(cmd))\n for regex, functions in r.handlers.iteritems():\n t = create_help(regex, functions, matching=cmd)\n if t is None:\n continue\n matched = True\n print(t)\n\n if not matched:\n print(\"nothing :(\\n\")\n```", "description_content_type": null, "docs_url": null, "download_url": "UNKNOWN", "downloads": { "last_day": -1, "last_month": -1, "last_week": -1 }, "home_page": "https://github.com/plausibility/rcmd.py", "keywords": "cmd command line loop", "license": "MIT", "maintainer": null, "maintainer_email": null, "name": "rcmd", "package_url": "https://pypi.org/project/rcmd/", "platform": "UNKNOWN", "project_url": "https://pypi.org/project/rcmd/", "project_urls": { "Download": "UNKNOWN", "Homepage": "https://github.com/plausibility/rcmd.py" }, "release_url": "https://pypi.org/project/rcmd/1.0.3/", "requires_dist": null, "requires_python": null, "summary": "Like Python's cmd module, but uses regex based handlers instead!", "version": "1.0.3" }, "last_serial": 951763, "releases": { "1.0.1": [ { "comment_text": "", "digests": { "md5": "34b9fad3ee321919833a0947b1ed0561", "sha256": "a7c94eef2394e76e3fd1f59450a417d8c283e4a67cf7b4091c0027cab3d802ac" }, "downloads": -1, "filename": "rcmd-1.0.1.tar.gz", "has_sig": false, "md5_digest": "34b9fad3ee321919833a0947b1ed0561", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 5099, "upload_time": "2013-11-27T12:01:01", "url": "https://files.pythonhosted.org/packages/26/ac/fce3f510ba0273a0fadbee569d986916b69a676c1d8be7220a90867e641d/rcmd-1.0.1.tar.gz" } ], "1.0.2": [ { "comment_text": "", "digests": { "md5": "90a1a12d99d4fb6ae84796f1d2f8e630", "sha256": "612fa6102d75d7548737e0228c71f640b6d71b2194b530541e236b9725f9d2a3" }, "downloads": -1, "filename": "rcmd-1.0.2.tar.gz", "has_sig": false, "md5_digest": "90a1a12d99d4fb6ae84796f1d2f8e630", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 5185, "upload_time": "2013-12-22T13:47:02", "url": "https://files.pythonhosted.org/packages/b8/35/62e7d1015b6f903d98df7e2673fb3f2fe5bc3cc7a76e3a971984bb139cb1/rcmd-1.0.2.tar.gz" } ], "1.0.3": [ { "comment_text": "", "digests": { "md5": "b3ebb88d0aa67cff767aa6e4defb01e4", "sha256": "8790990947e3229e06b17592d7f061517dc3f9488775748a0dd2c44cc2207c2b" }, "downloads": -1, "filename": "rcmd-1.0.3.tar.gz", "has_sig": false, "md5_digest": "b3ebb88d0aa67cff767aa6e4defb01e4", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 5589, "upload_time": "2013-12-22T13:48:55", "url": "https://files.pythonhosted.org/packages/a3/44/20ec844187ef788e68dfc6f6707bd282bae571fb0264b26e81c35f76e938/rcmd-1.0.3.tar.gz" } ] }, "urls": [ { "comment_text": "", "digests": { "md5": "b3ebb88d0aa67cff767aa6e4defb01e4", "sha256": "8790990947e3229e06b17592d7f061517dc3f9488775748a0dd2c44cc2207c2b" }, "downloads": -1, "filename": "rcmd-1.0.3.tar.gz", "has_sig": false, "md5_digest": "b3ebb88d0aa67cff767aa6e4defb01e4", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 5589, "upload_time": "2013-12-22T13:48:55", "url": "https://files.pythonhosted.org/packages/a3/44/20ec844187ef788e68dfc6f6707bd282bae571fb0264b26e81c35f76e938/rcmd-1.0.3.tar.gz" } ] }