Safely index modes

This commit is contained in:
Luke
2020-06-11 20:53:02 +12:00
parent bf3588e516
commit 7e9c78605b
14 changed files with 328 additions and 15 deletions

View File

@@ -37,8 +37,8 @@ impl Config {
.unwrap_or_else(|_| panic!("Could not deserialise {}", CONFIG_PATH));
self = c;
} else {
self =
toml::from_str(&buf).expect(&format!("Could not deserialise {}", CONFIG_PATH));
self = toml::from_str(&buf)
.unwrap_or_else(|_| panic!("Could not deserialise {}", CONFIG_PATH));
}
}
self

View File

@@ -238,14 +238,17 @@ where
#[inline]
async fn set_builtin(&self, config: &mut Config, index: usize) -> Result<(), AuraError> {
let mode_next = config
.builtin_modes
.get_field_from(self.supported_modes[index].into())
.ok_or(AuraError::NotSupported)?
.to_owned();
println!("{:X?}", &mode_next);
self.set_and_save(&mode_next, config).await?;
info!("Switched LED mode to {:#?}", self.supported_modes[index]);
Ok(())
if let Some(mode) = self.supported_modes.get(index) {
let mode_next = config
.builtin_modes
.get_field_from(mode.to_owned().into())
.ok_or(AuraError::NotSupported)?
.to_owned();
println!("{:X?}", &mode_next);
self.set_and_save(&mode_next, config).await?;
info!("Switched LED mode to {:#?}", self.supported_modes[index]);
return Ok(());
}
Err(AuraError::NotSupported)
}
}

View File

@@ -8,7 +8,7 @@ use rog_client::{
AuraDbusWriter, LED_MSG_LEN,
};
static VERSION: &str = "0.11.0";
static VERSION: &str = "0.11.1";
#[derive(Debug, Options)]
struct CLIStart {