| 1 |
|
| 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 |
|
| 21 |
self.hidden_commands.append("history") |
| 22 |
|
| 23 |
|
| 24 |
del cmd2.Cmd.do_edit |
| 25 |
|
| 26 |
|
| 27 |
if __name__ == "__main__": |
| 28 |
import sys |
| 29 |
|
| 30 |
app = RemoveBuiltinCommands() |
| 31 |
sys.exit(app.cmdloop()) |