From c69c9061e0936ddecf4cc4f1c4f38ef08d8694e4 Mon Sep 17 00:00:00 2001 From: Boekhorst Date: Mon, 30 Sep 2024 10:26:52 +0200 Subject: [PATCH] fix: use dryrun as default and add migrate as executing command Signed-off-by: Boekhorst --- src/rookify/__main__.py | 24 ++++++++++++++---------- tests/test_main.py | 10 ++++++---- 2 files changed, 20 insertions(+), 14 deletions(-) diff --git a/src/rookify/__main__.py b/src/rookify/__main__.py index 1e2dfcb..cbefffc 100644 --- a/src/rookify/__main__.py +++ b/src/rookify/__main__.py @@ -26,18 +26,19 @@ def parse_args(args: list[str]) -> argparse.Namespace: ) arg_parser.add_argument( - "run", - nargs="?", - default=False, + "-m", + "--migrate", + action="store_true", + dest="execution_mode", help="Run the migration.", ) # Show help if no arguments are provided if not args: - arg_parser.print_help() - sys.exit(1) - - return arg_parser.parse_args(args) + print("No arguments provided.") + return arg_parser.parse_args(["--dry-run"]) + else: + return arg_parser.parse_args(args) def main() -> None: @@ -63,16 +64,19 @@ def main() -> None: # Get Logger log = get_logger() - log.info("Executing Rookify ...") - machine = Machine(config["general"].get("machine_pickle_file")) load_modules(machine, config) if args.show_states is True: + log.info("Showing Rookify state ...") ModuleHandler.show_states(machine, config) - if args.run: + elif args.dry_run_mode is True: + log.info("Running Rookify in dry-run-mode ...") machine.execute(dry_run_mode=args.dry_run_mode) + elif args.execution_mode is True: + log.info("Executing Rookify ...") + machine.execute() if __name__ == "__main__": diff --git a/tests/test_main.py b/tests/test_main.py index 6504e33..92a0f9e 100644 --- a/tests/test_main.py +++ b/tests/test_main.py @@ -17,10 +17,12 @@ # fmt: off test_cases: List[TestCase] = [ - (["--dry-run"], argparse.Namespace(dry_run_mode=True, show_states=False)), - (["--show-states"], argparse.Namespace(dry_run_mode=False, show_states=True)), - (["--dry-run", "--show-states"], argparse.Namespace(dry_run_mode=True, show_states=True)), - ([], argparse.Namespace(dry_run_mode=False, show_states=False)), + (["--migrate"], argparse.Namespace(dry_run_mode=False, show_states=False, execution_mode=True)), + (["--migrate", "--dry-run"], argparse.Namespace(dry_run_mode=True, show_states=False, execution_mode=True)), + (["--dry-run"], argparse.Namespace(dry_run_mode=True, show_states=False, execution_mode=False)), + (["--show-states"], argparse.Namespace(dry_run_mode=False, show_states=True, execution_mode=False)), + (["--dry-run", "--show-states"], argparse.Namespace(dry_run_mode=True, show_states=True, execution_mode=False)), + ([], argparse.Namespace(dry_run_mode=True, show_states=False, execution_mode=False)), ] # fmt: on