Add a builder-pattern proj-path setter, for flavor
I like being able to chain methods instead of using a temporary variable in between, so I've made one single function like I'm doing the builder pattern. But not really because there's nothing to build or finalize and such.
This commit is contained in:
@@ -36,6 +36,18 @@ struct PartialConfig {
|
|||||||
token: Option<String>,
|
token: Option<String>,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl PartialConfig {
|
||||||
|
// One lonely builder-pattern function to set the project path.
|
||||||
|
// This is so I can do continuation style calls instead of a bunch of
|
||||||
|
// successive `let conf = ...` temporaries.
|
||||||
|
fn project_path(self, path: impl ToString) -> Self{
|
||||||
|
PartialConfig {
|
||||||
|
project_path: Some(path.to_string()),
|
||||||
|
..self
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
impl TryFrom<&Table> for PartialConfig {
|
impl TryFrom<&Table> for PartialConfig {
|
||||||
type Error = crate::config::Error;
|
type Error = crate::config::Error;
|
||||||
|
|
||||||
@@ -82,11 +94,8 @@ fn lconf(text: &str) -> Result<WholeFile> {
|
|||||||
|
|
||||||
for path in per_project_keys {
|
for path in per_project_keys {
|
||||||
let tab = get_table(cfg_table, path)?;
|
let tab = get_table(cfg_table, path)?;
|
||||||
let part_cfg = PartialConfig::try_from(tab)?;
|
let part_cfg = PartialConfig::try_from(tab)?
|
||||||
let part_cfg = PartialConfig {
|
.project_path(path.clone());
|
||||||
project_path: Some(path.clone()),
|
|
||||||
..part_cfg
|
|
||||||
};
|
|
||||||
whole.project_overrides.push(part_cfg);
|
whole.project_overrides.push(part_cfg);
|
||||||
}
|
}
|
||||||
println!(" ->> lconf - keys {:?}", cfg_table.keys().collect::<Vec<&String>>());
|
println!(" ->> lconf - keys {:?}", cfg_table.keys().collect::<Vec<&String>>());
|
||||||
|
|||||||
Reference in New Issue
Block a user