Load remote configuration from a config file. This reads the TOML configuration file and extracts the `[remotes]` section. If the file doesn't exist or has no remotes section, returns an empty configuration. # Arguments `path` - Path to the config file (typically `.atomic/config.toml`) # Errors Returns an error if the file exists but cannot be read or parsed.
(path: P)
| 274 | /// |
| 275 | /// Returns an error if the file exists but cannot be read or parsed. |
| 276 | pub fn load<P: AsRef<Path>>(path: P) -> RemoteResult<Self> { |
| 277 | let path = path.as_ref(); |
| 278 | |
| 279 | // If file doesn't exist, return empty config |
| 280 | if !path.exists() { |
| 281 | return Ok(Self::new()); |
| 282 | } |
| 283 | |
| 284 | let content = std::fs::read_to_string(path).map_err(|e| RemoteError::ReadError { |
| 285 | path: path.display().to_string(), |
| 286 | source: e, |
| 287 | })?; |
| 288 | |
| 289 | Self::parse(&content, path) |
| 290 | } |
| 291 | |
| 292 | /// Parse remote configuration from TOML content. |
| 293 | fn parse(content: &str, path: &Path) -> RemoteResult<Self> { |