From af147196e246a45321e3b5834ac6752acf175db4 Mon Sep 17 00:00:00 2001 From: "Soren I. Bjornstad" Date: Wed, 25 Aug 2021 14:48:07 -0500 Subject: [PATCH] fully replicate the commit.sh script as is In fact, this script is missing some things we might like it to have (e.g., making sure we're really in the right directory). --- .gitignore | 1 + filesystem.py | 0 git.py | 5 +++++ tzk.py | 26 +++++++++++++++++++------- 4 files changed, 25 insertions(+), 7 deletions(-) create mode 100644 .gitignore create mode 100644 filesystem.py create mode 100644 git.py diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..c18dd8d --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +__pycache__/ diff --git a/filesystem.py b/filesystem.py new file mode 100644 index 0000000..e69de29 diff --git a/git.py b/git.py new file mode 100644 index 0000000..c09b9af --- /dev/null +++ b/git.py @@ -0,0 +1,5 @@ +import subprocess +from typing import Sequence + +def exec(*args: Sequence[str]): + return subprocess.call(["git", *args]) diff --git a/tzk.py b/tzk.py index 992cc3b..79c500f 100644 --- a/tzk.py +++ b/tzk.py @@ -1,27 +1,37 @@ from abc import ABC, abstractmethod, abstractclassmethod import argparse +import os + +import git class CliCommand(ABC): @abstractclassmethod - def setup_arguments(self, parser): + def setup_arguments(self, parser: argparse.ArgumentParser) -> None: raise NotImplementedError @abstractmethod - def execute(self, parser): + def execute(self, parser: argparse.ArgumentParser) -> None: raise NotImplementedError class CommitCommand(CliCommand): cmd = "commit" - help = "Do a commit" + help = "Commit all changes to the wiki repository." @classmethod - def setup_arguments(self, parser): - pass + def setup_arguments(self, parser: argparse.ArgumentParser) -> None: + parser.add_argument( + "-m, --message", + metavar="MSG", + help="Commit message to use.", + default="daily checkpoint") - def execute(self, args): - print(f"We have committed!") + def execute(self, args: argparse.Namespace) -> None: + os.chdir("zk-wiki") + git.exec("add", "-A") + git.exec("commit", "-m", args.message) + git.exec("push", "backup") parser = argparse.ArgumentParser() @@ -32,4 +42,6 @@ for command in CliCommand.__subclasses__(): command.setup_arguments(subparser) args = parser.parse_args() +print(type(args)) +9/0 args._cls().execute(args)