-
-
Notifications
You must be signed in to change notification settings - Fork 82
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* read bacon.toml in `workspace/.config/` and `package/.config`. * read config embedded in Cargo.toml Fix #268 Fix #241
- Loading branch information
Showing
7 changed files
with
120 additions
and
51 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
use { | ||
super::Config, | ||
anyhow::*, | ||
serde::Deserialize, | ||
std::path::Path, | ||
}; | ||
|
||
#[derive(Deserialize)] | ||
struct CargoWrappedConfig { | ||
workspace: Option<WrappedMetadata>, | ||
package: Option<WrappedMetadata>, | ||
} | ||
#[derive(Deserialize)] | ||
struct WrappedMetadata { | ||
metadata: Option<WrappedConfig>, | ||
} | ||
#[derive(Deserialize)] | ||
struct WrappedConfig { | ||
bacon: Option<Config>, | ||
} | ||
|
||
pub fn load_config_from_cargo_toml(cargo_file_path: &Path) -> Result<Vec<Config>> { | ||
if !cargo_file_path.exists() { | ||
return Ok(Vec::default()); | ||
} | ||
let cargo_toml = std::fs::read_to_string(cargo_file_path)?; | ||
let mut cargo: CargoWrappedConfig = toml::from_str(&cargo_toml)?; | ||
let mut configs = Vec::new(); | ||
let worskpace_config = cargo | ||
.workspace | ||
.take() | ||
.and_then(|workspace| workspace.metadata) | ||
.and_then(|metadata| metadata.bacon); | ||
if let Some(config) = worskpace_config { | ||
configs.push(config); | ||
} | ||
let worskpace_config = cargo | ||
.package | ||
.take() | ||
.and_then(|package| package.metadata) | ||
.and_then(|metadata| metadata.bacon); | ||
if let Some(config) = worskpace_config { | ||
configs.push(config); | ||
} | ||
Ok(configs) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters