Parse command line arguments into kwargs. Simple argument parser that handles: - Flags: --flag or -f - Options: --option value - Positional args (if command expects them)
(command: Any, args: list[str])
| 192 | |
| 193 | @staticmethod |
| 194 | def _parse_arguments(command: Any, args: list[str]) -> dict[str, Any]: |
| 195 | """ |
| 196 | Parse command line arguments into kwargs. |
| 197 | |
| 198 | Simple argument parser that handles: |
| 199 | - Flags: --flag or -f |
| 200 | - Options: --option value |
| 201 | - Positional args (if command expects them) |
| 202 | """ |
| 203 | kwargs: dict[str, Any] = {} |
| 204 | i = 0 |
| 205 | |
| 206 | while i < len(args): |
| 207 | arg = args[i] |
| 208 | |
| 209 | if arg.startswith("--"): |
| 210 | # Long option |
| 211 | option_name = arg[2:] |
| 212 | |
| 213 | # Check if this is a flag |
| 214 | param = next( |
| 215 | (p for p in command.parameters if p.name == option_name), None |
| 216 | ) |
| 217 | |
| 218 | if param and param.is_flag: |
| 219 | kwargs[option_name] = True |
| 220 | elif i + 1 < len(args) and not args[i + 1].startswith("-"): |
| 221 | # Has a value |
| 222 | kwargs[option_name] = args[i + 1] |
| 223 | i += 1 |
| 224 | else: |
| 225 | # No value, treat as flag |
| 226 | kwargs[option_name] = True |
| 227 | |
| 228 | elif arg.startswith("-") and len(arg) == 2: |
| 229 | # Short option (single letter) |
| 230 | # For now, treat as flag |
| 231 | kwargs[arg[1:]] = True |
| 232 | |
| 233 | else: |
| 234 | # Positional argument |
| 235 | # For now, add to a list of positional args |
| 236 | if "args" not in kwargs: |
| 237 | kwargs["args"] = [] |
| 238 | kwargs["args"].append(arg) |
| 239 | |
| 240 | i += 1 |
| 241 | |
| 242 | return kwargs |
| 243 | |
| 244 | @staticmethod |
| 245 | def get_completions(partial_text: str) -> list[str]: |
no outgoing calls