From b3c4385617e050e17e983352a49ca155d9ed062c Mon Sep 17 00:00:00 2001 From: veeso Date: Sat, 23 Jan 2021 16:09:13 +0100 Subject: [PATCH] Added to ConfigClient getters/setters for file_fmt --- src/system/config_client.rs | 39 +++++++++++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) diff --git a/src/system/config_client.rs b/src/system/config_client.rs index 50a1061..78abb1f 100644 --- a/src/system/config_client.rs +++ b/src/system/config_client.rs @@ -163,6 +163,30 @@ impl ConfigClient { }; } + /// ### get_file_fmt + /// + /// Get current file fmt; if none return "" + pub fn get_file_fmt(&self) -> String { + match &self.config.user_interface.file_fmt { + None => String::new(), + Some(s) => s.clone(), + } + } + + /// ### set_file_fmt + /// + /// Set file fmt parameter + pub fn set_file_fmt(&mut self, s: String) { + self.config.user_interface.file_fmt = 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 /// ### save_ssh_key @@ -451,6 +475,21 @@ mod tests { assert_eq!(client.get_group_dirs(), None,); } + #[test] + fn test_system_config_file_fmt() { + let tmp_dir: tempfile::TempDir = create_tmp_dir(); + let (cfg_path, key_path): (PathBuf, PathBuf) = get_paths(tmp_dir.path()); + let mut client: ConfigClient = ConfigClient::new(cfg_path.as_path(), key_path.as_path()) + .ok() + .unwrap(); + assert_eq!(client.get_file_fmt(), String::from("")); + client.set_file_fmt(String::from("{NAME}")); + assert_eq!(client.get_file_fmt(), String::from("{NAME}")); + // Delete + client.del_file_fmt(); + assert_eq!(client.get_file_fmt(), String::from("")); + } + #[test] fn test_system_config_ssh_keys() { let tmp_dir: tempfile::TempDir = create_tmp_dir();