Compare commits
2 Commits
6c424c6135
...
75d29a2c0d
| Author | SHA1 | Date | |
|---|---|---|---|
| 75d29a2c0d | |||
| 11f0bce116 |
35
main.py
35
main.py
@@ -3,22 +3,14 @@
|
|||||||
import sys
|
import sys
|
||||||
import argparse
|
import argparse
|
||||||
|
|
||||||
from skywipe.commands import run_configure
|
from skywipe.commands import get_registry
|
||||||
from skywipe.configure import Configuration
|
from skywipe.configure import Configuration
|
||||||
|
|
||||||
|
|
||||||
COMMANDS = {
|
|
||||||
"all": "target everything",
|
|
||||||
"configure": "create configuration",
|
|
||||||
"posts": "only posts",
|
|
||||||
"medias": "only posts with medias",
|
|
||||||
"likes": "only likes",
|
|
||||||
"reposts": "only reposts",
|
|
||||||
"follows": "only follows",
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
def _create_parser():
|
def _create_parser():
|
||||||
|
registry = get_registry()
|
||||||
|
commands = registry.get_all_commands()
|
||||||
|
|
||||||
parser = argparse.ArgumentParser(
|
parser = argparse.ArgumentParser(
|
||||||
description="Clean your bluesky account with style.",
|
description="Clean your bluesky account with style.",
|
||||||
epilog="WARNING: This tool performs destructive operations. Only use it if you intend to erase data from your Bluesky account."
|
epilog="WARNING: This tool performs destructive operations. Only use it if you intend to erase data from your Bluesky account."
|
||||||
@@ -31,16 +23,12 @@ def _create_parser():
|
|||||||
required=True
|
required=True
|
||||||
)
|
)
|
||||||
|
|
||||||
for cmd, help_text in COMMANDS.items():
|
for cmd, help_text in commands.items():
|
||||||
subparsers.add_parser(cmd, help=help_text)
|
subparsers.add_parser(cmd, help=help_text)
|
||||||
|
|
||||||
return parser
|
return parser
|
||||||
|
|
||||||
|
|
||||||
def _check_config_required(command: str) -> bool:
|
|
||||||
return command != "configure"
|
|
||||||
|
|
||||||
|
|
||||||
def _require_config():
|
def _require_config():
|
||||||
config = Configuration()
|
config = Configuration()
|
||||||
if not config.exists():
|
if not config.exists():
|
||||||
@@ -53,13 +41,16 @@ def main():
|
|||||||
parser = _create_parser()
|
parser = _create_parser()
|
||||||
args = parser.parse_args()
|
args = parser.parse_args()
|
||||||
|
|
||||||
if _check_config_required(args.command):
|
registry = get_registry()
|
||||||
|
|
||||||
|
if registry.requires_config(args.command):
|
||||||
_require_config()
|
_require_config()
|
||||||
|
|
||||||
if args.command == "configure":
|
try:
|
||||||
run_configure()
|
registry.execute(args.command)
|
||||||
else:
|
except ValueError as e:
|
||||||
print(f"Command '{args.command}' is not yet implemented.")
|
print(f"Error: {e}")
|
||||||
|
sys.exit(1)
|
||||||
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
|
|||||||
@@ -1,8 +1,95 @@
|
|||||||
"""Command implementations for Skywipe CLI."""
|
"""Command implementations for Skywipe CLI."""
|
||||||
|
|
||||||
|
from typing import Callable, Dict, Optional
|
||||||
from skywipe.configure import Configuration
|
from skywipe.configure import Configuration
|
||||||
|
|
||||||
|
|
||||||
|
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] = {}
|
||||||
|
|
||||||
|
def register(
|
||||||
|
self,
|
||||||
|
name: str,
|
||||||
|
handler: CommandHandler,
|
||||||
|
help_text: str,
|
||||||
|
requires_config: bool = True
|
||||||
|
):
|
||||||
|
self._commands[name] = handler
|
||||||
|
self._help_texts[name] = help_text
|
||||||
|
self._requires_config[name] = requires_config
|
||||||
|
|
||||||
|
def get_handler(self, name: str) -> Optional[CommandHandler]:
|
||||||
|
return self._commands.get(name)
|
||||||
|
|
||||||
|
def get_help_text(self, name: str) -> Optional[str]:
|
||||||
|
return self._help_texts.get(name)
|
||||||
|
|
||||||
|
def requires_config(self, name: str) -> bool:
|
||||||
|
return self._requires_config.get(name, True)
|
||||||
|
|
||||||
|
def get_all_commands(self) -> Dict[str, str]:
|
||||||
|
return self._help_texts.copy()
|
||||||
|
|
||||||
|
def execute(self, name: str):
|
||||||
|
handler = self.get_handler(name)
|
||||||
|
if handler:
|
||||||
|
handler()
|
||||||
|
else:
|
||||||
|
raise ValueError(f"Unknown command: {name}")
|
||||||
|
|
||||||
|
|
||||||
|
_registry = CommandRegistry()
|
||||||
|
|
||||||
|
|
||||||
|
def get_registry() -> CommandRegistry:
|
||||||
|
return _registry
|
||||||
|
|
||||||
|
|
||||||
def run_configure():
|
def run_configure():
|
||||||
config = Configuration()
|
config = Configuration()
|
||||||
config.create()
|
config.create()
|
||||||
|
|
||||||
|
|
||||||
|
def run_posts():
|
||||||
|
print("Command 'posts' is not yet implemented.")
|
||||||
|
|
||||||
|
|
||||||
|
def run_medias():
|
||||||
|
print("Command 'medias' is not yet implemented.")
|
||||||
|
|
||||||
|
|
||||||
|
def run_likes():
|
||||||
|
print("Command 'likes' is not yet implemented.")
|
||||||
|
|
||||||
|
|
||||||
|
def run_reposts():
|
||||||
|
print("Command 'reposts' is not yet implemented.")
|
||||||
|
|
||||||
|
|
||||||
|
def run_follows():
|
||||||
|
print("Command 'follows' is not yet implemented.")
|
||||||
|
|
||||||
|
|
||||||
|
def run_all():
|
||||||
|
registry = get_registry()
|
||||||
|
registry.execute("posts")
|
||||||
|
registry.execute("medias")
|
||||||
|
registry.execute("likes")
|
||||||
|
registry.execute("reposts")
|
||||||
|
registry.execute("follows")
|
||||||
|
|
||||||
|
|
||||||
|
_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")
|
||||||
|
|||||||
Reference in New Issue
Block a user