Skip to content

Commit

Permalink
fix: interpret unnamed .config script files as kconfig files (fixes #6)
Browse files Browse the repository at this point in the history
  • Loading branch information
oddlama committed Mar 2, 2023
1 parent ade4b7b commit e1aaf0b
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions src/script/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,19 +13,21 @@ pub trait Script {
fn apply(&self, bridge: &Bridge) -> Result<()>;
}

/// Loads the given script file by instanciating
/// the correct implementation and applys it
/// Loads the given script file by instanciating the correct implementation
pub fn load(path: impl AsRef<Path>) -> Result<Box<dyn Script>> {
let ext = path
.as_ref()
.extension()
// If no extension is found, interpret the file name as extension.
// Happens for files beginning with a . like .config
.or_else(|| path.as_ref().file_name())
.expect("Missing file extension")
.to_str()
.unwrap();

Ok(match ext {
"lua" => Box::new(LuaScript::new(path)?),
"txt" | "config" => Box::new(KConfig::new(path)?),
"txt" | "config" | ".config" => Box::new(KConfig::new(path)?),
_ => bail!(format!("Unknown script type {ext}")),
})
}
Expand Down

0 comments on commit e1aaf0b

Please sign in to comment.