|
29 | 29 | _logger: Final = logging.getLogger("salad") |
30 | 30 |
|
31 | 31 |
|
| 32 | +def parse_kv(pair: str) -> tuple[str, str]: |
| 33 | + """Parse `key=value` arguments into a tuple of `key` and `value`.""" |
| 34 | + try: |
| 35 | + k, v = pair.split("=", 1) |
| 36 | + return k, v |
| 37 | + except ValueError as e: |
| 38 | + raise argparse.ArgumentTypeError(f"Invalid format: '{pair}', expected key=value") from e |
| 39 | + |
| 40 | + |
32 | 41 | def printrdf( |
33 | 42 | workflow: str, |
34 | 43 | wf: CommentedMap | CommentedSeq, |
@@ -147,6 +156,15 @@ def arg_parser() -> argparse.ArgumentParser: |
147 | 156 | "from the base URL (Java/TypeScript/.Net/Dlang only).", |
148 | 157 | ) |
149 | 158 |
|
| 159 | + codegen_opts.add_argument( |
| 160 | + "--codegen-parent", |
| 161 | + type=parse_kv, |
| 162 | + metavar="PARENTS_MAP", |
| 163 | + action="append", |
| 164 | + default=None, |
| 165 | + help="Optional mapping of prefix into parent package for generated classes (Python only).", |
| 166 | + ) |
| 167 | + |
150 | 168 | codegen_opts.add_argument( |
151 | 169 | "--codegen-copyright", |
152 | 170 | type=str, |
@@ -351,6 +369,7 @@ def main(argsl: list[str] | None = None) -> int: |
351 | 369 | examples=args.codegen_examples, |
352 | 370 | package=args.codegen_package, |
353 | 371 | copyright=args.codegen_copyright, |
| 372 | + parents_map=dict(args.codegen_parent or []), |
354 | 373 | spdx_license_identifier=args.codegen_spdx_license_identifier, |
355 | 374 | spdx_copyright_text=args.codegen_spdx_copyright_text, |
356 | 375 | parser_info=args.codegen_parser_info, |
|
0 commit comments