| 1 | # Why cmd2 |
| 2 | |
| 3 | ## cmd |
| 4 | |
| 5 | [cmd][cmd] is the Python Standard Library's module for creating simple interactive command-line |
| 6 | applications. [cmd][cmd] is an extremely bare-bones framework which leaves a lot to be desired. It |
| 7 | doesn't even include a built-in way to exit from an application! |
| 8 | |
| 9 | Since the API provided by [cmd][cmd] provides the foundation on which `cmd2` is based, understanding |
| 10 | the use of [cmd][cmd] is the first step in learning the use of `cmd2`. Once you have read the |
| 11 | [cmd](#cmd) docs, return here to learn the ways that `cmd2` differs from [cmd][cmd]. |
| 12 | |
| 13 | ## cmd2 |
| 14 | |
| 15 | `cmd2` is a batteries-included extension of [cmd][cmd], which provides a wealth of functionality to |
| 16 | make it quicker and easier for developers to create feature-rich interactive command-line |
| 17 | applications which delight customers. |
| 18 | |
| 19 | `cmd2` can be used as a drop-in replacement for [cmd][cmd] with a few minor discrepancies as |
| 20 | discussed in the [Incompatibilities](incompatibilities.md) section. Simply importing `cmd2` in place |
| 21 | of [cmd][cmd] will add many features to an application without any further modifications. Migrating |
| 22 | to `cmd2` will also open many additional doors for making it possible for developers to provide a |
| 23 | top-notch interactive command-line experience for their users. |
| 24 | |
| 25 | !!! warning |
| 26 | |
| 27 | As of version 4.0.0, `cmd2` does not have an actual dependency on `cmd`. `cmd2` is mostly API compatible with `cmd2`. |
| 28 | See [Incompatibilities](./incompatibilities.md) for the few documented incompatibilities. |
| 29 | |
| 30 | ## Automatic Features |
| 31 | |
| 32 | After switching from [cmd][cmd] to `cmd2`, your application will have the following new features and |
| 33 | capabilities, without you having to do anything: |
| 34 | |
| 35 | - More robust [History](../features/history.md). Both [cmd][cmd] and `cmd2` provide familiar |
| 36 | readline-style history, but `cmd2` utilizes the powerful |
| 37 | [prompt-toolkit](https://github.com/prompt-toolkit/python-prompt-toolkit) library for a pure |
| 38 | Python, fully cross-platform experience. Additionally, `cmd2` has a robust `history` command which |
| 39 | allows you to edit prior commands in a text editor of your choosing, re-run multiple commands at a |
| 40 | time, save prior commands as a script to be executed later, and much more. |
| 41 | - Users can redirect output to a file or pipe it to some other operating system command. You did |
| 42 | remember to use `self.stdout` instead of `sys.stdout` in all of your print functions, right? If |
| 43 | you did, then this will work out of the box. If you didn't, you'll have to go back and fix them. |
| 44 | Before you do, you should consider the various ways `cmd2` has of |
| 45 | [Generatoring Output](../features/generating_output.md). |
| 46 | - Users can load [script files](../features/scripting.md), which contain a series of commands to be |
| 47 | executed. |
| 48 | - Users can create [Shortcuts, Aliases, and Macros](../features/shortcuts_aliases_macros.md) to |
| 49 | reduce the typing required for repetitive commands. |
| 50 | - [Embedded Python and/or IPython shells](../features/embedded_python_shells.md) allow a user to |
| 51 | execute Python code from within your `cmd2` app. How meta. |
| 52 | - [Clipboard Integration](../features/clipboard.md) allows you to save command output to the |
| 53 | operating system clipboard. |
| 54 | - A built-in [Timer](../features/misc.md#Timer) can show how long it takes a command to execute |
| 55 | |
| 56 | ## Next Steps |
| 57 | |
| 58 | In addition to the features you get with no additional work, `cmd2` offers a broad range of |
| 59 | additional capabilities which can be easily added to your application. [Next Steps](next_steps.md) |
| 60 | has some ideas of where you can start, or you can dig in to all the |
| 61 | [Features](../features/index.md). |
| 62 | |
| 63 | [cmd]: https://docs.python.org/3/library/cmd |