Compare commits
5 Commits
15593204e0
...
277f638c60
| Author | SHA1 | Date | |
|---|---|---|---|
| 277f638c60 | |||
| 626973d2bc | |||
| 28539f54cc | |||
| 5ce20adf2e | |||
| fc1e20185e |
@@ -36,6 +36,34 @@ struct PartialConfig {
|
||||
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 {
|
||||
type Error = crate::config::Error;
|
||||
|
||||
fn try_from(value: &Table) -> Result<Self> {
|
||||
Ok(Self {
|
||||
// can't get table name because that key is gone by this point.
|
||||
project_path: None,
|
||||
gitea_url: get_maybe_property(&value, "gitea_url")?.cloned(),
|
||||
owner: get_maybe_property(&value, "owner")?.cloned(),
|
||||
repo: get_maybe_property(&value, "repo")?.cloned(),
|
||||
token: get_maybe_property(&value, "token")?.cloned(),
|
||||
})
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
#[derive(Debug, Default)]
|
||||
#[cfg_attr(test, derive(PartialEq))]
|
||||
struct WholeFile {
|
||||
@@ -54,15 +82,23 @@ fn lconf(text: &str) -> Result<WholeFile> {
|
||||
let cfg_table = toml_val.as_table().ok_or(Error::BadFormat)?;
|
||||
|
||||
// Get the global config out of the file
|
||||
if let Some(section_all) = cfg_table.get("all") {
|
||||
if let Some(table_all) = section_all.as_table() {
|
||||
whole.all.gitea_url = get_maybe_property(&table_all, "gitea_url")?.cloned();
|
||||
whole.all.owner = get_maybe_property(&table_all, "owner")?.cloned();
|
||||
whole.all.repo = get_maybe_property(&table_all, "repo")?.cloned();
|
||||
whole.all.token = get_maybe_property(&table_all, "token")?.cloned();
|
||||
}
|
||||
}
|
||||
let table_all = get_table(cfg_table, "all")?;
|
||||
whole.all = PartialConfig::try_from(table_all)?;
|
||||
|
||||
// Loop over the per-project configs, if any.
|
||||
let per_project_keys = cfg_table
|
||||
.keys()
|
||||
.filter(|s| { // Discard the "[all]" table
|
||||
*s != "all"
|
||||
});
|
||||
|
||||
for path in per_project_keys {
|
||||
let tab = get_table(cfg_table, path)?;
|
||||
let part_cfg = PartialConfig::try_from(tab)?
|
||||
.project_path(path.clone());
|
||||
whole.project_overrides.push(part_cfg);
|
||||
}
|
||||
println!(" ->> lconf - keys {:?}", cfg_table.keys().collect::<Vec<&String>>());
|
||||
Ok(whole)
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user