summaryrefslogtreecommitdiff
path: root/examples/modular_commands_basic.py
diff options
context:
space:
mode:
authorEric Lin <anselor@gmail.com>2020-07-24 12:21:43 -0400
committeranselor <anselor@gmail.com>2020-08-04 13:38:08 -0400
commit06cee9126839c465a356f8b44a5f008853eb8cad (patch)
tree88de1a9f07f20fb6a7e1a8f77b1c48fb41382d19 /examples/modular_commands_basic.py
parent787a31931ed4c4a18ae66a570d396b12b2b7b525 (diff)
downloadcmd2-git-06cee9126839c465a356f8b44a5f008853eb8cad.tar.gz
updated imports
Added additional documentation
Diffstat (limited to 'examples/modular_commands_basic.py')
-rw-r--r--examples/modular_commands_basic.py37
1 files changed, 37 insertions, 0 deletions
diff --git a/examples/modular_commands_basic.py b/examples/modular_commands_basic.py
new file mode 100644
index 00000000..9f4a0bd2
--- /dev/null
+++ b/examples/modular_commands_basic.py
@@ -0,0 +1,37 @@
+#!/usr/bin/env python3
+# coding=utf-8
+"""
+Simple example demonstrating basic CommandSet usage.
+"""
+
+import cmd2
+from cmd2 import CommandSet, with_default_category
+
+
+@with_default_category('My Category')
+class AutoLoadCommandSet(CommandSet):
+ def __init__(self):
+ super().__init__()
+
+ def do_hello(self, cmd: cmd2.Cmd, _: cmd2.Statement):
+ cmd.poutput('Hello')
+
+ def do_world(self, cmd: cmd2.Cmd, _: cmd2.Statement):
+ cmd.poutput('World')
+
+
+class ExampleApp(cmd2.Cmd):
+ """
+ CommandSets are automatically loaded. Nothing needs to be done.
+ """
+
+ def __init__(self):
+ super(ExampleApp, self).__init__()
+
+ def do_something(self, arg):
+ self.poutput('this is the something command')
+
+
+if __name__ == '__main__':
+ app = ExampleApp()
+ app.cmdloop()