From bf8bf3b4ce299d6783e35efe328bfff1d7532b68 Mon Sep 17 00:00:00 2001 From: Steve Kowalik Date: Fri, 23 May 2025 12:33:51 +0200 Subject: [PATCH] Support Click 8.2+ Click 8.2 and above will now force an abort if a confirmation prompt isn't answered, rather than raising the CLIAbort that is expected. Catch this exception so that our own exceptions are raised. --- SoftLayer/CLI/formatting.py | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/SoftLayer/CLI/formatting.py b/SoftLayer/CLI/formatting.py index b9eca571e..2c0e324fe 100644 --- a/SoftLayer/CLI/formatting.py +++ b/SoftLayer/CLI/formatting.py @@ -243,7 +243,10 @@ def confirm(prompt_str, default=False): default_str = 'n' prompt = '%s [y/N]' % prompt_str - ans = click.prompt(prompt, default=default_str, show_default=False) + try: + ans = click.prompt(prompt, default=default_str, show_default=False) + except click.exceptions.Abort: + return False if ans.lower() in ('y', 'yes', 'yeah', 'yup', 'yolo'): return True @@ -260,7 +263,10 @@ def no_going_back(confirmation): prompt = f"This action cannot be undone! Type '{confirmation}' or press Enter to abort" - ans = click.prompt(prompt, default='', show_default=False) + try: + ans = click.prompt(prompt, default='', show_default=False) + except click.exceptions.Abort: + return False if ans.lower() == str(confirmation).lower(): return True