Added check_for_updates to config

This commit is contained in:
veeso
2021-02-28 12:44:00 +01:00
parent 4e887c3429
commit 6682c07eb6
3 changed files with 40 additions and 1 deletions

View File

@@ -55,6 +55,7 @@ pub struct UserInterfaceConfig {
pub text_editor: PathBuf, pub text_editor: PathBuf,
pub default_protocol: String, pub default_protocol: String,
pub show_hidden_files: bool, pub show_hidden_files: bool,
pub check_for_updates: Option<bool>, // @! Since 0.3.3
pub group_dirs: Option<String>, pub group_dirs: Option<String>,
pub file_fmt: Option<String>, pub file_fmt: Option<String>,
} }
@@ -85,6 +86,7 @@ impl Default for UserInterfaceConfig {
}, },
default_protocol: FileTransferProtocol::Sftp.to_string(), default_protocol: FileTransferProtocol::Sftp.to_string(),
show_hidden_files: false, show_hidden_files: false,
check_for_updates: Some(true),
group_dirs: None, group_dirs: None,
file_fmt: None, file_fmt: None,
} }
@@ -172,6 +174,7 @@ mod tests {
default_protocol: String::from("SFTP"), default_protocol: String::from("SFTP"),
text_editor: PathBuf::from("nano"), text_editor: PathBuf::from("nano"),
show_hidden_files: true, show_hidden_files: true,
check_for_updates: Some(true),
group_dirs: Some(String::from("first")), group_dirs: Some(String::from("first")),
file_fmt: Some(String::from("{NAME}")), 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.default_protocol, String::from("SFTP"));
assert_eq!(cfg.user_interface.text_editor, PathBuf::from("nano")); assert_eq!(cfg.user_interface.text_editor, PathBuf::from("nano"));
assert_eq!(cfg.user_interface.show_hidden_files, true); 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.group_dirs, Some(String::from("first")));
assert_eq!(cfg.user_interface.file_fmt, Some(String::from("{NAME}"))); assert_eq!(cfg.user_interface.file_fmt, Some(String::from("{NAME}")));
} }
@@ -201,6 +205,7 @@ mod tests {
let cfg: UserConfig = UserConfig::default(); let cfg: UserConfig = UserConfig::default();
assert_eq!(cfg.user_interface.default_protocol, String::from("SFTP")); 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.text_editor, PathBuf::from("vim"));
assert_eq!(cfg.user_interface.check_for_updates.unwrap(), true);
assert_eq!(cfg.remote.ssh_keys.len(), 0); assert_eq!(cfg.remote.ssh_keys.len(), 0);
} }

View File

@@ -107,8 +107,12 @@ mod tests {
assert_eq!(cfg.user_interface.default_protocol, String::from("SCP")); 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.text_editor, PathBuf::from("vim"));
assert_eq!(cfg.user_interface.show_hidden_files, true); 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.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 // Verify keys
assert_eq!( assert_eq!(
*cfg.remote *cfg.remote
@@ -144,6 +148,7 @@ mod tests {
assert_eq!(cfg.user_interface.text_editor, PathBuf::from("vim")); assert_eq!(cfg.user_interface.text_editor, PathBuf::from("vim"));
assert_eq!(cfg.user_interface.show_hidden_files, true); assert_eq!(cfg.user_interface.show_hidden_files, true);
assert_eq!(cfg.user_interface.group_dirs, None); 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); assert_eq!(cfg.user_interface.file_fmt, None);
// Verify keys // Verify keys
assert_eq!( assert_eq!(
@@ -200,6 +205,7 @@ mod tests {
default_protocol = "SCP" default_protocol = "SCP"
text_editor = "vim" text_editor = "vim"
show_hidden_files = true show_hidden_files = true
check_for_updates = true
group_dirs = "last" group_dirs = "last"
file_fmt = "{NAME} {PEX}" file_fmt = "{NAME} {PEX}"

View File

@@ -138,6 +138,20 @@ impl ConfigClient {
self.config.user_interface.show_hidden_files = value; 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_group_dirs
/// ///
/// Get GroupDirs value from configuration (will be converted from string) /// Get GroupDirs value from configuration (will be converted from string)
@@ -455,6 +469,20 @@ mod tests {
assert_eq!(client.get_show_hidden_files(), true); 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] #[test]
fn test_system_config_group_dirs() { fn test_system_config_group_dirs() {
let tmp_dir: tempfile::TempDir = create_tmp_dir(); let tmp_dir: tempfile::TempDir = create_tmp_dir();