From 65b9ff61856e67aa457cd952758f4fc708be476d Mon Sep 17 00:00:00 2001 From: fdai7451 Date: Sat, 21 Jan 2023 18:09:09 +0100 Subject: [PATCH] refactoring: unwrap preprocessing env set key as its always Some --- src/preprocess.rs | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/src/preprocess.rs b/src/preprocess.rs index 2162753..74eedf4 100644 --- a/src/preprocess.rs +++ b/src/preprocess.rs @@ -9,14 +9,12 @@ const ENV_SET: Lazy = Lazy::new(|| Regex::new(r#"(?P\w+)=(?P\ /// returns `Ok(None)`, do not execute a command. pub fn preprocess(line: String) -> Result, ShellError> { if let Some(capture) = ENV_SET.captures(&line) { - let Some(key) = capture.name("key") else { - return Err(ShellError::MalformedArgs("cannot find key to set env variable".to_string())) - }; + let key = capture.name("key").unwrap().as_str(); let value = capture .name("value") .map_or("".to_string(), |v| v.as_str().to_string()); - env::set_var(key.as_str(), value); + env::set_var(key, value); return Ok(None); }