From d92d20a97ac8e65524ccbfd7487d9c8899948544 Mon Sep 17 00:00:00 2001 From: Steve Kowalik Date: Thu, 22 May 2025 15:29:56 +0200 Subject: [PATCH 1/3] 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 | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/SoftLayer/CLI/formatting.py b/SoftLayer/CLI/formatting.py index b9eca571e..b4c9a98f7 100644 --- a/SoftLayer/CLI/formatting.py +++ b/SoftLayer/CLI/formatting.py @@ -260,7 +260,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 From 3947b27f90ba556bde7dc73abd13802362f3b219 Mon Sep 17 00:00:00 2001 From: Christopher Gallo Date: Fri, 23 May 2025 09:21:58 +0530 Subject: [PATCH 2/3] Fixed tox errors --- SoftLayer/CLI/command.py | 5 +++++ SoftLayer/CLI/object_storage/credential/__init__.py | 2 ++ 2 files changed, 7 insertions(+) diff --git a/SoftLayer/CLI/command.py b/SoftLayer/CLI/command.py index b4cbd768c..34c50e549 100644 --- a/SoftLayer/CLI/command.py +++ b/SoftLayer/CLI/command.py @@ -73,6 +73,7 @@ def get_command(self, ctx, cmd_name): else: return module + # # pylint: disable=unused-argument def format_usage(self, ctx: click.Context, formatter: click.formatting.HelpFormatter) -> None: """Formats and colorizes the usage information.""" self.ensure_env(ctx) @@ -85,6 +86,7 @@ def format_usage(self, ctx: click.Context, formatter: click.formatting.HelpForma self.console.print(f"Usage: [path]{ctx.command_path}[/] {' '.join(pieces)}") + # pylint: disable=unused-argument def format_help_text(self, ctx: click.Context, formatter: click.formatting.HelpFormatter) -> None: """Writes the help text""" text = self.help if self.help is not None else "" @@ -104,6 +106,7 @@ def format_epilog(self, ctx: click.Context, formatter: click.formatting.HelpForm self.console.print(epilog) self.format_commands(ctx, formatter) + # pylint: disable=unused-argument def format_options(self, ctx, formatter): """Prints out the options in a table format""" @@ -136,7 +139,9 @@ def format_options(self, ctx, formatter): self.console.print(options_table) + # pylint: disable=unused-argument def format_commands(self, ctx, formatter): + """Formats the command list for click""" commands = [] for subcommand in self.list_commands(ctx): cmd = self.get_command(ctx, subcommand) diff --git a/SoftLayer/CLI/object_storage/credential/__init__.py b/SoftLayer/CLI/object_storage/credential/__init__.py index f3bc2723a..82bfef311 100644 --- a/SoftLayer/CLI/object_storage/credential/__init__.py +++ b/SoftLayer/CLI/object_storage/credential/__init__.py @@ -17,6 +17,7 @@ def __init__(self, **attrs): click.MultiCommand.__init__(self, **attrs) self.path = os.path.dirname(__file__) + # pylint: disable=unused-argument def list_commands(self, ctx): """List all sub-commands.""" commands = [] @@ -28,6 +29,7 @@ def list_commands(self, ctx): commands.sort() return commands + # pylint: disable=unused-argument def get_command(self, ctx, cmd_name): """Get command for click.""" path = "%s.%s" % (__name__, cmd_name) From bf8bf3b4ce299d6783e35efe328bfff1d7532b68 Mon Sep 17 00:00:00 2001 From: Steve Kowalik Date: Fri, 23 May 2025 12:33:51 +0200 Subject: [PATCH 3/3] 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