Debian Codegraph @

examples/README.md

raw symbols SCIP
1 # cmd2 Examples
2
3 The [examples](https://github.com/python-cmd2/cmd2/tree/main/examples) directory within the `cmd2`
4 repository contains a number of simple self-contained examples which each demonstrate a few
5 particular features of `cmd2`. None of them are representative of a full real-world complex `cmd2`
6 application, if you are looking for that then see
7 [Projects using cmd2](https://github.com/python-cmd2/cmd2?tab=readme-ov-file#projects-using-cmd2).
8
9 ## List of cmd2 examples
10
11 Here is the list of examples in alphabetical order by filename along with a brief description of
12 each:
13
14 - [argparse_completion.py](https://github.com/python-cmd2/cmd2/blob/main/examples/argparse_completion.py)
15 - Shows how to integrate tab-completion with argparse-based commands
16 - [argparse_example.py](https://github.com/python-cmd2/cmd2/blob/main/examples/argparse_example.py)
17 - Comprehensive example demonstrating various aspects of using
18 [argparse](https://docs.python.org/3/library/argparse.html) for command argument processing
19 via the `cmd2.with_argparser` decorator
20 - [async_call.py](https://github.com/python-cmd2/cmd2/blob/main/examples/async_call.py)
21 - Shows how to make a call to an async function from a cmd2 command.
22 - [async_commands.py](https://github.com/python-cmd2/cmd2/blob/main/examples/async_commands.py)
23 - A simple example demonstrating how to run async commands in a cmd2 app
24 - [async_printing.py](https://github.com/python-cmd2/cmd2/blob/main/examples/async_printing.py)
25 - Shows how to asynchronously print alerts, update the prompt in realtime, and change the window
26 title
27 - [basic_completion.py](https://github.com/python-cmd2/cmd2/blob/main/examples/basic_completion.py)
28 - Show how to enable custom tab completion by assigning a completer function to `do_*` commands
29 - [cmd2_as_argument.py](https://github.com/python-cmd2/cmd2/blob/main/examples/cmd_as_argument.py)
30 - Demonstrates how to accept and parse command-line arguments when invoking a cmd2 application
31 - [color.py](https://github.com/python-cmd2/cmd2/blob/main/examples/color.py)
32 - Show the numerous colors available to use in your cmd2 applications
33 - [command_sets.py](https://github.com/python-cmd2/cmd2/blob/main/examples/command_sets.py)
34 - Example that demonstrates the `CommandSet` features for modularizing commands and demonstrates
35 all main capabilities including basic CommandSets, dynamic loading an unloading, using
36 subcommands, etc.
37 - [completion_item_choices.py](https://github.com/python-cmd2/cmd2/blob/main/examples/completion_item_choices.py)
38 - Demonstrates using CompletionItem instances as elements in an argparse choices list.
39 - [custom_parser.py](https://github.com/python-cmd2/cmd2/blob/main/examples/custom_parser.py)
40 - Demonstrates how to create your own custom `Cmd2ArgumentParser`
41 - [custom_types.py](https://github.com/python-cmd2/cmd2/blob/main/examples/custom_types.py)
42 - Some useful custom argument types
43 - [default_categories.py](https://github.com/python-cmd2/cmd2/blob/main/examples/default_categories.py)
44 - Demonstrates usage of the `DEFAULT_CATEGORY` class variable to group and categorize commands.
45 - [dynamic_commands.py](https://github.com/python-cmd2/cmd2/blob/main/examples/dynamic_commands.py)
46 - Shows how `do_*` commands can be dynamically created programmatically at runtime
47 - [environment.py](https://github.com/python-cmd2/cmd2/blob/main/examples/environment.py)
48 - Shows how to create custom `cmd2.Settable` parameters which serve as internal environment
49 variables
50 - [event_loops.py](https://github.com/python-cmd2/cmd2/blob/main/examples/event_loops.py)
51 - Shows how to integrate a `cmd2` application with an external event loop which isn't managed by
52 `cmd2`
53 - [exit_code.py](https://github.com/python-cmd2/cmd2/blob/main/examples/exit_code.py)
54 - Show how to emit a non-zero exit code from your `cmd2` application when it exits
55 - [getting_started.py](https://github.com/python-cmd2/cmd2/blob/main/examples/getting_started.py)
56 - Short application that demonstrates many key features of cmd2
57 - [hello_cmd2.py](https://github.com/python-cmd2/cmd2/blob/main/examples/hello_cmd2.py)
58 - Completely bare-bones `cmd2` application suitable for rapid testing and debugging of `cmd2`
59 itself
60 - [help_categories.py](https://github.com/python-cmd2/cmd2/blob/main/examples/help_categories.py)
61 - Demonstrates command categorization and its impact on the output of the built-in `help`
62 command
63 - [hooks.py](https://github.com/python-cmd2/cmd2/blob/main/examples/hooks.py)
64 - Shows how to use various `cmd2` application lifecycle hooks
65 - [migrating.py](https://github.com/python-cmd2/cmd2/blob/main/examples/migrating.py)
66 - A simple `cmd` application that you can migrate to `cmd2` by changing one line
67 - [modular_commandsets.py](https://github.com/python-cmd2/cmd2/blob/main/examples/modular_commandsets.py)
68 - Complex example demonstrating a variety of methods to load `CommandSets` using a mix of
69 command decorators
70 - [paged_output.py](https://github.com/python-cmd2/cmd2/blob/main/examples/paged_output.py)
71 - Shows how to use output pagination within `cmd2` apps via the `ppaged` method
72 - [persistent_history.py](https://github.com/python-cmd2/cmd2/blob/main/examples/persistent_history.py)
73 - Shows how to enable persistent history in your `cmd2` application
74 - [pretty_print.py](https://github.com/python-cmd2/cmd2/blob/main/examples/pretty_print.py)
75 - Demonstrates use of rich within cmd2 for pretty-printing arbitrary Python data structures like
76 dictionaries.
77 - [python_scripting.py](https://github.com/python-cmd2/cmd2/blob/main/examples/python_scripting.py)
78 - Shows how cmd2's built-in `run_pyscript` command can provide advanced Python scripting of cmd2
79 applications
80 - [read_input.py](https://github.com/python-cmd2/cmd2/blob/main/examples/read_input.py)
81 - Demonstrates the various ways to call `cmd2.Cmd.read_input()` and `cmd2.Cmd.read_secret()` for
82 input history, tab completion, and password masking
83 - [remove_builtin_commands.py](https://github.com/python-cmd2/cmd2/blob/main/examples/remove_builtin_commands.py)
84 - Shows how to remove any built-in cmd2 commands you do not want to be present in your cmd2
85 application
86 - [remove_settable.py](https://github.com/python-cmd2/cmd2/blob/main/examples/remove_settable.py)
87 - Shows how to remove any of the built-in cmd2 `Settables` you do not want in your cmd2
88 application
89 - [rich_tables.py](https://github.com/python-cmd2/cmd2/blob/main/examples/rich_tables.py)
90 - Example of using Rich Tables within a cmd2 application for displaying tabular data
91 - [rich_theme.py](https://github.com/python-cmd2/cmd2/blob/main/examples/rich_theme.py)
92 - Demonstrates how to create a custom theme for a cmd2 application
93 - [tmux_launch.sh](https://github.com/python-cmd2/cmd2/blob/main/examples/tmux_launch.sh)
94 - Shell script that launches two applications using tmux in different windows/tabs
95 - [tmux_split.sh](https://github.com/python-cmd2/cmd2/blob/main/examples/tmux_split.sh)
96 - Shell script that launches two applications using tmux in a split pane view
97 - [unicode_commands.py](https://github.com/python-cmd2/cmd2/blob/main/examples/unicode_commands.py)
98 - Shows that cmd2 supports unicode everywhere, including within command names