summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--CHANGES.md3
-rwxr-xr-xexamples/remove_unused.py30
2 files changed, 32 insertions, 1 deletions
diff --git a/CHANGES.md b/CHANGES.md
index 56983a07..43225f44 100644
--- a/CHANGES.md
+++ b/CHANGES.md
@@ -1,4 +1,4 @@
-News
+rerNews
====
0.7.6
@@ -13,6 +13,7 @@ News
* Fixed some timing bugs when running unit tests in parallel by using monkeypatch
* Enhancements
* Enhanced tab-completion of cmd2 command names to support case-insensitive completion
+ * Added an example showing how to remove unused commands
0.7.5
-----
diff --git a/examples/remove_unused.py b/examples/remove_unused.py
new file mode 100755
index 00000000..c8c9e15e
--- /dev/null
+++ b/examples/remove_unused.py
@@ -0,0 +1,30 @@
+#!/usr/bin/env python
+# coding=utf-8
+"""A simple example demonstrating how to remove unused commands.
+
+Commands can be removed from the help menu by appending their full command name (including "do_") to the
+"exclude_from_help" list. These commands will still exist and can be executed and help can be retrieved for them by
+name, they just won't clutter the help menu.
+
+Commands can also be removed entirely by using Python's "del".
+"""
+
+import cmd2
+
+
+class RemoveUnusedBuiltinCommands(cmd2.Cmd):
+ """ Example cmd2 application where we remove some unused built-in commands."""
+
+ def __init__(self):
+ cmd2.Cmd.__init__(self)
+
+ # To hide commands from displaying in the help menu, add their function name to the exclude_from_help list
+ self.exclude_from_help.append('do__relative_load')
+
+ # To remove built-in commands entirely, delete their "do_*" function from the cmd2.Cmd class
+ del cmd2.Cmd.do_cmdenvironment
+
+
+if __name__ == '__main__':
+ app = RemoveUnusedBuiltinCommands()
+ app.cmdloop()