Parse [`RawConfig`] from a TOML file at the given path, returning `None` if the file does not exist. NOTE**: Comments and formatting in the file will be preserved.
(path: &Path)
| 612 | /// |
| 613 | /// **NOTE**: Comments and formatting in the file will be preserved. |
| 614 | fn parse_config(path: &Path) -> anyhow::Result<Option<(toml_edit::DocumentMut, RawConfig)>> { |
| 615 | match std::fs::read_to_string(path) { |
| 616 | Ok(contents) => { |
| 617 | let doc = contents.parse::<toml_edit::DocumentMut>()?; |
| 618 | let config = RawConfig::try_from(&doc)?; |
| 619 | Ok(Some((doc, config))) |
| 620 | } |
| 621 | Err(e) if e.kind() == io::ErrorKind::NotFound => Ok(None), |
| 622 | Err(e) => Err(e.into()), |
| 623 | } |
| 624 | } |
| 625 | |
| 626 | pub fn load(home_path: CliTomlPath) -> anyhow::Result<Self> { |
| 627 | let home = Self::parse_config(home_path.as_ref()) |