Add quickinstall support

This commit is contained in:
Félix Saparelli 2022-02-16 00:14:37 +13:00
parent b584038d0d
commit 4e0ca0c1c3
No known key found for this signature in database
GPG key ID: B948C4BAE44FC474
5 changed files with 75 additions and 18 deletions

View file

@ -1,17 +1,17 @@
use std::path::Path;
pub use gh_release::*;
pub use quickinstall::*;
use crate::PkgMeta;
mod gh_release;
mod quickinstall;
#[async_trait::async_trait]
pub trait Fetcher {
/// Create a new fetcher from some data
async fn new(data: &Data) -> Result<Self, anyhow::Error>
where
Self: std::marker::Sized;
async fn new(data: &Data) -> Result<Box<Self>, anyhow::Error> where Self: Sized;
/// Fetch a package
async fn fetch(&self, dst: &Path) -> Result<(), anyhow::Error>;
@ -21,10 +21,32 @@ pub trait Fetcher {
}
/// Data required to fetch a package
#[derive(Debug)]
pub struct Data {
pub name: String,
pub target: String,
pub version: String,
pub repo: Option<String>,
pub meta: PkgMeta,
}
#[derive(Default)]
pub struct MultiFetcher {
fetchers: Vec<Box<dyn Fetcher>>,
}
impl MultiFetcher {
pub fn add(&mut self, fetcher: Box<dyn Fetcher>) {
self.fetchers.push(fetcher);
}
pub async fn first_available(&self) -> Option<&dyn Fetcher> {
for fetcher in &self.fetchers {
if fetcher.check().await.unwrap_or(false) {
return Some(&**fetcher);
}
}
None
}
}