A python package for building powerful command-line interpreter (CLI) programs. Extends the Python Standard Library’s cmd package.
The basic use of
cmd2 is identical to that of cmd.
Create a subclass of
cmd2.Cmd. Define attributes and
do_*methods to control its behavior. Throughout this documentation, we will assume that you are naming your subclass
from cmd2 import Cmd class App(Cmd): # customized attributes and methods here
Appand start the command loop:
app = App() app.cmdloop()
Already built an application that uses cmd from the python standard library and want to add more functionality with very little work?
cmd2 is a powerful python library for building command line applications.
Start here to find out if this library is a good fit for your needs.
- Installation Instructions - how to install
cmd2and associated optional dependencies
- First Application - a sample application showing 8
key features of
- Integrate cmd2 Into Your Project - adding
cmd2to your project
- Alternatives - other python packages that might meet your needs
- Resources - related links and other materials
Migrating from cmd¶
If you’re thinking of migrating your cmd app to
cmd2, this section
will help you decide if it’s right for your app, and show you how to
- Why cmd2 - we try and convince you
cmd2instead of cmd
- Incompatibilities -
cmd2is not quite 100% compatible with cmd.
- Minimum Required Changes - the minimum changes
required to move from cmd to
cmd2. Start your migration here.
- Next Steps - Once you’ve migrated, here a list of things you can do next to add even more functionality to your app.
- Argument Processing
- Builtin Commands
- Clipboard Integration
- Disabling Commands
- Embedded Python Shells
- Generating Output
- Miscellaneous Features
- Multiline Commands
- Integrating with the OS
- Packaging a cmd2 application for distribution
- Output Redirection and Pipes
- Shortcuts, Aliases, and Macros
- Startup Commands