Better handle empty diffs

This commit is contained in:
Joshua Boniface 2023-08-27 14:44:21 -04:00
parent b968110e9f
commit 0bae729a18
1 changed files with 19 additions and 7 deletions

View File

@ -1216,9 +1216,6 @@ def cli_vm_modify(
), ),
) )
# Show a diff and confirm
echo(CLI_CONFIG, "Pending modifications:")
echo(CLI_CONFIG, "")
diff = list( diff = list(
unified_diff( unified_diff(
current_vm_cfgfile.split("\n"), current_vm_cfgfile.split("\n"),
@ -1231,6 +1228,13 @@ def cli_vm_modify(
lineterm="", lineterm="",
) )
) )
if len(diff) < 1:
echo(CLI_CONFIG, "Aborting with no modifications.")
exit(0)
# Show a diff and confirm
echo(CLI_CONFIG, "Pending modifications:")
echo(CLI_CONFIG, "")
for line in diff: for line in diff:
if re.match(r"^\+", line) is not None: if re.match(r"^\+", line) is not None:
echo(CLI_CONFIG, Fore.GREEN + line + Fore.RESET) echo(CLI_CONFIG, Fore.GREEN + line + Fore.RESET)
@ -4569,8 +4573,6 @@ def cli_provisioner_userdata_modify(name, filename, editor):
new_userdata = new_userdata.strip() new_userdata = new_userdata.strip()
# Show a diff and confirm # Show a diff and confirm
echo(CLI_CONFIG, "Pending modifications:")
echo(CLI_CONFIG, "")
diff = list( diff = list(
unified_diff( unified_diff(
current_userdata.split("\n"), current_userdata.split("\n"),
@ -4583,6 +4585,12 @@ def cli_provisioner_userdata_modify(name, filename, editor):
lineterm="", lineterm="",
) )
) )
if len(diff) < 1:
echo(CLI_CONFIG, "Aborting with no modifications.")
exit(0)
echo(CLI_CONFIG, "Pending modifications:")
echo(CLI_CONFIG, "")
for line in diff: for line in diff:
if re.match(r"^\+", line) is not None: if re.match(r"^\+", line) is not None:
echo(CLI_CONFIG, Fore.GREEN + line + Fore.RESET) echo(CLI_CONFIG, Fore.GREEN + line + Fore.RESET)
@ -4757,8 +4765,6 @@ def cli_provisioner_script_modify(name, filename, editor):
new_script = new_script.strip() new_script = new_script.strip()
# Show a diff and confirm # Show a diff and confirm
echo(CLI_CONFIG, "Pending modifications:")
echo(CLI_CONFIG, "")
diff = list( diff = list(
unified_diff( unified_diff(
current_script.split("\n"), current_script.split("\n"),
@ -4771,6 +4777,12 @@ def cli_provisioner_script_modify(name, filename, editor):
lineterm="", lineterm="",
) )
) )
if len(diff) < 1:
echo(CLI_CONFIG, "Aborting with no modifications.")
exit(0)
echo(CLI_CONFIG, "Pending modifications:")
echo(CLI_CONFIG, "")
for line in diff: for line in diff:
if re.match(r"^\+", line) is not None: if re.match(r"^\+", line) is not None:
echo(CLI_CONFIG, Fore.GREEN + line + Fore.RESET) echo(CLI_CONFIG, Fore.GREEN + line + Fore.RESET)