From 804e3bd05a34f4f3e286bcac355a18e90b5b932c Mon Sep 17 00:00:00 2001 From: "Soren I. Bjornstad" Date: Wed, 25 Aug 2021 14:36:40 -0500 Subject: [PATCH] initial toy commit --- tzk.py | 35 +++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) create mode 100644 tzk.py diff --git a/tzk.py b/tzk.py new file mode 100644 index 0000000..992cc3b --- /dev/null +++ b/tzk.py @@ -0,0 +1,35 @@ +from abc import ABC, abstractmethod, abstractclassmethod +import argparse + + +class CliCommand(ABC): + @abstractclassmethod + def setup_arguments(self, parser): + raise NotImplementedError + + @abstractmethod + def execute(self, parser): + raise NotImplementedError + + +class CommitCommand(CliCommand): + cmd = "commit" + help = "Do a commit" + + @classmethod + def setup_arguments(self, parser): + pass + + def execute(self, args): + print(f"We have committed!") + + +parser = argparse.ArgumentParser() +subparsers = parser.add_subparsers() +for command in CliCommand.__subclasses__(): + subparser = subparsers.add_parser(command.cmd, help=command.help) + subparser.set_defaults(_cls=command) + command.setup_arguments(subparser) + +args = parser.parse_args() +args._cls().execute(args)