{ "info": { "author": "darkcode0x00", "author_email": "darkcode357@gmail.com", "bugtrack_url": null, "classifiers": [ "Development Status :: 5 - Production/Stable", "Environment :: Console", "Intended Audience :: Developers", "Intended Audience :: System Administrators", "License :: OSI Approved :: MIT License", "Operating System :: OS Independent", "Programming Language :: Python", "Programming Language :: Python :: 3", "Programming Language :: Python :: 3.5", "Programming Language :: Python :: 3.6", "Programming Language :: Python :: 3.7", "Programming Language :: Python :: 3.8", "Programming Language :: Python :: Implementation :: CPython", "Topic :: Software Development :: Libraries :: Python Modules" ], "description": "cmd2: a tool for building interactive command line apps\n=======================================================\n[![Latest Version](https://img.shields.io/pypi/v/cmd2.svg?style=flat-square&label=latest%20stable%20version)](https://pypi.python.org/pypi/cmd2/)\n[![Build status](https://img.shields.io/travis/python-cmd2/cmd2.svg?style=flat-square&label=unix%20build)](https://travis-ci.org/python-cmd2/cmd2)\n[![Appveyor build status](https://img.shields.io/appveyor/ci/FedericoCeratto/cmd2.svg?style=flat-square&label=windows%20build)](https://ci.appveyor.com/project/FedericoCeratto/cmd2)\n[![Azure Build status](https://python-cmd2.visualstudio.com/cmd2/_apis/build/status/python-cmd2.cmd2?branch=master)](https://python-cmd2.visualstudio.com/cmd2/_build/latest?definitionId=1&branch=master)\n[![codecov](https://codecov.io/gh/python-cmd2/cmd2/branch/master/graph/badge.svg)](https://codecov.io/gh/python-cmd2/cmd2)\n[![Documentation Status](https://readthedocs.org/projects/cmd2/badge/?version=latest)](http://cmd2.readthedocs.io/en/latest/?badge=latest)\n\"Chat\"\n\ncmd2 is a tool for building interactive command line applications in Python. Its goal is to make it\nquick and easy for developers to build feature-rich and user-friendly interactive command line\napplications. It provides a simple API which is an extension of Python's built-in\n[cmd](https://docs.python.org/3/library/cmd.html) module. cmd2 provides a wealth of features on top\nof cmd to make your life easier and eliminates much of the boilerplate code which would be necessary\nwhen using cmd.\n\nClick on image below to watch a short video demonstrating the capabilities of cmd2:\n[![Screenshot](cmd2.png)](https://youtu.be/DDU_JH6cFsA)\n\nMain Features\n-------------\n- Searchable command history (`history` command and `+r`) - optionally persistent\n- Text file scripting of your application with `run_script` (`@`) and `_relative_run_script` (`@@`)\n- Python scripting of your application with ``run_pyscript``\n- Run shell commands with ``!``\n- Pipe command output to shell commands with `|`\n- Redirect command output to file with `>`, `>>`\n- Bare `>`, `>>` with no filename send output to paste buffer (clipboard)\n- `py` enters interactive Python console (opt-in `ipy` for IPython console)\n- Option to display long output using a pager with ``cmd2.Cmd.ppaged()``\n- Multi-line commands\n- Special-character command shortcuts (beyond cmd's `?` and `!`)\n- Command aliasing similar to bash `alias` command\n- Macros, which are similar to aliases, but they can contain argument placeholders\n- Ability to run commands at startup from an initialization script\n- Settable environment parameters\n- Parsing commands with arguments using `argparse`, including support for sub-commands\n- Unicode character support\n- Good tab-completion of commands, sub-commands, file system paths, and shell commands\n- Automatic tab-completion of `argparse` flags when using one of the `cmd2` `argparse` decorators\n- Support for Python 3.5+ on Windows, macOS, and Linux\n- Trivial to provide built-in help for all commands\n- Built-in regression testing framework for your applications (transcript-based testing)\n- Transcripts for use with built-in regression can be automatically generated from `history -t` or `run_script -t`\n- Alerts that seamlessly print while user enters text at prompt\n- Colored and stylized output using `ansi.style()`\n\nPython 2.7 support is EOL\n-------------------------\nThe last version of cmd2 to support Python 2.7 is [0.8.9](https://pypi.org/project/cmd2/0.8.9/), released on August 21, 2018.\n\nSupporting Python 2 was an increasing burden on our limited resources. Switching to support only Python 3 is allowing\nus to clean up the codebase, remove some cruft, and focus on developing new features.\n\nInstallation\n------------\nOn all operating systems, the latest stable version of `cmd2` can be installed using pip:\n\n```bash\npip install -U cmd2\n```\n\ncmd2 works with Python 3.5+ on Windows, macOS, and Linux. It is pure Python code with few 3rd-party dependencies.\n\nFor information on other installation options, see\n[Installation Instructions](https://cmd2.readthedocs.io/en/latest/install.html) in the cmd2\ndocumentation.\n\n\nDocumentation\n-------------\nThe latest documentation for cmd2 can be read online here: https://cmd2.readthedocs.io/en/latest/\n\nIt is available in HTML, PDF, and ePub formats.\n\n\nFeature Overview\n----------------\nInstructions for implementing each feature follow.\n\n- Extension of the `cmd` module. So capabilities provided by `cmd` still exist\n - Your applicaiton inherits from `cmd2.Cmd`, let's say you call this class `MyApp`\n ```Python\n import cmd2\n class MyApp(cmd2.Cmd):\n pass\n ```\n - Define a command named **foo** by creating a method named **do_foo**\n ```Python\n class MyApp(cmd2.Cmd):\n def do_foo(self, args):\n \"\"\"This docstring is the built-in help for the foo command.\"\"\"\n self.poutput(cmd2.style('foo bar baz', fg='red'))\n ```\n - By default the docstring for your **do_foo** method is the help for the **foo** command\n - NOTE: This doesn't apply if you use one of the `argparse` decorators mentioned below\n - Can provide more custom help by creating a **help_foo** method (except when using `argparse` decorators)\n - Can provide custom tab-completion for the **foo** command by creating a **complete_foo** method\n - Easy to upgrade an existing `cmd` app to `cmd2`\n - Run your `cmd2` app using the built-in REPL by executing the **cmdloop** method\n\n- Searchable command history\n - Readline history using `+r`, arrow keys, and other [Readline Shortcut keys](http://readline.kablamo.org/emacs.html)\n - Readline history can be persistent between application runs via optional argument to `cmd2.Cmd` initializer\n - `cmd2` `history` command provides flexible and powerful search\n - By design, this history does NOT persist between application runs\n - If you wish to exclude some of your custom commands from the history, append their names to the list at `Cmd.exclude_from_history`.\n - Do `help history` in any `cmd2` application for more information\n\n- Simple scripting using ASCII text files with one command + arguments per line\n - See the [Script files](https://cmd2.readthedocs.io/en/latest/freefeatures.html#script-files) section of the `cmd2` docs for more info\n - See [script.txt](https://github.com/python-cmd2/cmd2/blob/master/examples/scripts/script.txt) for a trivial example script that can be\n used in any `cmd2` application with the `run_script` command (or `@` shortcut)\n\n- Powerful and flexible built-in Python scripting of your application using the `run_pyscript` command\n - Run arbitrary Python scripts within your `cmd2` application with the ability to also call custom `cmd2` commands\n - No separate API for your end users to learn\n - Syntax for calling `cmd2` commands in a `run_pyscript` is essentially identical to what they would enter on the command line\n - See the [Python](https://cmd2.readthedocs.io/en/latest/freefeatures.html#python) section of the `cmd2` docs for more info\n - Also see the [python_scripting.py](https://github.com/python-cmd2/cmd2/blob/master/examples/python_scripting.py) \n example in conjunction with the [conditional.py](https://github.com/python-cmd2/cmd2/blob/master/examples/scripts/conditional.py) script\n\n- Parsing commands with `argparse`\n - Two decorators provide built-in capability for using `argparse.ArgumentParser` to parse command arguments\n - `cmd2.with_argparser` - all arguments are parsed by the `ArgumentParser`\n - `cmd2.with_argparser_and_unknown_args` - any arguments not parsed by the `ArgumentParser` get passed as a list\n\n ```Python\n import argparse\n from cmd2 import with_argparser\n\n argparser = argparse.ArgumentParser()\n argparser.add_argument('-p', '--piglatin', action='store_true', help='atinLay')\n argparser.add_argument('-s', '--shout', action='store_true', help='N00B EMULATION MODE')\n argparser.add_argument('words', nargs='+', help='words to say')\n\n @with_argparser(argparser)\n def do_speak(self, args):\n \"\"\"Repeats what you tell me to.\"\"\"\n words = []\n for word in args.words:\n if args.piglatin:\n word = '%s%say' % (word[1:], word[0])\n if args.shout:\n word = word.upper()\n words.append(word)\n self.stdout.write('{}\\n'.format(' '.join(words)))\n ```\n\n See https://cmd2.readthedocs.io/en/latest/argument_processing.html for more details\n \n NOTE: `cmd2` also provides the `cmd2.ArgParser` customization of `argparse.ArgumentParser` for prettier formatting\n of help and error messages.\n\n- `cmd2` applications function like a full-featured shell in many ways (and are cross-platform)\n - Run arbitrary shell commands by preceding them with `!` or `shell`\n - Redirect the output of any command to a file with `>` for overwrite or `>>` for append\n - If no file name provided after the `>`/`>>`, then output goes to the clipboard/pastebuffer\n - Pipe the output of any command to an arbitrary shell command with `|`\n - Create your own custom command aliases using the `alias` command\n - Create your own custom macros using the `macro` command (similar to aliases, but allow arguments)\n - Settable environment parameters that users can change during execution supported via `set` command\n - Option to display long output using a pager with ``cmd2.Cmd.ppaged()``\n - Optionally specify a startup script that end users can use to customize their environment\n\n- Top-notch tab-completion capabilities which are easy to use but very powerful\n - For a command **foo** implement a **complete_foo** method to provide custom tab completion for that command\n - But the helper methods within `cmd2` discussed below mean you would rarely have to implement this from scratch\n - Commands which use one of the `argparse` decorators have automatic tab-completion of `argparse` flags\n - And also provide help hints for values associated with these flags\n - Experiment with the [argprint.py](https://github.com/python-cmd2/cmd2/blob/master/examples/arg_print.py) example\n using the **oprint** and **pprint** commands to get a feel for how this works\n - `path_complete` helper method provides flexible tab-completion of file system paths\n - See the [paged_output.py](https://github.com/python-cmd2/cmd2/blob/master/examples/paged_output.py) example for a simple use case\n - See the [python_scripting.py](https://github.com/python-cmd2/cmd2/blob/master/examples/python_scripting.py) example for a more full-featured use case\n - `flag_based_complete` helper method for tab completion based on a particular flag preceding the token being completed\n - See the [tab_completion.py](https://github.com/python-cmd2/cmd2/blob/master/examples/tab_completion.py) example for a demonstration of how to use this feature\n - `index_based_complete` helper method for tab completion based on a fixed position in the input string\n - See the [tab_completion.py](https://github.com/python-cmd2/cmd2/blob/master/examples/tab_completion.py) example for a demonstration of how to use this feature\n - `basic_complete` helper method for tab completion against a list\n - `delimiter_complete` helper method for tab completion against a list but each match is split on a delimiter \n - See the [tab_autocompletion.py](https://github.com/python-cmd2/cmd2/blob/master/examples/tab_autocompletion.py) example for a demonstration of how to use this feature\n - `cmd2` in combination with `argparse` also provide several advanced capabilities for automatic tab-completion\n - See the [tab_autocompletion.py](https://github.com/python-cmd2/cmd2/blob/master/examples/tab_autocompletion.py) example for more info\n\n- Multi-line commands\n\n Any command accepts multi-line input when its name is listed the `multiline_commands` optional argument to \n `cmd2.Cmd.__init`. The program will keep expecting input until a line ends with any of the characters listed in the \n `terminators` optional argument to `cmd2.Cmd.__init__()` . The default terminators are `;` and `/n` (empty newline).\n\n- Special-character shortcut commands (beyond cmd's \"@\" and \"!\")\n\n To create a single-character shortcut for a command, update `Cmd.shortcuts`.\n\n- Asynchronous alerts based on events happening in background threads\n - `cmd2` provides the following helper methods for providing information to users asynchronously even though the `cmd2`\n REPL is a line-oriented command interpreter:\n - `async_alert` - display an important message to the user while they are at the prompt in between commands\n - To the user it appears as if an alert message is printed above the prompt\n - `async_update_prompt` - update the prompt while the user is still typing at it\n - This is good for alerting the user to system changes dynamically in between commands\n - `set_window_title` - set the terminal window title\n - This changes the window title of the terminal that the user is running the `cmd2` app within\n\n\nTutorials\n---------\n\nA few tutorials on using cmd2 exist:\n\n* Florida PyCon 2017 talk: [slides](https://docs.google.com/presentation/d/1LRmpfBt3V-pYQfgQHdczf16F3hcXmhK83tl77R6IJtE), [video](https://www.youtube.com/watch?v=6m0RdpITaeY)\n* PyCon 2010 talk by Catherine Devlin, the original author: [video](http://pyvideo.org/pycon-us-2010/pycon-2010--easy-command-line-applications-with-c.html)\n* A nice brief step-by-step tutorial: [blog](https://kushaldas.in/posts/developing-command-line-interpreters-using-python-cmd2.html)\n\n\nExample Application\n-------------------\n\nExample cmd2 application (**examples/example.py**):\n\n```python\n#!/usr/bin/env python\n# coding=utf-8\nthgcmd\nimport argparse\nimport random\nimport sys\nimport cmd2\n\nclass CmdLineApp(cmd2.Cmd):\n thgcmd\n\n thgcmd\n # default_to_shell = True\n MUMBLES = ['like', '...', 'um', 'er', 'hmmm', 'ahh']\n MUMBLE_FIRST = ['so', 'like', 'well']\n MUMBLE_LAST = ['right?']\n\n def __init__(self):\n self.maxrepeats = 3\n shortcuts = dict(cmd2.DEFAULT_SHORTCUTS)\n shortcuts.update({'&': 'speak'})\n\n # Set use_ipython to True to enable the \"ipy\" command which embeds and interactive IPython shell\n super().__init__(use_ipython=False, multiline_commands=['orate'], shortcuts=shortcuts)\n \n # Make maxrepeats settable at runtime\n self.settable['maxrepeats'] = 'max repetitions for speak command'\n\n speak_parser = argparse.ArgumentParser()\n speak_parser.add_argument('-p', '--piglatin', action='store_true', help='atinLay')\n speak_parser.add_argument('-s', '--shout', action='store_true', help='N00B EMULATION MODE')\n speak_parser.add_argument('-r', '--repeat', type=int, help='output [n] times')\n speak_parser.add_argument('words', nargs='+', help='words to say')\n\n @cmd2.with_argparser(speak_parser)\n def do_speak(self, args):\n \"\"\"Repeats what you tell me to.\"\"\"\n words = []\n for word in args.words:\n if args.piglatin:\n word = '%s%say' % (word[1:], word[0])\n if args.shout:\n word = word.upper()\n words.append(word)\n repetitions = args.repeat or 1\n for i in range(min(repetitions, self.maxrepeats)):\n # .poutput handles newlines, and accommodates output redirection too\n self.poutput(' '.join(words))\n\n do_say = do_speak # now \"say\" is a synonym for \"speak\"\n do_orate = do_speak # another synonym, but this one takes multi-line input\n\n mumble_parser = argparse.ArgumentParser()\n mumble_parser.add_argument('-r', '--repeat', type=int, help='how many times to repeat')\n mumble_parser.add_argument('words', nargs='+', help='words to say')\n\n @cmd2.with_argparser(mumble_parser)\n def do_mumble(self, args):\n \"\"\"Mumbles what you tell me to.\"\"\"\n repetitions = args.repeat or 1\n for i in range(min(repetitions, self.maxrepeats)):\n output = []\n if (random.random() < .33):\n output.append(random.choice(self.MUMBLE_FIRST))\n for word in args.words:\n if (random.random() < .40):\n output.append(random.choice(self.MUMBLES))\n output.append(word)\n if (random.random() < .25):\n output.append(random.choice(self.MUMBLE_LAST))\n self.poutput(' '.join(output))\n\nif __name__ == '__main__':\n app = CmdLineApp()\n sys.exit(app.cmdloop())\n```\n\nThe following is a sample session running example.py.\nThanks to Cmd2's built-in transcript testing capability, it also serves as a test\nsuite for example.py when saved as *transcript_regex.txt*.\nRunning\n\n```bash\npython example.py -t transcript_regex.txt\n```\nwill run all the commands in the transcript against `example.py`, verifying that the output produced\nmatches the transcript.\n\nexample/transcript_regex.txt:\n\n```text\n# Run this transcript with \"python example.py -t transcript_regex.txt\"\n# The regex for editor will match whatever program you use.\n# regexes on prompts just make the trailing space obvious\n(Cmd) set\nallow_ansi: Terminal\ncontinuation_prompt: >/ /\ndebug: False\necho: False\neditor: /.*?/\nfeedback_to_output: False\nlocals_in_py: True\nmaxrepeats: 3\nprompt: (Cmd)/ /\nquiet: False\ntiming: False\n```\n\nRegular expressions can be used anywhere within a transcript file simply by enclosing them within forward slashes, `/`.\n\n\nFound a bug?\n------------\n\nIf you think you've found a bug, please first read through the open [Issues](https://github.com/python-cmd2/cmd2/issues). If you're confident it's a new bug, go ahead and create a new GitHub issue. Be sure to include as much information as possible so we can reproduce the bug. At a minimum, please state the following:\n\n* ``cmd2`` version\n* Python version\n* OS name and version\n* What you did to cause the bug to occur\n* Include any traceback or error message associated with the bug\n\n\nOpen source projects using cmd2\n-------------------------------\n\nHere are a few examples of open-source projects which use `cmd2`:\n\n* [CephFS Shell](http://docs.ceph.com/docs/master/cephfs/cephfs-shell/)\n * [Ceph](https://ceph.com/) is a distributed object, block, and file storage platform\n* [JSShell](https://github.com/Den1al/JSShell)\n * An interactive multi-user web JavaScript shell\n* [psiTurk](https://psiturk.org)\n * An open platform for science on Amazon Mechanical Turk\n* [Jok3r](http://www.jok3r-framework.com)\n * Network & Web Pentest Automation Framework\n* [Poseidon](https://github.com/CyberReboot/poseidon)\n * Leverages software-defined networks (SDNs) to acquire and then feed network traffic to a number of machine learning techniques\n* [Unipacker](https://github.com/unipacker/unipacker)\n * Automatic and platform-independent unpacker for Windows binaries based on emulation\n* [FLASHMINGO](https://github.com/fireeye/flashmingo)\n * Automatic analysis of SWF files based on some heuristics. Extensible via plugins.\n* [tomcatmanager](https://github.com/tomcatmanager/tomcatmanager)\n * A command line tool and python library for managing a tomcat server\n* [mptcpanalyzer](https://github.com/teto/mptcpanalyzer)\n * Tool to help analyze mptcp pcaps\n* [clanvas](https://github.com/marklalor/clanvas)\n * Command-line client for Canvas by Instructure", "description_content_type": "text/markdown", "docs_url": null, "download_url": "https://github.com/darkcode357/thgcmd/archive/1.1.tar.gz", "downloads": { "last_day": -1, "last_month": -1, "last_week": -1 }, "home_page": "https://github.com/darkcode357/thgcmd", "keywords": "command prompt console cmd", "license": "MIT", "maintainer": "", "maintainer_email": "", "name": "thgcmd", "package_url": "https://pypi.org/project/thgcmd/", "platform": "any", "project_url": "https://pypi.org/project/thgcmd/", "project_urls": { "Download": "https://github.com/darkcode357/thgcmd/archive/1.1.tar.gz", "Homepage": "https://github.com/darkcode357/thgcmd" }, "release_url": "https://pypi.org/project/thgcmd/1.1/", "requires_dist": null, "requires_python": ">=3.5", "summary": "thgcmd - quickly build feature-rich and user-friendly interactive command line applications in Python", "version": "1.1" }, "last_serial": 5547525, "releases": { "0.0.0": [ { "comment_text": "", "digests": { "md5": "ec4346bad458d3a3b7b9dd42624b7f5d", "sha256": "84f4c12dc2448949ec9e844b4fab01cef68f46bcd08197760e11f34232e1b894" }, "downloads": -1, "filename": "thgcmd-0.0.0.tar.gz", "has_sig": false, "md5_digest": "ec4346bad458d3a3b7b9dd42624b7f5d", "packagetype": "sdist", "python_version": "source", "requires_python": ">=3.5", "size": 627112, "upload_time": "2019-07-17T15:13:10", "url": "https://files.pythonhosted.org/packages/42/7c/e74e6911f6d18a3edac180975db5728df83f78d2bfd4e6147d50f4f800ed/thgcmd-0.0.0.tar.gz" } ], "1.1": [ { "comment_text": "", "digests": { "md5": "6b1aa72ae459a19849ff8aefd6f223b9", "sha256": "cf22e5ce72dc99ea3fa87b2dc95358e6b2365ccf87b6ec5c9596b67de9d94e2c" }, "downloads": -1, "filename": "thgcmd-1.1.tar.gz", "has_sig": false, "md5_digest": "6b1aa72ae459a19849ff8aefd6f223b9", "packagetype": "sdist", "python_version": "source", "requires_python": ">=3.5", "size": 621803, "upload_time": "2019-07-17T20:01:38", "url": "https://files.pythonhosted.org/packages/33/a5/48e3b030cc027279a0023d9581b1dfbb3a711b838c70ceced80287c7472d/thgcmd-1.1.tar.gz" } ] }, "urls": [ { "comment_text": "", "digests": { "md5": "6b1aa72ae459a19849ff8aefd6f223b9", "sha256": "cf22e5ce72dc99ea3fa87b2dc95358e6b2365ccf87b6ec5c9596b67de9d94e2c" }, "downloads": -1, "filename": "thgcmd-1.1.tar.gz", "has_sig": false, "md5_digest": "6b1aa72ae459a19849ff8aefd6f223b9", "packagetype": "sdist", "python_version": "source", "requires_python": ">=3.5", "size": 621803, "upload_time": "2019-07-17T20:01:38", "url": "https://files.pythonhosted.org/packages/33/a5/48e3b030cc027279a0023d9581b1dfbb3a711b838c70ceced80287c7472d/thgcmd-1.1.tar.gz" } ] }