Configuration for Unity CLI Client. Attributes: relay_host: Relay server hostname or IP address. relay_port: Relay server port (1-65535). timeout: TCP socket timeout in seconds (for connect/read operations). timeout_ms: Unity command timeout in milliseconds (for
| 33 | |
| 34 | |
| 35 | class UnityCLIConfig(BaseModel): |
| 36 | """Configuration for Unity CLI Client. |
| 37 | |
| 38 | Attributes: |
| 39 | relay_host: Relay server hostname or IP address. |
| 40 | relay_port: Relay server port (1-65535). |
| 41 | timeout: TCP socket timeout in seconds (for connect/read operations). |
| 42 | timeout_ms: Unity command timeout in milliseconds (for command execution). |
| 43 | instance: Target Unity instance path (optional). |
| 44 | retry_initial_ms: Initial retry backoff interval in milliseconds. |
| 45 | retry_max_ms: Maximum retry backoff interval in milliseconds. |
| 46 | retry_max_time_ms: Maximum total retry time in milliseconds. |
| 47 | |
| 48 | Note: |
| 49 | `timeout` and `timeout_ms` serve different purposes: |
| 50 | - `timeout`: Low-level socket operation timeout (seconds) |
| 51 | - `timeout_ms`: High-level Unity command execution timeout (milliseconds) |
| 52 | """ |
| 53 | |
| 54 | model_config = ConfigDict( |
| 55 | validate_assignment=True, |
| 56 | frozen=False, |
| 57 | extra="ignore", |
| 58 | ) |
| 59 | |
| 60 | relay_host: str = DEFAULT_RELAY_HOST |
| 61 | relay_port: Annotated[int, Field(gt=0, le=65535)] = DEFAULT_RELAY_PORT |
| 62 | timeout: Annotated[float, Field(gt=0)] = 15.0 |
| 63 | timeout_ms: Annotated[int, Field(gt=0)] = DEFAULT_TIMEOUT_MS |
| 64 | instance: str | None = None |
| 65 | retry_initial_ms: Annotated[int, Field(gt=0)] = 500 |
| 66 | retry_max_ms: Annotated[int, Field(gt=0)] = 8000 |
| 67 | retry_max_time_ms: Annotated[int, Field(gt=0)] = 45000 |
| 68 | |
| 69 | @classmethod |
| 70 | def load(cls, config_path: Path | None = None) -> Self: |
| 71 | """Load configuration from TOML file. |
| 72 | |
| 73 | Args: |
| 74 | config_path: Path to TOML config file. If None, searches for |
| 75 | .unity-cli.toml in current directory or Unity project root. |
| 76 | |
| 77 | Returns: |
| 78 | UnityCLIConfig instance with loaded or default values. |
| 79 | """ |
| 80 | toml_path = config_path if config_path and config_path.exists() else cls._find_config_file() |
| 81 | |
| 82 | if toml_path: |
| 83 | try: |
| 84 | with open(toml_path, "rb") as f: |
| 85 | data = tomllib.load(f) |
| 86 | return cls.model_validate(data) |
| 87 | except (tomllib.TOMLDecodeError, OSError): |
| 88 | pass |
| 89 | |
| 90 | return cls() |
| 91 | |
| 92 | @classmethod |