List of cmd2 examples
cmd2 Examples
The examples directory within the cmd2
repository contains a number of simple self-contained examples which each demonstrate a few
particular features of cmd2. None of them are representative of a full real-world complex cmd2
application, if you are looking for that then see
Projects using cmd2.
List of cmd2 examples
Here is the list of examples in alphabetical order by filename along with a brief description of each:
- argparse_completion.py
- Shows how to integrate tab-completion with argparse-based commands
- argparse_example.py
- Comprehensive example demonstrating various aspects of using
argparse for command argument processing
via the
cmd2.with_argparserdecorator
- Comprehensive example demonstrating various aspects of using
argparse for command argument processing
via the
- async_call.py
- Shows how to make a call to an async function from a cmd2 command.
- async_printing.py
- Shows how to asynchronously print alerts, update the prompt in realtime, and change the window title
- basic_completion.py
- Show how to enable custom tab completion by assigning a completer function to
do_*commands
- Show how to enable custom tab completion by assigning a completer function to
- cmd2_as_argument.py
- Demonstrates how to accept and parse command-line arguments when invoking a cmd2 application
- color.py
- Show the numerous colors available to use in your cmd2 applications
- command_sets.py
- Example that demonstrates the
CommandSetfeatures for modularizing commands and demonstrates all main capabilities including basic CommandSets, dynamic loading an unloading, using subcommands, etc.
- Example that demonstrates the
- custom_parser.py
- Demonstrates how to create your own custom
Cmd2ArgumentParser
- Demonstrates how to create your own custom
- custom_types.py
- Some useful custom argument types
- default_categories.py
- Demonstrates usage of
@with_default_categorydecorator to group and categorize commands andCommandSetuse
- Demonstrates usage of
- dynamic_commands.py
- Shows how
do_*commands can be dynamically created programatically at runtime
- Shows how
- environment.py
- Shows how to create custom
cmd2.Settableparameters which serve as internal environment variables
- Shows how to create custom
- event_loops.py
- Shows how to integrate a
cmd2application with an external event loop which isn't managed bycmd2
- Shows how to integrate a
- exit_code.py
- Show how to emit a non-zero exit code from your
cmd2application when it exits
- Show how to emit a non-zero exit code from your
- getting_started.py
- Short application that demonstrates many key features of cmd2
- hello_cmd2.py
- Completely bare-bones
cmd2application suitable for rapid testing and debugging ofcmd2itself
- Completely bare-bones
- help_categories.py
- Demonstrates command categorization and its impact on the output of the built-in
helpcommand
- Demonstrates command categorization and its impact on the output of the built-in
- hooks.py
- Shows how to use various
cmd2application lifecycle hooks
- Shows how to use various
- migrating.py
- A simple
cmdapplication that you can migrate tocmd2by changing one line
- A simple
- modular_commands.py
- Complex example demonstrating a variety of methods to load
CommandSetsusing a mix of command decorators
- Complex example demonstrating a variety of methods to load
- paged_output.py
- Shows how to use output pagination within
cmd2apps via theppagedmethod
- Shows how to use output pagination within
- persistent_history.py
- Shows how to enable persistent history in your
cmd2application
- Shows how to enable persistent history in your
- pretty_print.py
- Demonstrates use of rich within cmd2 for pretty-printing arbitrary Python data structures like dictionaries.
- python_scripting.py
- Shows how cmd2's built-in
run_pyscriptcommand can provide advanced Python scripting of cmd2 applications
- Shows how cmd2's built-in
- read_input.py
- Demonstrates the various ways to call
cmd2.Cmd.read_input()for input history and tab completion
- Demonstrates the various ways to call
- remove_builtin_commands.py
- Shows how to remove any built-in cmd2 commands you do not want to be present in your cmd2 application
- remove_settable.py
- Shows how to remove any of the built-in cmd2
Settablesyou do not want in your cmd2 application
- Shows how to remove any of the built-in cmd2
- rich_tables.py
- Example of using Rich Tables within a cmd2 application for displaying tabular data
- rich_theme.py
- Demonstrates how to create a custom theme for a cmd2 application
- tmux_launch.sh
- Shell script that launches two applications using tmux in different windows/tabs
- tmux_split.sh
- Shell script that launches two applications using tmux in a split pane view
- transcript_example.py
- This example is intended to demonstrate
cmd2'sbuild-in transcript testing capability
- This example is intended to demonstrate
- unicode_commands.py
- Shows that cmd2 supports unicode everywhere, including within command names