From 96cb7b6cc8404e5a214cc54e4be463153aea7911 Mon Sep 17 00:00:00 2001 From: sxyazi Date: Sat, 2 Sep 2023 11:44:22 +0800 Subject: [PATCH] refactor: deprecate the obsolete features --- config/src/boot/boot.rs | 19 ++------------ config/src/open/opener.rs | 55 ++++++--------------------------------- 2 files changed, 10 insertions(+), 64 deletions(-) diff --git a/config/src/boot/boot.rs b/config/src/boot/boot.rs index 743b041f..19fa9271 100644 --- a/config/src/boot/boot.rs +++ b/config/src/boot/boot.rs @@ -18,11 +18,6 @@ pub struct Boot { #[command(name = "yazi")] #[command(version = "0.1.4")] struct Args { - // -- TODO: Deprecate this in v0.1.5 - /// Set the current working directory - #[arg(long, short)] - _cwd: Option, - /// Set the current working directory #[arg(index = 1)] cwd: Option, @@ -43,18 +38,8 @@ impl Default for Boot { fn default() -> Self { let args = Args::parse(); - // -- TODO: Deprecate this in v0.1.5 - let cwd = if args._cwd.is_some() { - println!( - "Warning: -c/--cwd is deprecated in v0.1.5, please use the positional argument instead: `yazi --cwd /path/to/dir` -> `yazi /path/to/dir`.\nSee https://github.com/sxyazi/yazi/issues/95 for more information." - ); - args._cwd - } else { - args.cwd - }; - // TODO: Deprecate this in v0.1.5 -- - - let cwd = cwd.map(absolute_path).filter(|p| p.is_dir()).or_else(|| env::current_dir().ok()); + let cwd = + args.cwd.map(absolute_path).filter(|p| p.is_dir()).or_else(|| env::current_dir().ok()); let boot = Self { cwd: cwd.unwrap_or("/".into()), diff --git a/config/src/open/opener.rs b/config/src/open/opener.rs index 37256ba0..b813c04d 100644 --- a/config/src/open/opener.rs +++ b/config/src/open/opener.rs @@ -15,62 +15,23 @@ impl<'de> Deserialize<'de> for Opener { { #[derive(Deserialize)] pub struct Shadow { - // TODO: Deprecate this field in v0.1.5 - pub cmd: Option, - // TODO: Deprecate this field in v0.1.5 - pub args: Option>, - - pub exec: Option, + pub exec: String, #[serde(default)] pub block: bool, pub display_name: Option, } - let mut shadow = Shadow::deserialize(deserializer)?; + let shadow = Shadow::deserialize(deserializer)?; - // -- TODO: Deprecate this in v0.1.5 - if shadow.exec.is_none() { - if shadow.cmd.is_none() { - return Err(serde::de::Error::missing_field("exec")); - } - if shadow.args.is_none() { - return Err(serde::de::Error::missing_field("args")); - } - - println!( - "WARNING: `cmd` and `args` will be deprecated in favor of `exec` in Yazi v0.1.5, see https://github.com/sxyazi/yazi/pull/45" - ); - - // Replace the $0 to $1, $1 to $2, and so on - shadow.args = Some( - shadow - .args - .unwrap() - .into_iter() - .map(|s| { - if !s.starts_with('$') { - return shell_words::quote(&s).into(); - } - if let Ok(idx) = s[1..].parse::() { - return format!("${}", idx + 1); - } - s - }) - .collect(), - ); - shadow.exec = Some(format!("{} {}", shadow.cmd.unwrap(), shadow.args.unwrap().join(" "))); - } - let exec = shadow.exec.unwrap(); - // TODO: Deprecate this in v0.1.5 -- - - if exec.is_empty() { + if shadow.exec.is_empty() { return Err(serde::de::Error::custom("`exec` cannot be empty")); } - let display_name = - shadow.display_name.unwrap_or_else(|| exec.split_whitespace().next().unwrap().to_string()); + let display_name = shadow + .display_name + .unwrap_or_else(|| shadow.exec.split_whitespace().next().unwrap().to_string()); - let spread = exec.contains("$*") || exec.contains("$@"); - Ok(Self { exec, block: shadow.block, display_name, spread }) + let spread = shadow.exec.contains("$*") || shadow.exec.contains("$@"); + Ok(Self { exec: shadow.exec, block: shadow.block, display_name, spread }) } }