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(version = "0.1.4")]
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
#[arg(index = 1)]
cwd: Option<PathBuf>,
@ -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()),

View File

@ -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<String>,
// TODO: Deprecate this field in v0.1.5
pub args: Option<Vec<String>>,
pub exec: Option<String>,
pub exec: String,
#[serde(default)]
pub block: bool,
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_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() {
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 })
}
}