Skip to content

Commit

Permalink
Make Rookify execute in dry-run mode by default
Browse files Browse the repository at this point in the history
Signed-off-by: Boekhorst <[email protected]>
Co-authored-by: Tobias Wolf <[email protected]>
  • Loading branch information
boekhorstb1 and NotTheEvilOne authored Oct 1, 2024
1 parent ad6f0da commit 225b1f7
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 11 deletions.
34 changes: 27 additions & 7 deletions src/rookify/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,16 +15,33 @@ def parse_args(args: list[str]) -> argparse.Namespace:
# Putting args-parser in seperate function to make this testable
arg_parser = ArgumentParser("Rookify")

# --dry-run option
arg_parser.add_argument("--dry-run", action="store_true", dest="dry_run_mode")
arg_parser.add_argument(
"-d",
"--dry-run",
action="store_true",
dest="dry_run_mode",
help="Preflight data analysis and migration validation.",
)

arg_parser.add_argument(
"-m",
"--migrate",
action="store_true",
dest="execution_mode",
help="Run the migration.",
)

arg_parser.add_argument(
"-s",
"--show-states",
action="store_true",
dest="show_states",
help="Show states of the modules.",
)

if len(args) < 1:
args = ["--dry-run"]

return arg_parser.parse_args(args)


Expand All @@ -39,7 +56,7 @@ def main() -> None:

# Configure logging
try:
if args.show_states is True:
if args.show_states:
configure_logging(
{"level": "ERROR", "format": {"renderer": "console", "time": "iso"}}
)
Expand All @@ -51,16 +68,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:
if args.show_states:
log.debug("Showing Rookify state ...")
ModuleHandler.show_states(machine, config)
else:
elif args.dry_run_mode:
log.info("Running Rookify in dry-run mode ...")
machine.execute(dry_run_mode=args.dry_run_mode)
else:
log.info("Executing Rookify ...")
machine.execute()


if __name__ == "__main__":
Expand Down
10 changes: 6 additions & 4 deletions tests/test_main.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down

0 comments on commit 225b1f7

Please sign in to comment.