mod install;
pub mod progress;
mod reference;
mod release;
mod store;
pub use reference::ProviderReference;
pub use release::latest_release_at;
pub use release::{
checksum_sidecar, download_bytes, extract_binary, latest_release, pick_asset, platform_target,
verify_checksum,
};
use serde::{Deserialize, Serialize};
use std::path::PathBuf;
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct Receipt {
pub name: String,
pub source: String,
pub tag: String,
pub sha256: String,
pub pinned: bool,
#[serde(default)]
pub installed_at: Option<String>,
#[serde(default)]
pub latest_tag: Option<String>,
}
pub type Result<T, E = ManagerError> = std::result::Result<T, E>;
#[derive(Debug, thiserror::Error)]
pub enum ManagerError {
#[error("{0}")]
User(String),
#[error("network: {0}")]
Network(String),
#[error("io: {0}")]
Io(#[from] std::io::Error),
}
pub struct Manager {
store: PathBuf,
state: PathBuf,
api: String,
}
impl Manager {
pub fn new() -> Result<Manager> {
Ok(Manager {
store: store::store_root().ok_or_else(|| ManagerError::User("no data dir".into()))?,
state: store::state_root().ok_or_else(|| ManagerError::User("no state dir".into()))?,
api: "https://api.github.com".into(),
})
}
#[cfg(test)]
pub(crate) fn rooted_at(store: PathBuf, state: PathBuf) -> Manager {
Manager {
store,
state,
api: "https://api.github.com".into(),
}
}
#[cfg(test)]
pub(crate) fn with_api(mut self, api: &str) -> Manager {
self.api = api.into();
self
}
}
#[derive(Debug, Clone)]
pub struct Installed {
pub receipt: Receipt,
pub active: bool,
pub current: Option<String>,
}
#[derive(Debug, Clone)]
pub enum SweepOutcome {
Upgraded {
name: String,
from: String,
to: String,
},
Stale {
name: String,
from: String,
to: String,
},
Current {
name: String,
tag: String,
},
Pinned {
name: String,
tag: String,
},
Untracked {
name: String,
source: String,
},
Failed {
name: String,
error: String,
},
}