Parse CLI URL into host and port. Supports formats: "host:port", "http://host:port", "https://host:port", or just "port". Args: url: The CLI URL to parse. Returns: A tuple of (host, port). Raises: ValueError: If
(self, url: str)
| 1291 | return self._runtime_port |
| 1292 | |
| 1293 | def _parse_cli_url(self, url: str) -> tuple[str, int]: |
| 1294 | """ |
| 1295 | Parse CLI URL into host and port. |
| 1296 | |
| 1297 | Supports formats: "host:port", "http://host:port", "https://host:port", |
| 1298 | or just "port". |
| 1299 | |
| 1300 | Args: |
| 1301 | url: The CLI URL to parse. |
| 1302 | |
| 1303 | Returns: |
| 1304 | A tuple of (host, port). |
| 1305 | |
| 1306 | Raises: |
| 1307 | ValueError: If the URL format is invalid or the port is out of range. |
| 1308 | """ |
| 1309 | import re |
| 1310 | |
| 1311 | # Remove protocol if present |
| 1312 | clean_url = re.sub(r"^https?://", "", url) |
| 1313 | |
| 1314 | # Check if it's just a port number |
| 1315 | if clean_url.isdigit(): |
| 1316 | port = int(clean_url) |
| 1317 | if port <= 0 or port > 65535: |
| 1318 | raise ValueError(f"Invalid port in cli_url: {url}") |
| 1319 | return ("localhost", port) |
| 1320 | |
| 1321 | # Parse host:port format |
| 1322 | parts = clean_url.split(":") |
| 1323 | if len(parts) != 2: |
| 1324 | raise ValueError(f"Invalid cli_url format: {url}") |
| 1325 | |
| 1326 | host = parts[0] if parts[0] else "localhost" |
| 1327 | try: |
| 1328 | port = int(parts[1]) |
| 1329 | except ValueError as e: |
| 1330 | raise ValueError(f"Invalid port in cli_url: {url}") from e |
| 1331 | |
| 1332 | if port <= 0 or port > 65535: |
| 1333 | raise ValueError(f"Invalid port in cli_url: {url}") |
| 1334 | |
| 1335 | return (host, port) |
| 1336 | |
| 1337 | async def __aenter__(self) -> CopilotClient: |
| 1338 | """ |