Skip to content

Commit

Permalink
Add support for specifying compatibility flags in config file
Browse files Browse the repository at this point in the history
  • Loading branch information
simu committed Jan 23, 2024
1 parent 3a6d26c commit 6a32cdd
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 3 deletions.
27 changes: 27 additions & 0 deletions src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,18 @@ impl CompatFlag {
}
}

impl TryFrom<&str> for CompatFlag {
type Error = anyhow::Error;
fn try_from(value: &str) -> Result<Self> {
match value {
"compose-node-name-literal-dots"
| "compose_node_name_literal_dots"
| "ComposeNodeNameLiteralDots" => Ok(Self::ComposeNodeNameLiteralDots),
_ => Err(anyhow!("Unknown compatibility flag '{value}'")),
}
}
}

#[pyclass]
#[derive(Clone, Debug, Default)]
pub struct Config {
Expand Down Expand Up @@ -143,6 +155,21 @@ impl Config {
"Expected value of config key 'compose_node_name' to be a boolean"
))?;
}
"reclass_rs_compat_flags" => {
let flags = v.as_sequence().ok_or(anyhow!(
"Expected value of config key 'reclass_rs_compat_flags' to be a list"
))?;
for f in flags {
let f = f
.as_str()
.ok_or(anyhow!("Expected compatibility flag to be a string"))?;
if let Ok(flag) = CompatFlag::try_from(f) {
self.compatflags.insert(flag);
} else {
eprintln!("Unknown compatibility flag '{f}', ignoring...");
}
}
}
_ => {
eprintln!(
"reclass-config.yml entry '{kstr}={vstr}' not implemented yet, ignoring..."
Expand Down
4 changes: 1 addition & 3 deletions src/inventory.rs
Original file line number Diff line number Diff line change
Expand Up @@ -217,9 +217,7 @@ mod inventory_tests {
None,
)
.unwrap();
c.load_from_file("reclass-config.yml").unwrap();
c.compatflags
.insert(crate::config::CompatFlag::ComposeNodeNameLiteralDots);
c.load_from_file("reclass-config-compat.yml").unwrap();
let r = Reclass::new_from_config(c).unwrap();
let invabsdir = std::fs::canonicalize("./tests/inventory-compose-node-name").unwrap();
let invabsdir = invabsdir.to_str().unwrap();
Expand Down

0 comments on commit 6a32cdd

Please sign in to comment.