mirror of
https://github.com/sxyazi/yazi.git
synced 2026-07-25 08:41:05 +00:00
Simplify the code a bit
This commit is contained in:
parent
72902f8d57
commit
6fc52713b5
2 changed files with 12 additions and 14 deletions
|
|
@ -5,7 +5,7 @@ use serde::{Deserialize, Deserializer, Serialize, Serializer};
|
||||||
use twox_hash::XxHash3_128;
|
use twox_hash::XxHash3_128;
|
||||||
use yazi_fs::Xdg;
|
use yazi_fs::Xdg;
|
||||||
|
|
||||||
#[derive(Default)]
|
#[derive(Clone, Default)]
|
||||||
pub(crate) struct Dependency {
|
pub(crate) struct Dependency {
|
||||||
pub(crate) use_: String, // owner/repo:child
|
pub(crate) use_: String, // owner/repo:child
|
||||||
pub(crate) name: String, // child.yazi
|
pub(crate) name: String, // child.yazi
|
||||||
|
|
@ -39,6 +39,11 @@ impl Dependency {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[inline]
|
||||||
|
pub(super) fn identical(&self, other: &Self) -> bool {
|
||||||
|
self.parent == other.parent && self.child == other.child
|
||||||
|
}
|
||||||
|
|
||||||
pub(super) fn header(&self, s: &str) -> Result<()> {
|
pub(super) fn header(&self, s: &str) -> Result<()> {
|
||||||
use crossterm::style::{Attribute, Print, SetAttributes};
|
use crossterm::style::{Attribute, Print, SetAttributes};
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -45,18 +45,15 @@ impl Package {
|
||||||
}
|
}
|
||||||
|
|
||||||
pub(crate) async fn delete(&mut self, use_: &str) -> Result<()> {
|
pub(crate) async fn delete(&mut self, use_: &str) -> Result<()> {
|
||||||
let dep_to_find = Dependency::from_str(use_)?;
|
let Some(dep) = self.identical(&Dependency::from_str(use_)?).cloned() else {
|
||||||
|
bail!("`{}` was not found in package.toml", use_)
|
||||||
let dep = match self.identical(&dep_to_find) {
|
|
||||||
Some(d) => d,
|
|
||||||
None => bail!("`{}` was not found in package.toml", use_),
|
|
||||||
};
|
};
|
||||||
|
|
||||||
dep.delete().await?;
|
dep.delete().await?;
|
||||||
if dep.is_flavor {
|
if dep.is_flavor {
|
||||||
self.flavors.retain(|f| f.use_ != use_);
|
self.flavors.retain(|d| !d.identical(&dep));
|
||||||
} else {
|
} else {
|
||||||
self.plugins.retain(|f| f.use_ != use_);
|
self.plugins.retain(|d| !d.identical(&dep));
|
||||||
}
|
}
|
||||||
|
|
||||||
let s = toml::to_string_pretty(self)?;
|
let s = toml::to_string_pretty(self)?;
|
||||||
|
|
@ -189,12 +186,8 @@ impl Package {
|
||||||
fn toml() -> PathBuf { Xdg::config_dir().join("package.toml") }
|
fn toml() -> PathBuf { Xdg::config_dir().join("package.toml") }
|
||||||
|
|
||||||
#[inline]
|
#[inline]
|
||||||
fn identical(&self, dep: &Dependency) -> Option<&Dependency> {
|
fn identical(&self, other: &Dependency) -> Option<&Dependency> {
|
||||||
self
|
self.plugins.iter().chain(&self.flavors).find(|d| d.identical(other))
|
||||||
.plugins
|
|
||||||
.iter()
|
|
||||||
.chain(&self.flavors)
|
|
||||||
.find(|d| d.parent == dep.parent && d.child == dep.child)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue