Skip to content

Commit

Permalink
Add option in recipesauto to not ask for confirmation over and over
Browse files Browse the repository at this point in the history
  • Loading branch information
benoit74 committed Jan 10, 2025
1 parent 0ee588e commit 5b05dd9
Showing 1 changed file with 27 additions and 15 deletions.
42 changes: 27 additions & 15 deletions recipesauto/src/recipesauto/processor.py
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,7 @@ def _create_new_recipes(
logger.info(
f"{len(recipes_to_create)} recipes would have been created:"
)
ask_for_confirmation = True
for recipe in recipes_to_create:
logger.info(f'- {recipe["name"]}')
if not context.push:
Expand All @@ -132,11 +133,14 @@ def _create_new_recipes(
# /!\ beware that it means that if you run this tool twice in a /!\
# /!\ row, second run will erase these "on-creation" settings /!\

if (
input("Do you really want to create this recipe? [y/N]").upper()
!= "Y"
):
continue
if ask_for_confirmation:
response = input(
"Do you really want to create this recipe? [y/N/a]"
).upper()
if response not in ("Y", "A"):
continue
if response == "A":
ask_for_confirmation = False
self._create_recipe_on_zf(recipe)
logger.info("Recipe created successfully")

Expand Down Expand Up @@ -198,6 +202,7 @@ def _maintain_existing_recipes(
logger.info(
f"{len(recipes_to_maintain)} recipes would have been maintained:"
)
ask_for_confirmation = True
for expected_recipe in recipes_to_maintain:
logger.info(f'- {expected_recipe["name"]}')
if override := self._get_recipe_overrides(expected_recipe["name"]):
Expand Down Expand Up @@ -251,11 +256,14 @@ def _maintain_existing_recipes(
logger.info(f"Removed keys: {previous_keys}")
changes[current_recipe_key] = expected_value
if changes and context.push:
if (
input("Do you really want to update this recipe? [y/N]").upper()
!= "Y"
):
continue
if ask_for_confirmation:
response = input(
"Do you really want to update this recipe? [y/N/a]"
).upper()
if response not in ("Y", "A"):
continue
if response == "A":
ask_for_confirmation = False
self._patch_recipe_on_zf(expected_recipe["name"], changes)
logger.info("Recipe updated successfully")

Expand Down Expand Up @@ -291,15 +299,19 @@ def _delete_obsolete_recipes(
logger.info(
f"{len(recipes_to_delete)} recipes would have been deleted:"
)
ask_for_confirmation = True
for recipe in recipes_to_delete:
logger.info(f"- {recipe}")
if not context.push:
continue
if (
input("Do you really want to delete this recipe? [y/N]").upper()
!= "Y"
):
continue
if ask_for_confirmation:
response = input(
"Do you really want to delete this recipe? [y/N/a]"
).upper()
if response not in ("Y", "A"):
continue
if response == "A":
ask_for_confirmation = False
self._delete_recipe_on_zf(recipe)
logger.info("Recipe deleted successfully")

Expand Down

0 comments on commit 5b05dd9

Please sign in to comment.