|
|
@@ -192,17 +192,13 @@ class BorgmaticContainer:
|
|
|
|
|
|
|
|
|
class CliArguments:
|
|
|
- def __init__(self, namespace) -> None:
|
|
|
- for k, v in vars(namespace).items():
|
|
|
- if k != "type_":
|
|
|
- setattr(self, k, v)
|
|
|
-
|
|
|
- @classmethod
|
|
|
- def init_subparser(cls, p):
|
|
|
- ...
|
|
|
+ @staticmethod
|
|
|
+ def read_command(parser):
|
|
|
+ args = parser.parse_args()
|
|
|
+ return args.command(args)
|
|
|
|
|
|
- @classmethod
|
|
|
- def new(cls) -> None:
|
|
|
+ @staticmethod
|
|
|
+ def new() -> argparse.ArgumentParser:
|
|
|
parser = argparse.ArgumentParser(prog=sys.argv[0])
|
|
|
subparsers = parser.add_subparsers()
|
|
|
|
|
|
@@ -216,34 +212,47 @@ class CliArguments:
|
|
|
]:
|
|
|
p = subparsers.add_parser(sub.command, help=sub.help)
|
|
|
sub.init_subparser(p)
|
|
|
- p.set_defaults(type_=sub)
|
|
|
+ p.set_defaults(command=sub)
|
|
|
|
|
|
- args = parser.parse_args()
|
|
|
- return args.type_(args)
|
|
|
+ return parser
|
|
|
+
|
|
|
+
|
|
|
+class Command:
|
|
|
+ def __init__(self, namespace) -> None:
|
|
|
+ for k, v in vars(namespace).items():
|
|
|
+ if k != "type_":
|
|
|
+ setattr(self, k, v)
|
|
|
|
|
|
+ @classmethod
|
|
|
+ def init_subparser(cls, p):
|
|
|
+ ...
|
|
|
|
|
|
-class CommandStart(CliArguments):
|
|
|
+
|
|
|
+class CommandStart(Command):
|
|
|
command = "start"
|
|
|
help = "start container"
|
|
|
|
|
|
def run(self, *, container: BorgmaticContainer, data_sources: list[Path], secret_sources: list[Secret], **kwargs):
|
|
|
container.run(data_sources, secret_sources)
|
|
|
|
|
|
-class CommandRm(CliArguments):
|
|
|
+
|
|
|
+class CommandRm(Command):
|
|
|
command = "rm"
|
|
|
help = "remove container"
|
|
|
|
|
|
def run(self, *, container: BorgmaticContainer, **kwargs):
|
|
|
container.rm()
|
|
|
|
|
|
-class CommandBash(CliArguments):
|
|
|
+
|
|
|
+class CommandBash(Command):
|
|
|
command = "bash"
|
|
|
help = "run shell in container"
|
|
|
|
|
|
def run(self, *, container: BorgmaticContainer, **kwargs):
|
|
|
container.exec(["bash"])
|
|
|
|
|
|
-class CommandCreateRepo(CliArguments):
|
|
|
+
|
|
|
+class CommandCreateRepo(Command):
|
|
|
command = "create_repo"
|
|
|
help = "create repository"
|
|
|
env_vars=["BORG_PASSPHRASE_NAME", "STORAGE_BOX_USER", "SSH_KEY_NAME"]
|
|
|
@@ -251,7 +260,8 @@ class CommandCreateRepo(CliArguments):
|
|
|
def run(self, *, container: BorgmaticContainer, **kwargs):
|
|
|
container.exec(["borgmatic", "repo-create", "--encryption", "repokey"], self.env_vars)
|
|
|
|
|
|
-class CommandExportKey(CliArguments):
|
|
|
+
|
|
|
+class CommandExportKey(Command):
|
|
|
command = "export_key"
|
|
|
help = "export the repository key"
|
|
|
env_vars=["BORG_PASSPHRASE_NAME", "STORAGE_BOX_USER", "SSH_KEY_NAME"]
|
|
|
@@ -259,7 +269,8 @@ class CommandExportKey(CliArguments):
|
|
|
def run(self, *, container: BorgmaticContainer, **kwargs):
|
|
|
container.exec(["borgmatic", "export", "key"], self.env_vars)
|
|
|
|
|
|
-class CommandCreateSecrets(CliArguments):
|
|
|
+
|
|
|
+class CommandCreateSecrets(Command):
|
|
|
command="create_secrets"
|
|
|
help="create podman secrets"
|
|
|
|
|
|
@@ -285,8 +296,9 @@ def main():
|
|
|
|
|
|
container = BorgmaticContainer.new(hostname, login)
|
|
|
|
|
|
- args = CliArguments.new()
|
|
|
- args.run(
|
|
|
+ parser = CliArguments.new()
|
|
|
+ command = CliArguments.read_command(parser)
|
|
|
+ command.run(
|
|
|
secret_sources=secret_sources,
|
|
|
data_sources=data_sources,
|
|
|
container=container,
|