cmd2


Namecmd2 JSON
Version 2.5.6 PyPI version JSON
download
home_pageNone
Summarycmd2 - quickly build feature-rich and user-friendly interactive command line applications in Python
upload_time2024-11-14 14:01:00
maintainerNone
docs_urlNone
authorcmd2 Contributors
requires_python>=3.8
licenseThe MIT License (MIT) Copyright (c) 2008-2024 Catherine Devlin and others Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
keywords cli cmd command interactive prompt python
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            <h1 align="center">cmd2 : immersive interactive command line applications</h1>

[![Latest Version](https://img.shields.io/pypi/v/cmd2.svg?style=flat-square&label=latest%20stable%20version)](https://pypi.python.org/pypi/cmd2/)
[![GitHub Actions](https://github.com/python-cmd2/cmd2/workflows/CI/badge.svg)](https://github.com/python-cmd2/cmd2/actions?query=workflow%3ACI)
[![codecov](https://codecov.io/gh/python-cmd2/cmd2/branch/master/graph/badge.svg)](https://codecov.io/gh/python-cmd2/cmd2)
[![Documentation Status](https://readthedocs.org/projects/cmd2/badge/?version=latest)](http://cmd2.readthedocs.io/en/latest/?badge=latest)
<a href="https://discord.gg/RpVG6tk"><img src="https://img.shields.io/badge/chat-on%20discord-7289da.svg" alt="Chat"></a>


<p align="center">
  <a href="#the-developers-toolbox">Developer's Toolbox</a> •
  <a href="#philosophy">Philosophy</a> •
  <a href="#installation">Installation</a> •
  <a href="#documentation">Documentation</a> •
  <a href="#tutorials">Tutorials</a> •
  <a href="#hello-world">Hello World</a> •
  <a href="#projects-using-cmd2">Projects using cmd2</a> •
</p>

[![Screenshot](https://raw.githubusercontent.com/python-cmd2/cmd2/master/cmd2.png)](https://youtu.be/DDU_JH6cFsA)

cmd2 is a tool for building interactive command line applications in Python. Its goal is to make it
quick and easy for developers to build feature-rich and user-friendly interactive command line
applications.  It provides a simple API which is an extension of Python's built-in
[cmd](https://docs.python.org/3/library/cmd.html) module.  cmd2 provides a wealth of features on top
of cmd to make your life easier and eliminates much of the boilerplate code which would be necessary
when using cmd.

The developers toolbox
----------------------

![system schema](https://raw.githubusercontent.com/python-cmd2/cmd2/master/.github/images/graph.drawio.png)


When creating solutions developers have no shortage of tools to create rich and smart user interfaces.
System administrators have long been duct taping together brittle workflows based on a menagerie of simple command line tools created by strangers on github and the guy down the hall.
Unfortunately, when CLIs become significantly complex the ease of command discoverability tends to fade quickly.
On the other hand, Web and traditional desktop GUIs are first in class when it comes to easily discovering functionality.
The price we pay for beautifully colored displays is complexity required to aggregate disperate applications into larger systems.
`cmd2` fills the niche between high [ease of command discovery](https://clig.dev/#ease-of-discovery) applications and smart workflow automation systems.

The `cmd2` framework provides a great mixture of both worlds. Application designers can easily create complex applications and rely on the cmd2 library to offer effortless user facing help and extensive tab completion.
When users become comfortable with functionality, cmd2 turns into a feature rich library enabling a smooth transition to full automation. If designed with enough forethought, a well implemented cmd2 application can serve as a boutique workflow tool. `cmd2` pulls off this flexibility based on two pillars of philosophy:

* Tab Completion
* Automation Transition

Philosophy
-------------

<a href="https://imgflip.com/i/63h03x"><img src="https://i.imgflip.com/63h03x.jpg" title="made at imgflip.com" width="70%" height="%70"/></a>


Deep extensive tab completion and help text generation based on the argparse library create the first pillar of 'ease of command discovery'. The following is a list of features in this category.

- Great tab completion of commands, subcommands, file system paths, and shell commands.
- Custom tab completion for user designed commands via simple function overloading.
- Tab completion from `persistent_history_file` sources added with very little friction.
- Automatic tab completion of `argparse` flags and optional arguments.
- Path completion easily enabled.
- When all else fails, custom tab completion based on `choices_provider` can fill any gaps.

<a href="https://imgflip.com/i/66t0y0"><img src="https://i.imgflip.com/66t0y0.jpg" title="made at imgflip.com" width="70%" height="70%"/></a>

cmd2 creates the second pillar of 'ease of transition to automation' through alias/macro creation, command line argument parsing and execution of cmd2 scripting.

- Flexible alias and macro creation for quick abstraction of commands.
- Text file scripting of your application with `run_script` (`@`) and `_relative_run_script` (`@@`)
- Powerful and flexible built-in Python scripting of your application using the `run_pyscript` command
- Transcripts for use with built-in regression can be automatically generated from `history -t` or `run_script -t`


Installation
------------
On all operating systems, the latest stable version of `cmd2` can be installed using pip:

```bash
pip install -U cmd2
```

cmd2 works with Python 3.8+ on Windows, macOS, and Linux. It is pure Python code with few 3rd-party dependencies.

For information on other installation options, see
[Installation Instructions](https://cmd2.readthedocs.io/en/latest/overview/installation.html) in the cmd2
documentation.


Documentation
-------------
The latest documentation for cmd2 can be read online here: https://cmd2.readthedocs.io/en/latest/

It is available in HTML, PDF, and ePub formats.


The best way to learn the cmd2 api is to delve into the example applications located in source under examples.

Tutorials
---------

* PyOhio 2019 presentation:
    * [video](https://www.youtube.com/watch?v=pebeWrTqIIw)
    * [slides](https://github.com/python-cmd2/talks/blob/master/PyOhio_2019/cmd2-PyOhio_2019.pdf)
    * [example code](https://github.com/python-cmd2/talks/tree/master/PyOhio_2019/examples)
* [Cookiecutter](https://github.com/cookiecutter/cookiecutter) Templates from community
    * Basic cookiecutter template for cmd2 application : https://github.com/jayrod/cookiecutter-python-cmd2
    * Advanced cookiecutter template with external plugin support : https://github.com/jayrod/cookiecutter-python-cmd2-ext-plug
* [Example Applications](https://github.com/jayrod/cmd2-example-apps)


Hello World
-----------

```python
#!/usr/bin/env python
"""A simple cmd2 application."""
import cmd2


class FirstApp(cmd2.Cmd):
    """A simple cmd2 application."""

  def do_hello_world(self, _: cmd2.Statement):
    self.poutput('Hello World')

if __name__ == '__main__':
    import sys
    c = FirstApp()
    sys.exit(c.cmdloop())

```


Found a bug?
------------

If 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:

* ``cmd2`` version
* Python version
* OS name and version
* What you did to cause the bug to occur
* Include any traceback or error message associated with the bug


Projects using cmd2
-------------------------------

| Application Name                                                | Description                                                                                                                     |   |
|-----------------------------------------------------------------|---------------------------------------------------------------------------------------------------------------------------------|---|
| [Jok3r](http://www.jok3r-framework.com)                         | Network & Web Pentest Automation Framework                                                                                      |   |
| [CephFS Shell](https://github.com/ceph/ceph)                    | [Ceph](https://ceph.com/) is a distributed object, block, and file storage platform                                             |   |
| [psiTurk](https://psiturk.org)                                  | An open platform for science on Amazon Mechanical Turk                                                                          |   |
| [Poseidon](https://github.com/CyberReboot/poseidon)             | Leverages software-defined networks (SDNs) to acquire and then feed network traffic to a number of machine learning techniques. |   |
| [Unipacker](https://github.com/unipacker/unipacker)             | Automatic and platform-independent unpacker for Windows binaries based on emulation                                             |   |
| [tomcatmanager](https://github.com/tomcatmanager/tomcatmanager) | A command line tool and python library for managing a tomcat server                                                             |   |
| [Expliot](https://gitlab.com/expliot_framework/expliot)         | Internet of Things (IoT) exploitation framework                                                                                 |   |
| [mptcpanalyzer]()                                               | Tool to help analyze mptcp pcaps                                                                                                |   |
| [clanvas](https://github.com/marklalor/clanvas)                 | Command-line client for Canvas by Instructure                                                                                   |   |


Possibly defunct but still good examples

* [JSShell](https://github.com/Den1al/JSShell)
* [FLASHMINGO](https://github.com/fireeye/flashmingo)

            

Raw data

            {
    "_id": null,
    "home_page": null,
    "name": "cmd2",
    "maintainer": null,
    "docs_url": null,
    "requires_python": ">=3.8",
    "maintainer_email": null,
    "keywords": "CLI, cmd, command, interactive, prompt, Python",
    "author": "cmd2 Contributors",
    "author_email": null,
    "download_url": "https://files.pythonhosted.org/packages/d5/88/703b5c75610ec4ac2c5bcd390ab4b478e689faf1f02ea91fce3f57d449b8/cmd2-2.5.6.tar.gz",
    "platform": null,
    "description": "<h1 align=\"center\">cmd2 : immersive interactive command line applications</h1>\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[![GitHub Actions](https://github.com/python-cmd2/cmd2/workflows/CI/badge.svg)](https://github.com/python-cmd2/cmd2/actions?query=workflow%3ACI)\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<a href=\"https://discord.gg/RpVG6tk\"><img src=\"https://img.shields.io/badge/chat-on%20discord-7289da.svg\" alt=\"Chat\"></a>\n\n\n<p align=\"center\">\n  <a href=\"#the-developers-toolbox\">Developer's Toolbox</a> \u2022\n  <a href=\"#philosophy\">Philosophy</a> \u2022\n  <a href=\"#installation\">Installation</a> \u2022\n  <a href=\"#documentation\">Documentation</a> \u2022\n  <a href=\"#tutorials\">Tutorials</a> \u2022\n  <a href=\"#hello-world\">Hello World</a> \u2022\n  <a href=\"#projects-using-cmd2\">Projects using cmd2</a> \u2022\n</p>\n\n[![Screenshot](https://raw.githubusercontent.com/python-cmd2/cmd2/master/cmd2.png)](https://youtu.be/DDU_JH6cFsA)\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\nThe developers toolbox\n----------------------\n\n![system schema](https://raw.githubusercontent.com/python-cmd2/cmd2/master/.github/images/graph.drawio.png)\n\n\nWhen creating solutions developers have no shortage of tools to create rich and smart user interfaces.\nSystem administrators have long been duct taping together brittle workflows based on a menagerie of simple command line tools created by strangers on github and the guy down the hall.\nUnfortunately, when CLIs become significantly complex the ease of command discoverability tends to fade quickly.\nOn the other hand, Web and traditional desktop GUIs are first in class when it comes to easily discovering functionality.\nThe price we pay for beautifully colored displays is complexity required to aggregate disperate applications into larger systems.\n`cmd2` fills the niche between high [ease of command discovery](https://clig.dev/#ease-of-discovery) applications and smart workflow automation systems.\n\nThe `cmd2` framework provides a great mixture of both worlds. Application designers can easily create complex applications and rely on the cmd2 library to offer effortless user facing help and extensive tab completion.\nWhen users become comfortable with functionality, cmd2 turns into a feature rich library enabling a smooth transition to full automation. If designed with enough forethought, a well implemented cmd2 application can serve as a boutique workflow tool. `cmd2` pulls off this flexibility based on two pillars of philosophy:\n\n* Tab Completion\n* Automation Transition\n\nPhilosophy\n-------------\n\n<a href=\"https://imgflip.com/i/63h03x\"><img src=\"https://i.imgflip.com/63h03x.jpg\" title=\"made at imgflip.com\" width=\"70%\" height=\"%70\"/></a>\n\n\nDeep extensive tab completion and help text generation based on the argparse library create the first pillar of 'ease of command discovery'. The following is a list of features in this category.\n\n- Great tab completion of commands, subcommands, file system paths, and shell commands.\n- Custom tab completion for user designed commands via simple function overloading.\n- Tab completion from `persistent_history_file` sources added with very little friction.\n- Automatic tab completion of `argparse` flags and optional arguments.\n- Path completion easily enabled.\n- When all else fails, custom tab completion based on `choices_provider` can fill any gaps.\n\n<a href=\"https://imgflip.com/i/66t0y0\"><img src=\"https://i.imgflip.com/66t0y0.jpg\" title=\"made at imgflip.com\" width=\"70%\" height=\"70%\"/></a>\n\ncmd2 creates the second pillar of 'ease of transition to automation' through alias/macro creation, command line argument parsing and execution of cmd2 scripting.\n\n- Flexible alias and macro creation for quick abstraction of commands.\n- Text file scripting of your application with `run_script` (`@`) and `_relative_run_script` (`@@`)\n- Powerful and flexible built-in Python scripting of your application using the `run_pyscript` command\n- Transcripts for use with built-in regression can be automatically generated from `history -t` or `run_script -t`\n\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.8+ 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/overview/installation.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\nThe best way to learn the cmd2 api is to delve into the example applications located in source under examples.\n\nTutorials\n---------\n\n* PyOhio 2019 presentation:\n    * [video](https://www.youtube.com/watch?v=pebeWrTqIIw)\n    * [slides](https://github.com/python-cmd2/talks/blob/master/PyOhio_2019/cmd2-PyOhio_2019.pdf)\n    * [example code](https://github.com/python-cmd2/talks/tree/master/PyOhio_2019/examples)\n* [Cookiecutter](https://github.com/cookiecutter/cookiecutter) Templates from community\n    * Basic cookiecutter template for cmd2 application : https://github.com/jayrod/cookiecutter-python-cmd2\n    * Advanced cookiecutter template with external plugin support : https://github.com/jayrod/cookiecutter-python-cmd2-ext-plug\n* [Example Applications](https://github.com/jayrod/cmd2-example-apps)\n\n\nHello World\n-----------\n\n```python\n#!/usr/bin/env python\n\"\"\"A simple cmd2 application.\"\"\"\nimport cmd2\n\n\nclass FirstApp(cmd2.Cmd):\n    \"\"\"A simple cmd2 application.\"\"\"\n\n  def do_hello_world(self, _: cmd2.Statement):\n    self.poutput('Hello World')\n\nif __name__ == '__main__':\n    import sys\n    c = FirstApp()\n    sys.exit(c.cmdloop())\n\n```\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\nProjects using cmd2\n-------------------------------\n\n| Application Name                                                | Description                                                                                                                     |   |\n|-----------------------------------------------------------------|---------------------------------------------------------------------------------------------------------------------------------|---|\n| [Jok3r](http://www.jok3r-framework.com)                         | Network & Web Pentest Automation Framework                                                                                      |   |\n| [CephFS Shell](https://github.com/ceph/ceph)                    | [Ceph](https://ceph.com/) is a distributed object, block, and file storage platform                                             |   |\n| [psiTurk](https://psiturk.org)                                  | An open platform for science on Amazon Mechanical Turk                                                                          |   |\n| [Poseidon](https://github.com/CyberReboot/poseidon)             | 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)             | Automatic and platform-independent unpacker for Windows binaries based on emulation                                             |   |\n| [tomcatmanager](https://github.com/tomcatmanager/tomcatmanager) | A command line tool and python library for managing a tomcat server                                                             |   |\n| [Expliot](https://gitlab.com/expliot_framework/expliot)         | Internet of Things (IoT) exploitation framework                                                                                 |   |\n| [mptcpanalyzer]()                                               | Tool to help analyze mptcp pcaps                                                                                                |   |\n| [clanvas](https://github.com/marklalor/clanvas)                 | Command-line client for Canvas by Instructure                                                                                   |   |\n\n\nPossibly defunct but still good examples\n\n* [JSShell](https://github.com/Den1al/JSShell)\n* [FLASHMINGO](https://github.com/fireeye/flashmingo)\n",
    "bugtrack_url": null,
    "license": "The MIT License (MIT)  Copyright (c) 2008-2024 Catherine Devlin and others  Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the \"Software\"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:  The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.  THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. ",
    "summary": "cmd2 - quickly build feature-rich and user-friendly interactive command line applications in Python",
    "version": "2.5.6",
    "project_urls": null,
    "split_keywords": [
        "cli",
        " cmd",
        " command",
        " interactive",
        " prompt",
        " python"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "98ec4a70c467be851d37b77c6e9e04207ea9d7a07b5252d3307d35c08871b108",
                "md5": "16d2d761988f9c4ff33a34a4fbcbdbc0",
                "sha256": "768511d3a496f2e1c20b275362edce8c0f937a0bb05116cf554961d7fb18b59c"
            },
            "downloads": -1,
            "filename": "cmd2-2.5.6-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "16d2d761988f9c4ff33a34a4fbcbdbc0",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.8",
            "size": 151292,
            "upload_time": "2024-11-14T14:00:57",
            "upload_time_iso_8601": "2024-11-14T14:00:57.537624Z",
            "url": "https://files.pythonhosted.org/packages/98/ec/4a70c467be851d37b77c6e9e04207ea9d7a07b5252d3307d35c08871b108/cmd2-2.5.6-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "d588703b5c75610ec4ac2c5bcd390ab4b478e689faf1f02ea91fce3f57d449b8",
                "md5": "fae3094ec91ff8655ca439815b723a0a",
                "sha256": "ab0ff178784ca087d886081b2ca384724c90b9b25eb982c57c6925ca17479f52"
            },
            "downloads": -1,
            "filename": "cmd2-2.5.6.tar.gz",
            "has_sig": false,
            "md5_digest": "fae3094ec91ff8655ca439815b723a0a",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.8",
            "size": 690006,
            "upload_time": "2024-11-14T14:01:00",
            "upload_time_iso_8601": "2024-11-14T14:01:00.055594Z",
            "url": "https://files.pythonhosted.org/packages/d5/88/703b5c75610ec4ac2c5bcd390ab4b478e689faf1f02ea91fce3f57d449b8/cmd2-2.5.6.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2024-11-14 14:01:00",
    "github": false,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "lcname": "cmd2"
}
        
Elapsed time: 0.85642s