Compare commits

...

2 Commits

2 changed files with 19 additions and 26 deletions

13
main.py
View File

@@ -3,12 +3,11 @@
import sys
import argparse
from skywipe.commands import get_registry
from skywipe.commands import registry
from skywipe.configure import Configuration
def _create_parser():
registry = get_registry()
def create_parser():
commands = registry.get_all_commands()
parser = argparse.ArgumentParser(
@@ -29,7 +28,7 @@ def _create_parser():
return parser
def _require_config():
def require_config():
config = Configuration()
if not config.exists():
print("Error: Configuration file not found.")
@@ -38,13 +37,11 @@ def _require_config():
def main():
parser = _create_parser()
parser = create_parser()
args = parser.parse_args()
registry = get_registry()
if registry.requires_config(args.command):
_require_config()
require_config()
try:
registry.execute(args.command)

View File

@@ -2,6 +2,7 @@
from typing import Callable, Dict, Optional
from skywipe.configure import Configuration
from skywipe.posts import delete_posts
CommandHandler = Callable[[], None]
@@ -9,9 +10,9 @@ CommandHandler = Callable[[], None]
class CommandRegistry:
def __init__(self):
self._commands: Dict[str, CommandHandler] = {}
self._help_texts: Dict[str, str] = {}
self._requires_config: Dict[str, bool] = {}
self._commands = {}
self._help_texts = {}
self._requires_config = {}
def register(
self,
@@ -44,11 +45,7 @@ class CommandRegistry:
raise ValueError(f"Unknown command: {name}")
_registry = CommandRegistry()
def get_registry() -> CommandRegistry:
return _registry
registry = CommandRegistry()
def run_configure():
@@ -57,7 +54,7 @@ def run_configure():
def run_posts():
print("Command 'posts' is not yet implemented.")
delete_posts()
def run_medias():
@@ -77,7 +74,6 @@ def run_follows():
def run_all():
registry = get_registry()
registry.execute("posts")
registry.execute("medias")
registry.execute("likes")
@@ -85,11 +81,11 @@ def run_all():
registry.execute("follows")
_registry.register("configure", run_configure,
registry.register("configure", run_configure,
"create configuration", requires_config=False)
_registry.register("posts", run_posts, "only posts")
_registry.register("medias", run_medias, "only posts with medias")
_registry.register("likes", run_likes, "only likes")
_registry.register("reposts", run_reposts, "only reposts")
_registry.register("follows", run_follows, "only follows")
_registry.register("all", run_all, "target everything")
registry.register("posts", run_posts, "only posts")
registry.register("medias", run_medias, "only posts with medias")
registry.register("likes", run_likes, "only likes")
registry.register("reposts", run_reposts, "only reposts")
registry.register("follows", run_follows, "only follows")
registry.register("all", run_all, "target everything")