Improved getters/setters config client

This commit is contained in:
veeso
2021-01-23 16:21:30 +01:00
parent b3c4385617
commit c16a2f6441

View File

@@ -165,26 +165,19 @@ impl ConfigClient {
/// ### get_file_fmt /// ### get_file_fmt
/// ///
/// Get current file fmt; if none return "" /// Get current file fmt
pub fn get_file_fmt(&self) -> String { pub fn get_file_fmt(&self) -> Option<String> {
match &self.config.user_interface.file_fmt { self.config.user_interface.file_fmt.clone()
None => String::new(),
Some(s) => s.clone(),
}
} }
/// ### set_file_fmt /// ### set_file_fmt
/// ///
/// Set file fmt parameter /// Set file fmt parameter
pub fn set_file_fmt(&mut self, s: String) { pub fn set_file_fmt(&mut self, s: String) {
self.config.user_interface.file_fmt = Some(s); self.config.user_interface.file_fmt = match s.is_empty() {
} true => None,
false => Some(s),
/// ### del_file_fmt };
///
/// Delete file fmt parameter
pub fn del_file_fmt(&mut self) {
self.config.user_interface.file_fmt = None;
} }
// SSH Keys // SSH Keys
@@ -482,12 +475,12 @@ mod tests {
let mut client: ConfigClient = ConfigClient::new(cfg_path.as_path(), key_path.as_path()) let mut client: ConfigClient = ConfigClient::new(cfg_path.as_path(), key_path.as_path())
.ok() .ok()
.unwrap(); .unwrap();
assert_eq!(client.get_file_fmt(), String::from("")); assert_eq!(client.get_file_fmt(), None);
client.set_file_fmt(String::from("{NAME}")); client.set_file_fmt(String::from("{NAME}"));
assert_eq!(client.get_file_fmt(), String::from("{NAME}")); assert_eq!(client.get_file_fmt().unwrap(), String::from("{NAME}"));
// Delete // Delete
client.del_file_fmt(); client.set_file_fmt(String::from(""));
assert_eq!(client.get_file_fmt(), String::from("")); assert_eq!(client.get_file_fmt(), None);
} }
#[test] #[test]