Debian Codegraph @

examples/remove_builtin_commands.py

raw symbols SCIP
1 #!/usr/bin/env python
2 """A simple example demonstrating how to remove unused commands.
3
4 Commands can be removed from help menu and tab completion by appending their command name to the hidden_commands list.
5 These commands will still exist and can be executed and help can be retrieved for them by
6 name, they just won't clutter the help menu.
7
8 Commands can also be removed entirely by using Python's "del".
9 """
10
11 import cmd2
12
13
14 class RemoveBuiltinCommands(cmd2.Cmd):
15 """Example cmd2 application where we remove some unused built-in commands."""
16
17 def __init__(self) -> None:
18 super().__init__()
19
20 # To hide commands from displaying in the help menu, add them to the hidden_commands list
21 self.hidden_commands.append("history")
22
23 # To remove built-in commands entirely, delete their "do_*" function from the cmd2.Cmd class
24 del cmd2.Cmd.do_edit
25
26
27 if __name__ == "__main__":
28 import sys
29
30 app = RemoveBuiltinCommands()
31 sys.exit(app.cmdloop())