From 049f21cfe779dbcd795d04917dff4ec3034a1546 Mon Sep 17 00:00:00 2001 From: Elena ``of Valhalla'' Grandi Date: Sat, 12 Mar 2022 20:20:15 +0100 Subject: Beginning of a tutorial in the docs --- docs/source/examples/greeter.py | 40 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 40 insertions(+) create mode 100755 docs/source/examples/greeter.py (limited to 'docs/source/examples') diff --git a/docs/source/examples/greeter.py b/docs/source/examples/greeter.py new file mode 100755 index 0000000..5a978f4 --- /dev/null +++ b/docs/source/examples/greeter.py @@ -0,0 +1,40 @@ +#!/usr/bin/env python3 +import hazwaz + + +class World(hazwaz.Command): + """ + Greet the whole world. + """ + + def main(self): + print("Hello world!") + + +class Individual(hazwaz.Command): + """ + Greet an individual. + """ + + def add_arguments(self, parser): + parser.add_argument( + "gretee", + help="The person to be greeted", + ) + + def main(self): + print("Hello {}".format(self.args.gretee)) + + +class Greet(hazwaz.MainCommand): + """ + Greet people in different ways. + """ + commands = ( + World(), + Individual(), + ) + + +if __name__ == "__main__": + Greet().run() -- cgit v1.2.3