Overview¶
cmd2
is an extension of cmd, the Python Standard Library’s module for
creating simple interactive command-line applications.
cmd2
can be used as a drop-in replacement for cmd. Simply importing cmd2
in place of cmd will add many features to an application without any further
modifications.
Understanding the use of cmd is the first step in learning the use of cmd2
.
Once you have read the cmd docs, return here to learn the ways that cmd2
differs from cmd.
Note
cmd2
is not quite a drop-in replacement for cmd.
The cmd.emptyline() function is called
when an empty line is entered in response to the prompt. By default, in cmd if this method is not overridden, it
repeats and executes the last nonempty command entered. However, no end user we have encountered views this as
expected or desirable default behavior. Thus, the default behavior in cmd2
is to simply go to the next line
and issue the prompt again. At this time, cmd2 completely ignores empty lines and the base class cmd.emptyline()
method never gets called and thus the emptyline() behavior cannot be overridden.