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

View File

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