Validate and parse command line arguments. Args: args: Command line arguments including script name Returns: Tuple of (sync_port, working_directory, target_args) Raises: ArgumentError: If arguments are invalid
(args: List[str])
| 36 | |
| 37 | |
| 38 | def _validate_arguments(args: List[str]) -> tuple[int, str, List[str]]: |
| 39 | """ |
| 40 | Validate and parse command line arguments. |
| 41 | |
| 42 | Args: |
| 43 | args: Command line arguments including script name |
| 44 | |
| 45 | Returns: |
| 46 | Tuple of (sync_port, working_directory, target_args) |
| 47 | |
| 48 | Raises: |
| 49 | ArgumentError: If arguments are invalid |
| 50 | """ |
| 51 | if len(args) < 4: |
| 52 | raise ArgumentError( |
| 53 | "Insufficient arguments. Expected: <sync_port> <cwd> <target> [args...]" |
| 54 | ) |
| 55 | |
| 56 | try: |
| 57 | sync_port = int(args[1]) |
| 58 | if not (1 <= sync_port <= 65535): |
| 59 | raise ValueError("Port out of range") |
| 60 | except ValueError as e: |
| 61 | raise ArgumentError(f"Invalid sync port '{args[1]}': {e}") from e |
| 62 | |
| 63 | cwd = args[2] |
| 64 | if not os.path.isdir(cwd): |
| 65 | raise ArgumentError(f"Working directory does not exist: {cwd}") |
| 66 | |
| 67 | target_args = args[3:] |
| 68 | if not target_args: |
| 69 | raise ArgumentError("No target specified") |
| 70 | |
| 71 | return sync_port, cwd, target_args |
| 72 | |
| 73 | |
| 74 | # Constants for socket communication |
no test coverage detected
searching dependent graphs…