mirror of
https://github.com/cargo-bins/cargo-binstall.git
synced 2025-06-15 15:16:37 +00:00
Use pkg_fmt from fetcher
This commit is contained in:
parent
a12e934940
commit
99e5de0025
4 changed files with 17 additions and 4 deletions
|
@ -3,7 +3,7 @@ use std::path::Path;
|
||||||
pub use gh_release::*;
|
pub use gh_release::*;
|
||||||
pub use quickinstall::*;
|
pub use quickinstall::*;
|
||||||
|
|
||||||
use crate::PkgMeta;
|
use crate::{PkgFmt, PkgMeta};
|
||||||
|
|
||||||
mod gh_release;
|
mod gh_release;
|
||||||
mod quickinstall;
|
mod quickinstall;
|
||||||
|
@ -20,6 +20,9 @@ pub trait Fetcher {
|
||||||
|
|
||||||
/// Check if a package is available for download
|
/// Check if a package is available for download
|
||||||
async fn check(&self) -> Result<bool, anyhow::Error>;
|
async fn check(&self) -> Result<bool, anyhow::Error>;
|
||||||
|
|
||||||
|
/// Return the package format
|
||||||
|
fn pkg_fmt(&self) -> PkgFmt;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Data required to fetch a package
|
/// Data required to fetch a package
|
||||||
|
|
|
@ -5,10 +5,11 @@ use reqwest::Method;
|
||||||
use serde::Serialize;
|
use serde::Serialize;
|
||||||
|
|
||||||
use super::Data;
|
use super::Data;
|
||||||
use crate::{download, remote_exists, Template};
|
use crate::{download, remote_exists, PkgFmt, Template};
|
||||||
|
|
||||||
pub struct GhRelease {
|
pub struct GhRelease {
|
||||||
url: String,
|
url: String,
|
||||||
|
pkg_fmt: PkgFmt,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[async_trait::async_trait]
|
#[async_trait::async_trait]
|
||||||
|
@ -26,6 +27,7 @@ impl super::Fetcher for GhRelease {
|
||||||
|
|
||||||
Ok(Box::new(Self {
|
Ok(Box::new(Self {
|
||||||
url: ctx.render(&data.meta.pkg_url)?,
|
url: ctx.render(&data.meta.pkg_url)?,
|
||||||
|
pkg_fmt: data.meta.pkg_fmt,
|
||||||
}))
|
}))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -38,6 +40,10 @@ impl super::Fetcher for GhRelease {
|
||||||
info!("Downloading package from: '{}'", self.url);
|
info!("Downloading package from: '{}'", self.url);
|
||||||
download(&self.url, dst).await
|
download(&self.url, dst).await
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn pkg_fmt(&self) -> PkgFmt {
|
||||||
|
self.pkg_fmt
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Template for constructing download paths
|
/// Template for constructing download paths
|
||||||
|
|
|
@ -4,7 +4,7 @@ use log::info;
|
||||||
use reqwest::Method;
|
use reqwest::Method;
|
||||||
|
|
||||||
use super::Data;
|
use super::Data;
|
||||||
use crate::{download, remote_exists};
|
use crate::{download, remote_exists, PkgFmt};
|
||||||
|
|
||||||
pub struct QuickInstall {
|
pub struct QuickInstall {
|
||||||
url: String,
|
url: String,
|
||||||
|
@ -28,4 +28,8 @@ impl super::Fetcher for QuickInstall {
|
||||||
info!("Downloading package from: '{}'", self.url);
|
info!("Downloading package from: '{}'", self.url);
|
||||||
download(&self.url, dst).await
|
download(&self.url, dst).await
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn pkg_fmt(&self) -> PkgFmt {
|
||||||
|
PkgFmt::Tgz
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -180,7 +180,7 @@ async fn main() -> Result<(), anyhow::Error> {
|
||||||
|
|
||||||
// Extract files
|
// Extract files
|
||||||
let bin_path = temp_dir.path().join(format!("bin-{}", opts.name));
|
let bin_path = temp_dir.path().join(format!("bin-{}", opts.name));
|
||||||
extract(&pkg_path, meta.pkg_fmt, &bin_path)?;
|
extract(&pkg_path, fetcher.pkg_fmt(), &bin_path)?;
|
||||||
|
|
||||||
// Bypass cleanup if disabled
|
// Bypass cleanup if disabled
|
||||||
if opts.no_cleanup {
|
if opts.no_cleanup {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue