summaryrefslogtreecommitdiff
path: root/examples
diff options
context:
space:
mode:
authorTodd Leonhardt <todd.leonhardt@gmail.com>2017-07-31 10:26:35 -0400
committerTodd Leonhardt <todd.leonhardt@gmail.com>2017-07-31 10:26:35 -0400
commit9e74cfdc9e287196385113bce55af7bc51bf4473 (patch)
tree98574fa39d5e41f535dd69dea4a4af1923849057 /examples
parent9f5bddbb0b7c49264b6962f6321ef2355b886971 (diff)
downloadcmd2-git-9e74cfdc9e287196385113bce55af7bc51bf4473.tar.gz
Added remove_unused.py example to demonstrate how to remove unused commands
Diffstat (limited to 'examples')
-rwxr-xr-xexamples/remove_unused.py30
1 files changed, 30 insertions, 0 deletions
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()