diff --git a/src/config/mod.rs b/src/config/mod.rs index 2225d2a..af62155 100644 --- a/src/config/mod.rs +++ b/src/config/mod.rs @@ -55,6 +55,7 @@ pub struct UserInterfaceConfig { pub text_editor: PathBuf, pub default_protocol: String, pub show_hidden_files: bool, + pub check_for_updates: Option, // @! Since 0.3.3 pub group_dirs: Option, pub file_fmt: Option, } @@ -85,6 +86,7 @@ impl Default for UserInterfaceConfig { }, default_protocol: FileTransferProtocol::Sftp.to_string(), show_hidden_files: false, + check_for_updates: Some(true), group_dirs: None, file_fmt: None, } @@ -172,6 +174,7 @@ mod tests { default_protocol: String::from("SFTP"), text_editor: PathBuf::from("nano"), show_hidden_files: true, + check_for_updates: Some(true), group_dirs: Some(String::from("first")), file_fmt: Some(String::from("{NAME}")), }; @@ -189,6 +192,7 @@ mod tests { assert_eq!(cfg.user_interface.default_protocol, String::from("SFTP")); assert_eq!(cfg.user_interface.text_editor, PathBuf::from("nano")); assert_eq!(cfg.user_interface.show_hidden_files, true); + assert_eq!(cfg.user_interface.check_for_updates, Some(true)); assert_eq!(cfg.user_interface.group_dirs, Some(String::from("first"))); assert_eq!(cfg.user_interface.file_fmt, Some(String::from("{NAME}"))); } @@ -201,6 +205,7 @@ mod tests { let cfg: UserConfig = UserConfig::default(); assert_eq!(cfg.user_interface.default_protocol, String::from("SFTP")); assert_eq!(cfg.user_interface.text_editor, PathBuf::from("vim")); + assert_eq!(cfg.user_interface.check_for_updates.unwrap(), true); assert_eq!(cfg.remote.ssh_keys.len(), 0); } diff --git a/src/config/serializer.rs b/src/config/serializer.rs index 544b594..fd927c6 100644 --- a/src/config/serializer.rs +++ b/src/config/serializer.rs @@ -107,8 +107,12 @@ mod tests { assert_eq!(cfg.user_interface.default_protocol, String::from("SCP")); assert_eq!(cfg.user_interface.text_editor, PathBuf::from("vim")); assert_eq!(cfg.user_interface.show_hidden_files, true); + assert_eq!(cfg.user_interface.check_for_updates.unwrap(), true); assert_eq!(cfg.user_interface.group_dirs, Some(String::from("last"))); - assert_eq!(cfg.user_interface.file_fmt, Some(String::from("{NAME} {PEX}"))); + assert_eq!( + cfg.user_interface.file_fmt, + Some(String::from("{NAME} {PEX}")) + ); // Verify keys assert_eq!( *cfg.remote @@ -144,6 +148,7 @@ mod tests { assert_eq!(cfg.user_interface.text_editor, PathBuf::from("vim")); assert_eq!(cfg.user_interface.show_hidden_files, true); assert_eq!(cfg.user_interface.group_dirs, None); + assert!(cfg.user_interface.check_for_updates.is_none()); assert_eq!(cfg.user_interface.file_fmt, None); // Verify keys assert_eq!( @@ -200,6 +205,7 @@ mod tests { default_protocol = "SCP" text_editor = "vim" show_hidden_files = true + check_for_updates = true group_dirs = "last" file_fmt = "{NAME} {PEX}" diff --git a/src/system/config_client.rs b/src/system/config_client.rs index 6b994c5..b9b464c 100644 --- a/src/system/config_client.rs +++ b/src/system/config_client.rs @@ -138,6 +138,20 @@ impl ConfigClient { self.config.user_interface.show_hidden_files = value; } + /// ### get_check_for_updates + /// + /// Get value of `check_for_updates` + pub fn get_check_for_updates(&self) -> bool { + self.config.user_interface.check_for_updates.unwrap_or(true) + } + + /// ### set_check_for_updates + /// + /// Set new value for `check_for_updates` + pub fn set_check_for_updates(&mut self, value: bool) { + self.config.user_interface.check_for_updates = Some(value); + } + /// ### get_group_dirs /// /// Get GroupDirs value from configuration (will be converted from string) @@ -455,6 +469,20 @@ mod tests { assert_eq!(client.get_show_hidden_files(), true); } + #[test] + fn test_system_config_check_for_updates() { + 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_check_for_updates(), true); // Null ? + client.set_check_for_updates(true); + assert_eq!(client.get_check_for_updates(), true); + client.set_check_for_updates(false); + assert_eq!(client.get_check_for_updates(), false); + } + #[test] fn test_system_config_group_dirs() { let tmp_dir: tempfile::TempDir = create_tmp_dir();