Compare commits

...

4 Commits

Author SHA1 Message Date
bc425b9224 Avoid duplicate confirmations in a safer way
This version instead still requires --yes with --restart to avoid the
confirmation option, but avoids duplicate prompts.

This might be slightly more cumbersome, but ensures consistency: every
situation that could cause a restart is confirmed even if --restart is
given.
2023-11-01 12:05:52 -04:00
79e5c098cd Revert "Remove duplicate confirmation for VM restart"
This reverts commit 3c61a3ac03.
2023-11-01 12:04:34 -04:00
3c61a3ac03 Remove duplicate confirmation for VM restart
Having both restart_opt and confirm_opt resulted in a duplicate
confirmation message, at least if neither --restart/--no-restart is
specified. This is not necessary as the confirmation is already given by
the restart_opt or the relevant --restart/--no-restart flag.
2023-11-01 12:02:34 -04:00
988c777912 Properly handle live state with restart confirm
If "--live" is passed (the default), we shouldn't confirm to restart the
VM as this is not required. Instead only confirm if "--no-live" was
passed or if the flag doesn't exist.
2023-11-01 11:46:59 -04:00

View File

@ -169,9 +169,10 @@ def restart_opt(function):
@wraps(function)
def confirm_action(*args, **kwargs):
restart_state = kwargs.get("restart_flag", None)
live_state = kwargs.get("live_flag", False)
if restart_state is None:
# Neither "--restart" or "--no-restart" was passed: prompt for restart or restart if "--unsafe"
if restart_state is None and not live_state:
# Neither "--restart" or "--no-restart" was passed, and "--no-live" was passed: prompt for restart or restart if "--unsafe"
try:
click.confirm(
f"Restart VM {kwargs.get('domain')} to apply changes",
@ -179,6 +180,7 @@ def restart_opt(function):
abort=True,
)
kwargs["restart_flag"] = True
kwargs["confirm_flag"] = True
except Exception:
echo(CLI_CONFIG, "Changes will be applied on next VM start/restart.")
kwargs["restart_flag"] = False