Skip to content

Commit 9e74cfd

Browse files
committed
Added remove_unused.py example to demonstrate how to remove unused commands
1 parent 9f5bddb commit 9e74cfd

File tree

2 files changed

+32
-1
lines changed

2 files changed

+32
-1
lines changed

CHANGES.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
News
1+
rerNews
22
====
33

44
0.7.6
@@ -13,6 +13,7 @@ News
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

1718
0.7.5
1819
-----

examples/remove_unused.py

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
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()

0 commit comments

Comments
 (0)