summaryrefslogtreecommitdiff
path: root/examples/remove_builtin_commands.py
diff options
context:
space:
mode:
authorTodd Leonhardt <todd.leonhardt@gmail.com>2019-09-21 20:29:39 -0400
committerGitHub <noreply@github.com>2019-09-21 20:29:39 -0400
commit27a0adbe53c7cdeda240c325a6f59b7cca0e7bfd (patch)
treeb2f385058c2758500077543e43f364485ea30354 /examples/remove_builtin_commands.py
parent1176c0cc99975044d2fcec88b3f0903b8453194f (diff)
parentb45fec9859533f8a1dcab3f5524945cb3b9c11a2 (diff)
downloadcmd2-git-27a0adbe53c7cdeda240c325a6f59b7cca0e7bfd.tar.gz
Merge pull request #780 from python-cmd2/doc_additions
Doc additions
Diffstat (limited to 'examples/remove_builtin_commands.py')
-rwxr-xr-xexamples/remove_builtin_commands.py31
1 files changed, 31 insertions, 0 deletions
diff --git a/examples/remove_builtin_commands.py b/examples/remove_builtin_commands.py
new file mode 100755
index 00000000..4c1794d6
--- /dev/null
+++ b/examples/remove_builtin_commands.py
@@ -0,0 +1,31 @@
+#!/usr/bin/env python
+# coding=utf-8
+"""A simple example demonstrating how to remove unused commands.
+
+Commands can be removed from help menu and tab completion by appending their command name to the hidden_commands 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 RemoveBuiltinCommands(cmd2.Cmd):
+ """ Example cmd2 application where we remove some unused built-in commands."""
+
+ def __init__(self):
+ super().__init__()
+
+ # To hide commands from displaying in the help menu, add them to the hidden_commands list
+ self.hidden_commands.append('py')
+
+ # To remove built-in commands entirely, delete their "do_*" function from the cmd2.Cmd class
+ del cmd2.Cmd.do_edit
+
+
+if __name__ == '__main__':
+ import sys
+ app = RemoveBuiltinCommands()
+ sys.exit(app.cmdloop())