refactor: deprecate the obsolete features

This commit is contained in:
sxyazi 2023-09-02 11:44:22 +08:00
parent e9218f8ad1
commit 96cb7b6cc8
No known key found for this signature in database
2 changed files with 10 additions and 64 deletions

View file

@ -18,11 +18,6 @@ pub struct Boot {
#[command(name = "yazi")] #[command(name = "yazi")]
#[command(version = "0.1.4")] #[command(version = "0.1.4")]
struct Args { struct Args {
// -- TODO: Deprecate this in v0.1.5
/// Set the current working directory
#[arg(long, short)]
_cwd: Option<PathBuf>,
/// Set the current working directory /// Set the current working directory
#[arg(index = 1)] #[arg(index = 1)]
cwd: Option<PathBuf>, cwd: Option<PathBuf>,
@ -43,18 +38,8 @@ impl Default for Boot {
fn default() -> Self { fn default() -> Self {
let args = Args::parse(); let args = Args::parse();
// -- TODO: Deprecate this in v0.1.5 let cwd =
let cwd = if args._cwd.is_some() { args.cwd.map(absolute_path).filter(|p| p.is_dir()).or_else(|| env::current_dir().ok());
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 boot = Self { let boot = Self {
cwd: cwd.unwrap_or("/".into()), cwd: cwd.unwrap_or("/".into()),

View file

@ -15,62 +15,23 @@ impl<'de> Deserialize<'de> for Opener {
{ {
#[derive(Deserialize)] #[derive(Deserialize)]
pub struct Shadow { pub struct Shadow {
// TODO: Deprecate this field in v0.1.5 pub exec: String,
pub cmd: Option<String>,
// TODO: Deprecate this field in v0.1.5
pub args: Option<Vec<String>>,
pub exec: Option<String>,
#[serde(default)] #[serde(default)]
pub block: bool, pub block: bool,
pub display_name: Option<String>, pub display_name: Option<String>,
} }
let mut shadow = Shadow::deserialize(deserializer)?; let shadow = Shadow::deserialize(deserializer)?;
// -- TODO: Deprecate this in v0.1.5 if shadow.exec.is_empty() {
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::<usize>() {
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() {
return Err(serde::de::Error::custom("`exec` cannot be empty")); return Err(serde::de::Error::custom("`exec` cannot be empty"));
} }
let display_name = let display_name = shadow
shadow.display_name.unwrap_or_else(|| exec.split_whitespace().next().unwrap().to_string()); .display_name
.unwrap_or_else(|| shadow.exec.split_whitespace().next().unwrap().to_string());
let spread = exec.contains("$*") || exec.contains("$@"); let spread = shadow.exec.contains("$*") || shadow.exec.contains("$@");
Ok(Self { exec, block: shadow.block, display_name, spread }) Ok(Self { exec: shadow.exec, block: shadow.block, display_name, spread })
} }
} }