//
// Wildland Project
//
// Copyright © 2022 Golem Foundation
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License version 3 as published by
// the Free Software Foundation.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program. If not, see <https://www.gnu.org/licenses/>.
use std::path::PathBuf;
use anyhow::Context as _;
use wildland_cargo_lib::api::config::parse_config;
pub use wildland_cargo_lib::api::CargoConfig;
#[tracing::instrument(level = "trace" err(Debug))]
pub fn load_json_config_from_file(config_path: &str) -> anyhow::Result<CargoConfig> {
let config_path = PathBuf::from(config_path);
if !config_path.exists() {
return Err(anyhow::anyhow!("Config file does not exist"));
}
if !config_path.is_file() {
return Err(anyhow::anyhow!("Config path is not a file"));
}
let config = std::fs::read_to_string(config_path)?;
parse_config(config.as_bytes().to_vec()).context("Error parsing config")
}