From 611e3b8dd0a6e1089e1a5c7530d0813da4375b0c Mon Sep 17 00:00:00 2001 From: "Brian J. Tarricone" Date: Mon, 23 May 2022 20:33:14 -0700 Subject: [PATCH] Use constants in settings rather than hard-coded strings --- util/src/settings.rs | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/util/src/settings.rs b/util/src/settings.rs index dd834fd..974b0e9 100644 --- a/util/src/settings.rs +++ b/util/src/settings.rs @@ -70,25 +70,25 @@ impl Configuration { let mut config = Configuration::default(); for config_toml in config_tomls { - config.lock_timeout = match config_toml.get("lock-timeout") { + config.lock_timeout = match config_toml.get(LOCK_TIMEOUT) { None => config.lock_timeout, - Some(val) => parse_duration(val.as_str().ok_or(anyhow!("'lock-timeout' must be a duration string like '10m' or '90s'"))?)?, + Some(val) => parse_duration(val.as_str().ok_or(anyhow!("'{}' must be a duration string like '10m' or '90s'", LOCK_TIMEOUT))?)?, }; - config.blank_before_locking = match config_toml.get("blank-before-locking") { + config.blank_before_locking = match config_toml.get(BLANK_BEFORE_LOCKING) { None => config.blank_before_locking, - Some(val) => parse_duration(val.as_str().ok_or(anyhow!("'blank-before-locking' must be a duration string like '10m' or '90s'"))?)?, + Some(val) => parse_duration(val.as_str().ok_or(anyhow!("'{}' must be a duration string like '10m' or '90s'", BLANK_BEFORE_LOCKING))?)?, }; - config.dialog_backend = match config_toml.get("dialog-backend") { + config.dialog_backend = match config_toml.get(DIALOG_BACKEND) { None => config.dialog_backend, - Some(val) => DialogBackend::try_from(val.as_str().ok_or(anyhow!("'dialog-backend' must be a string"))?)?, + Some(val) => DialogBackend::try_from(val.as_str().ok_or(anyhow!("'{}' must be a string", DIALOG_BACKEND))?)?, }; - config.new_login_command = match config_toml.get("new-login-command") { + config.new_login_command = match config_toml.get(NEW_LOGIN_COMMAND) { None => config.new_login_command, Some(val) => val.try_into().unwrap_or(NewLoginCommand::Auto), }; config.handle_brightness_keys = match config_toml.get(HANDLE_BRIGHTNESS_KEYS) { None => config.handle_brightness_keys, - Some(val) => val.as_bool().ok_or(anyhow!("'handle-brightness-keys' must be a boolean"))?, + Some(val) => val.as_bool().ok_or(anyhow!("'{}' must be a boolean", HANDLE_BRIGHTNESS_KEYS))?, } }