mirror of
https://github.com/sxyazi/yazi.git
synced 2026-07-25 08:41:05 +00:00
fix(package): preserve ".yazi" extension in package name
This allows using plugins that end in ".yazi"
This commit is contained in:
parent
63768f9cde
commit
4c5704e970
1 changed files with 57 additions and 9 deletions
|
|
@ -4,6 +4,7 @@ use anyhow::Result;
|
||||||
use md5::{Digest, Md5};
|
use md5::{Digest, Md5};
|
||||||
use yazi_shared::Xdg;
|
use yazi_shared::Xdg;
|
||||||
|
|
||||||
|
#[derive(Debug, PartialEq)]
|
||||||
pub(crate) struct Package {
|
pub(crate) struct Package {
|
||||||
pub(crate) repo: String,
|
pub(crate) repo: String,
|
||||||
/// When a package is a subdirectory of a repository, this field will be set
|
/// When a package is a subdirectory of a repository, this field will be set
|
||||||
|
|
@ -17,13 +18,8 @@ impl Package {
|
||||||
pub(super) fn new(url: &str, commit: Option<&str>) -> Self {
|
pub(super) fn new(url: &str, commit: Option<&str>) -> Self {
|
||||||
let mut parts = url.splitn(2, '#');
|
let mut parts = url.splitn(2, '#');
|
||||||
|
|
||||||
let mut repo = parts.next().unwrap_or_default().to_owned();
|
let repo = parts.next().unwrap_or_default().to_owned();
|
||||||
let child = if let Some(s) = parts.next() {
|
let child = parts.next().unwrap_or_default().to_owned();
|
||||||
format!("{s}.yazi")
|
|
||||||
} else {
|
|
||||||
repo.push_str(".yazi");
|
|
||||||
String::new()
|
|
||||||
};
|
|
||||||
|
|
||||||
Self { repo, child, commit: commit.unwrap_or_default().to_owned(), is_flavor: false }
|
Self { repo, child, commit: commit.unwrap_or_default().to_owned(), is_flavor: false }
|
||||||
}
|
}
|
||||||
|
|
@ -31,9 +27,9 @@ impl Package {
|
||||||
#[inline]
|
#[inline]
|
||||||
pub(super) fn use_(&self) -> Cow<str> {
|
pub(super) fn use_(&self) -> Cow<str> {
|
||||||
if self.child.is_empty() {
|
if self.child.is_empty() {
|
||||||
self.repo.trim_end_matches(".yazi").into()
|
self.repo.clone().into()
|
||||||
} else {
|
} else {
|
||||||
format!("{}#{}", self.repo, self.child.trim_end_matches(".yazi")).into()
|
format!("{}#{}", self.repo, self.child).into()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -79,3 +75,55 @@ impl Package {
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[cfg(test)]
|
||||||
|
mod tests {
|
||||||
|
use super::*;
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn test_adds_yazi_suffix() {
|
||||||
|
// if a package doesn't have a suffix, it should add ".yazi" to the end
|
||||||
|
let package = Package::new("abcd/my-plugin.yazi", None);
|
||||||
|
assert_eq!(package, Package {
|
||||||
|
repo: "abcd/my-plugin.yazi".to_owned(),
|
||||||
|
child: "".to_owned(),
|
||||||
|
commit: "".to_owned(),
|
||||||
|
is_flavor: false,
|
||||||
|
});
|
||||||
|
|
||||||
|
assert_eq!(package.use_(), "abcd/my-plugin.yazi");
|
||||||
|
assert_eq!(package.name(), Some("my-plugin.yazi"));
|
||||||
|
assert_eq!(package.remote(), "https://github.com/abcd/my-plugin.yazi.git");
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn test_supports_subdirectories() {
|
||||||
|
let package = Package::new("yazi-rs/flavors#catppuccin-mocha.yazi", None);
|
||||||
|
assert_eq!(package, Package {
|
||||||
|
repo: "yazi-rs/flavors".to_owned(),
|
||||||
|
child: "catppuccin-mocha.yazi".to_owned(),
|
||||||
|
commit: "".to_owned(),
|
||||||
|
is_flavor: false,
|
||||||
|
});
|
||||||
|
|
||||||
|
assert_eq!(package.use_(), "yazi-rs/flavors#catppuccin-mocha.yazi");
|
||||||
|
assert_eq!(package.name(), Some("catppuccin-mocha.yazi"));
|
||||||
|
assert_eq!(package.remote(), "https://github.com/yazi-rs/flavors.git");
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn test_github_with_yazi_suffix() {
|
||||||
|
// when a github repository ends with .yazi, it should not add another .yazi
|
||||||
|
let package = Package::new("DreamMaoMao/keyjump.yazi", None);
|
||||||
|
assert_eq!(package, Package {
|
||||||
|
repo: "DreamMaoMao/keyjump.yazi".to_owned(),
|
||||||
|
child: "".to_owned(),
|
||||||
|
commit: "".to_owned(),
|
||||||
|
is_flavor: false,
|
||||||
|
});
|
||||||
|
|
||||||
|
assert_eq!(package.use_(), "DreamMaoMao/keyjump.yazi");
|
||||||
|
assert_eq!(package.name(), Some("keyjump.yazi"));
|
||||||
|
assert_eq!(package.remote(), "https://github.com/DreamMaoMao/keyjump.yazi.git");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue