File tree Expand file tree Collapse file tree 2 files changed +32
-1
lines changed
Expand file tree Collapse file tree 2 files changed +32
-1
lines changed Original file line number Diff line number Diff line change 1- News
1+ rerNews
22====
33
440.7.6
1313 * Fixed some timing bugs when running unit tests in parallel by using monkeypatch
1414* Enhancements
1515 * Enhanced tab-completion of cmd2 command names to support case-insensitive completion
16+ * Added an example showing how to remove unused commands
1617
17180.7.5
1819-----
Original file line number Diff line number Diff line change 1+ #!/usr/bin/env python
2+ # coding=utf-8
3+ """A simple example demonstrating how to remove unused commands.
4+
5+ Commands can be removed from the help menu by appending their full command name (including "do_") to the
6+ "exclude_from_help" list. These commands will still exist and can be executed and help can be retrieved for them by
7+ name, they just won't clutter the help menu.
8+
9+ Commands can also be removed entirely by using Python's "del".
10+ """
11+
12+ import cmd2
13+
14+
15+ class RemoveUnusedBuiltinCommands (cmd2 .Cmd ):
16+ """ Example cmd2 application where we remove some unused built-in commands."""
17+
18+ def __init__ (self ):
19+ cmd2 .Cmd .__init__ (self )
20+
21+ # To hide commands from displaying in the help menu, add their function name to the exclude_from_help list
22+ self .exclude_from_help .append ('do__relative_load' )
23+
24+ # To remove built-in commands entirely, delete their "do_*" function from the cmd2.Cmd class
25+ del cmd2 .Cmd .do_cmdenvironment
26+
27+
28+ if __name__ == '__main__' :
29+ app = RemoveUnusedBuiltinCommands ()
30+ app .cmdloop ()
You can’t perform that action at this time.
0 commit comments