cmd2 - Feature-Rich Interactive Command Line Applications

3.4.0 · active · verified Sat Apr 11

cmd2 is a powerful Python library for quickly building feature-rich and user-friendly interactive command-line applications. It extends Python's built-in `cmd` module, providing a comprehensive set of enhancements including robust tab completion, searchable command history, text and Python scripting, and advanced argument parsing with `argparse`. The library is actively maintained with a frequent release cadence, continuously improving its capabilities and user experience.

Warnings

Install

Imports

Quickstart

This minimal example demonstrates how to create a basic `cmd2` application by subclassing `cmd2.Cmd` and defining a `do_` method for a command. Running `cmdloop()` starts the interactive shell, and you can type `hello_world` or `quit` to exit.

import cmd2
import sys

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

    def do_hello_world(self, _: cmd2.Statement):
        """Says hello to the world."""
        self.poutput('Hello World')

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

view raw JSON →