From 429f1b488152df81b7b54e4cbc23a317ada4535a Mon Sep 17 00:00:00 2001 From: Kharec Date: Sun, 14 Dec 2025 11:21:38 +0100 Subject: [PATCH] feat: way better argument parsing, cleaner structure and future-proof routing --- main.py | 62 +++++++++++++++++++++++++++++++++++++++++++++++---------- 1 file changed, 51 insertions(+), 11 deletions(-) diff --git a/main.py b/main.py index 154869c..f78303c 100644 --- a/main.py +++ b/main.py @@ -3,24 +3,64 @@ import sys import argparse -from skywipe.commands import * +from skywipe.commands import run_configure +from skywipe.configuration 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(): + parser = argparse.ArgumentParser( + 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." + ) + + subparsers = parser.add_subparsers( + dest="command", + help="Command to execute", + metavar="COMMAND", + required=True + ) + + for cmd, help_text in COMMANDS.items(): + subparsers.add_parser(cmd, help=help_text) + + return parser + + +def _check_config_required(command: str) -> bool: + return command != "configure" + + +def _require_config(): + config = Configuration() + if not config.exists(): + print("Error: Configuration file not found.") + print("You must run 'skywipe configure' first.") + sys.exit(1) def main(): - parser = argparse.ArgumentParser( - description="Clean your bluesky account with style") - parser.add_argument( - "command", - choices=["all", "configure", "posts", - "medias", "likes", "reposts", "follows"], - help="Command to execute" - ) - + parser = _create_parser() args = parser.parse_args() + if _check_config_required(args.command): + _require_config() + if args.command == "configure": run_configure() - + else: + print(f"Command '{args.command}' is not yet implemented.") + if __name__ == '__main__': main()