mirror of
https://github.com/sxyazi/yazi.git
synced 2026-07-25 08:41:05 +00:00
feat(yazi-cli/pack): support remotes other than github
This commit is contained in:
parent
a9eb218a5b
commit
11838092cf
5 changed files with 44 additions and 18 deletions
1
Cargo.lock
generated
1
Cargo.lock
generated
|
|
@ -2868,6 +2868,7 @@ dependencies = [
|
||||||
"serde_json",
|
"serde_json",
|
||||||
"tokio",
|
"tokio",
|
||||||
"toml_edit",
|
"toml_edit",
|
||||||
|
"url",
|
||||||
"vergen-gitcl",
|
"vergen-gitcl",
|
||||||
"yazi-boot",
|
"yazi-boot",
|
||||||
"yazi-dds",
|
"yazi-dds",
|
||||||
|
|
|
||||||
|
|
@ -21,6 +21,7 @@ md-5 = "0.10.6"
|
||||||
serde_json = "1.0.120"
|
serde_json = "1.0.120"
|
||||||
tokio = { version = "1.38.1", features = [ "full" ] }
|
tokio = { version = "1.38.1", features = [ "full" ] }
|
||||||
toml_edit = "0.22.16"
|
toml_edit = "0.22.16"
|
||||||
|
url = "2.5.2"
|
||||||
|
|
||||||
[build-dependencies]
|
[build-dependencies]
|
||||||
anyhow = "1.0.86"
|
anyhow = "1.0.86"
|
||||||
|
|
|
||||||
|
|
@ -9,7 +9,7 @@ impl Package {
|
||||||
|
|
||||||
let path = self.local();
|
let path = self.local();
|
||||||
if !must_exists(&path).await {
|
if !must_exists(&path).await {
|
||||||
Git::clone(&self.remote(), &path).await?;
|
Git::clone(&self.remote, &path).await?;
|
||||||
} else {
|
} else {
|
||||||
Git::pull(&path).await?;
|
Git::pull(&path).await?;
|
||||||
};
|
};
|
||||||
|
|
|
||||||
|
|
@ -9,7 +9,7 @@ impl Package {
|
||||||
|
|
||||||
let path = self.local();
|
let path = self.local();
|
||||||
if !must_exists(&path).await {
|
if !must_exists(&path).await {
|
||||||
Git::clone(&self.remote(), &path).await?;
|
Git::clone(&self.remote, &path).await?;
|
||||||
} else {
|
} else {
|
||||||
Git::fetch(&path).await?;
|
Git::fetch(&path).await?;
|
||||||
};
|
};
|
||||||
|
|
|
||||||
|
|
@ -2,28 +2,58 @@ use std::{borrow::Cow, io::BufWriter, path::PathBuf};
|
||||||
|
|
||||||
use anyhow::Result;
|
use anyhow::Result;
|
||||||
use md5::{Digest, Md5};
|
use md5::{Digest, Md5};
|
||||||
|
use url::Url;
|
||||||
use yazi_shared::Xdg;
|
use yazi_shared::Xdg;
|
||||||
|
|
||||||
pub(crate) struct Package {
|
pub(crate) struct Package {
|
||||||
pub(crate) repo: String,
|
pub(crate) repo: String,
|
||||||
pub(crate) child: String,
|
pub(crate) child: String,
|
||||||
|
pub(crate) remote: String,
|
||||||
pub(crate) commit: String,
|
pub(crate) commit: String,
|
||||||
pub(super) is_flavor: bool,
|
pub(super) is_flavor: bool,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Package {
|
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, '#');
|
match Url::parse(url) {
|
||||||
|
Ok(url) => {
|
||||||
|
let repo = url.path().trim_start_matches('/').to_string();
|
||||||
|
let child = match url.fragment() {
|
||||||
|
Some(fragment) => format!("{fragment}.yazi"),
|
||||||
|
None => String::new(),
|
||||||
|
};
|
||||||
|
let remote = url.to_string();
|
||||||
|
|
||||||
let mut repo = parts.next().unwrap_or_default().to_owned();
|
return Self {
|
||||||
let child = if let Some(s) = parts.next() {
|
repo,
|
||||||
format!("{s}.yazi")
|
child,
|
||||||
} else {
|
remote,
|
||||||
repo.push_str(".yazi");
|
commit: commit.unwrap_or_default().to_owned(),
|
||||||
String::new()
|
is_flavor: false,
|
||||||
};
|
};
|
||||||
|
}
|
||||||
|
Err(_) => {
|
||||||
|
let mut parts = url.splitn(2, '#');
|
||||||
|
|
||||||
Self { repo, child, commit: commit.unwrap_or_default().to_owned(), is_flavor: false }
|
let mut repo = parts.next().unwrap_or_default().to_owned();
|
||||||
|
let child = if let Some(s) = parts.next() {
|
||||||
|
format!("{s}.yazi")
|
||||||
|
} else {
|
||||||
|
repo.push_str(".yazi");
|
||||||
|
String::new()
|
||||||
|
};
|
||||||
|
|
||||||
|
let remote = format!("https://github.com/{}.git", repo);
|
||||||
|
|
||||||
|
return Self {
|
||||||
|
repo,
|
||||||
|
child,
|
||||||
|
remote,
|
||||||
|
commit: commit.unwrap_or_default().to_owned(),
|
||||||
|
is_flavor: false,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[inline]
|
#[inline]
|
||||||
|
|
@ -50,13 +80,7 @@ impl Package {
|
||||||
pub(super) fn local(&self) -> PathBuf {
|
pub(super) fn local(&self) -> PathBuf {
|
||||||
Xdg::state_dir()
|
Xdg::state_dir()
|
||||||
.join("packages")
|
.join("packages")
|
||||||
.join(format!("{:x}", Md5::new_with_prefix(self.remote()).finalize()))
|
.join(format!("{:x}", Md5::new_with_prefix(&self.remote).finalize()))
|
||||||
}
|
|
||||||
|
|
||||||
#[inline]
|
|
||||||
pub(super) fn remote(&self) -> String {
|
|
||||||
// Support more Git hosting services in the future
|
|
||||||
format!("https://github.com/{}.git", self.repo)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
pub(super) fn output(&self, s: &str) -> Result<()> {
|
pub(super) fn output(&self, s: &str) -> Result<()> {
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue