Parse a list of ['--key', 'value', ...] into a dict.
(extra: list[str])
| 119 | |
| 120 | |
| 121 | def _parse_extra_args(extra: list[str]) -> dict[str, str]: |
| 122 | """Parse a list of ['--key', 'value', ...] into a dict.""" |
| 123 | kwargs = {} |
| 124 | i = 0 |
| 125 | while i < len(extra): |
| 126 | arg = extra[i] |
| 127 | if arg.startswith("--"): |
| 128 | key = arg[2:] |
| 129 | if i + 1 < len(extra) and not extra[i + 1].startswith("--"): |
| 130 | kwargs[key] = extra[i + 1] |
| 131 | i += 2 |
| 132 | else: |
| 133 | # Flag without value — treat as "true" |
| 134 | kwargs[key] = "true" |
| 135 | i += 1 |
| 136 | else: |
| 137 | print(f"Error: Unexpected argument: {arg}", file=sys.stderr) |
| 138 | sys.exit(1) |
| 139 | return kwargs |
| 140 | |
| 141 | |
| 142 | def cmd_foreach(args, extra_args): |
no test coverage detected