Initial commands

This commit is contained in:
einarf
2023-03-09 00:56:50 +01:00
parent 7294d85c09
commit dbf238c5a9
7 changed files with 58 additions and 48 deletions

View File

@@ -1,12 +1,30 @@
import logging
from restic_compose_backup.config import Config
from restic_compose_backup.containers import RunningContainers
from restic_compose_backup import log
class BaseCommand:
"""Base class for all commands"""
name = "base"
def __init__(self):
def __init__(self, cli_args, *args, **kwargs):
self.cli_args = cli_args
self.log_level = cli_args.log_level
self.config = Config()
self.logger = logging.getLogger(__name__)
log.setup(level=self.log_level or self.config.log_level)
def get_containers(self):
"""Get running containers"""
return RunningContainers()
def run(self):
"""Run the command"""
raise NotImplementedError
def run_command(self, command: str):
"""Run a command by name and return the result"""
from . import COMMANDS
command = COMMANDS[command]
command(self.cli_args).run()