Fix expected incompatibilities in the CLI machinery with click 8.2.0
Marco Ricci

Marco Ricci commited on 2025-04-09 19:43:39
Zeige 1 geänderte Dateien mit 17 Einfügungen und 4 Löschungen.


click 8.2.0 is currently in pre-release, though a release candidate has
already been tagged as such. This candidate deprecated some internals,
which we access. Thus fix what we can reasonably assume will otherwise
be broken by click 8.2.0.
... ...
@@ -676,7 +676,7 @@ class CommandWithHelpGroups(click.Command):
676 676
         """Format the subcommands, if any.
677 677
 
678 678
         If called on a command object that isn't derived from
679
-        [`click.MultiCommand`][], then do nothing.
679
+        [`click.Group`][], then do nothing.
680 680
 
681 681
         Args:
682 682
             ctx:
... ...
@@ -685,7 +685,7 @@ class CommandWithHelpGroups(click.Command):
685 685
                 The formatter for the `--help` listing.
686 686
 
687 687
         """
688
-        if not isinstance(self, click.MultiCommand):
688
+        if not isinstance(self, click.Group):
689 689
             return
690 690
         commands: list[tuple[str, click.Command]] = []
691 691
         for subcommand in self.list_commands(ctx):
... ...
@@ -810,7 +810,20 @@ class DefaultToVaultGroup(CommandWithHelpGroups, click.Group):
810 810
         # resolve things like --help which now should go to the main
811 811
         # place.
812 812
         if cmd is None and not ctx.resilient_parsing:
813
-            if click.parser.split_opt(cmd_name)[0]:
813
+            ####
814
+            # BEGIN modifications for derivepassphrase
815
+            #
816
+            # Instead of using
817
+            #
818
+            #     if click.parsers.split_opt(cmd_name)[0]
819
+            #
820
+            # which splits the option prefix (typically `-` or `--`) from
821
+            # the option name, but triggers deprecation warnings in click
822
+            # 8.2.0 and later, we check directly for a `-` prefix.
823
+            #
824
+            # END modifications for derivepassphrase
825
+            ####
826
+            if cmd_name.startswith('-'):
814 827
                 self.parse_args(ctx, ctx.args)
815 828
             ####
816 829
             # BEGIN modifications for derivepassphrase
... ...
@@ -966,7 +979,7 @@ def common_version_output(
966 979
         pass
967 980
     else:
968 981
         major_dependencies.append(f'cryptography {cryptography_version}')
969
-    major_dependencies.append(f'click {click.__version__}')
982
+    major_dependencies.append(f'click {importlib.metadata.version("click")}')
970 983
 
971 984
     click.echo(
972 985
         ' '.join([
973 986