Skip to content

Commit c62bc8e

Browse files
feat(dns-resolver): add an option to exit the script
1 parent f952ffa commit c62bc8e

File tree

1 file changed

+11
-4
lines changed

1 file changed

+11
-4
lines changed

files/system/usr/libexec/secureblue/dns_selector.py

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -50,16 +50,16 @@
5050

5151

5252
def ask_option(options_count: int) -> int:
53-
"""Returns the user's chosen number between 1 and options_count."""
53+
"""Returns the user's chosen number between 0 and options_count."""
5454

5555
while True:
56-
raw_option = interruptible_ask(f"Choose an option [1-{options_count}]: ")
56+
raw_option = interruptible_ask(f"Choose an option [0-{options_count}]: ")
5757
if raw_option.isdigit():
5858
option = int(raw_option)
5959
if 1 <= option <= options_count:
6060
print()
6161
return option
62-
print(f"Please enter a number between 1 and {options_count}.")
62+
print(f"Please enter a number between 0 and {options_count}.")
6363

6464

6565
def ask_yes_no(prompt: str) -> bool:
@@ -264,6 +264,8 @@ def run_interactive() -> int:
264264
textwrap.dedent(
265265
f"""
266266
What DNS settings would you like to modify?
267+
{BOLD}0. Exit.{RESET}
268+
Exit without applying any changes.
267269
{BOLD}1. Reset to defaults.{RESET}
268270
Uses the Unbound resolver with DNSSEC disabled.
269271
{BOLD}2. Configure DNS over HTTPS in Trivalent.{RESET}
@@ -291,6 +293,10 @@ def run_interactive() -> int:
291293

292294
exit_code = 1
293295
match mode:
296+
case 0:
297+
# Exit
298+
exit_code = 1
299+
294300
case 1:
295301
# Reset to defaults.
296302
exit_code = sandbox.run(dns_function, "reset")
@@ -557,7 +563,8 @@ def main() -> int:
557563
print("Invalid option selected. Try --help.", file=sys.stderr)
558564
return 1
559565

560-
print_all_status()
566+
if exit_code != 1:
567+
print_all_status()
561568
return exit_code
562569

563570

0 commit comments

Comments
 (0)