|
23 | 23 | from .emulate_efuse_controller_base import EmulateEfuseControllerBase
|
24 | 24 |
|
25 | 25 |
|
26 |
| -class EfuseValuePairArg(click.Argument): |
| 26 | +class EfuseArgument(click.Argument): |
| 27 | + def make_metavar(self, ctx: click.Context | None = None) -> str: |
| 28 | + """Compatibility layer for Click 8.2.0+; which now requires a ctx parameter.""" |
| 29 | + try: |
| 30 | + return super().make_metavar(ctx) # type: ignore |
| 31 | + except TypeError: |
| 32 | + # Fall back to the old signature (pre-Click 8.2.0) |
| 33 | + return super().make_metavar() # type: ignore |
| 34 | + |
| 35 | + |
| 36 | +class EfuseValuePairArg(EfuseArgument): |
27 | 37 | def __init__(self, *args, **kwargs):
|
28 | 38 | super().__init__(*args, **kwargs)
|
29 | 39 |
|
30 |
| - def make_metavar(self) -> str: |
31 |
| - return f"[{super().make_metavar()}] ..." |
| 40 | + def make_metavar(self, ctx=None) -> str: |
| 41 | + return f"[{super().make_metavar(ctx)}] ..." |
32 | 42 |
|
33 | 43 | def type_cast_value(self, ctx: click.Context, value: list[str]):
|
34 | 44 | return self.type.convert(value, None, ctx)
|
@@ -84,17 +94,17 @@ def convert(self, value: str, param: click.Parameter | None, ctx: click.Context)
|
84 | 94 | return base_fields.CheckArgValue(ctx.obj["efuses"], "CUSTOM_MAC")(value)
|
85 | 95 |
|
86 | 96 |
|
87 |
| -class TupleParameter(click.Argument): |
| 97 | +class TupleParameter(EfuseArgument): |
88 | 98 | def __init__(self, *args, **kwargs):
|
89 | 99 | self.max_arity = kwargs.pop("max_arity", None)
|
90 | 100 | super().__init__(*args, **kwargs)
|
91 | 101 |
|
92 |
| - def make_metavar(self) -> str: |
| 102 | + def make_metavar(self, ctx=None) -> str: |
93 | 103 | if self.nargs == 1:
|
94 |
| - return super().make_metavar() # type: ignore |
| 104 | + return super().make_metavar(ctx) # type: ignore |
95 | 105 | if self.max_arity is None:
|
96 |
| - return f"[{super().make_metavar()}] ..." |
97 |
| - return f"[{super().make_metavar()}] ... (max {self.max_arity} groups)" |
| 106 | + return f"[{super().make_metavar(ctx)}] ..." |
| 107 | + return f"[{super().make_metavar(ctx)}] ... (max {self.max_arity} groups)" |
98 | 108 |
|
99 | 109 | def type_cast_value(self, ctx: click.Context, value: list[str]) -> tuple[Any, ...]:
|
100 | 110 | # This is by default eating all options, so we need to check for help option
|
|
0 commit comments