mirror of
https://github.com/cargo-bins/cargo-binstall.git
synced 2025-06-15 07:06:36 +00:00
add cli override support
This commit is contained in:
parent
8b4e77918c
commit
6c1887674a
4 changed files with 30 additions and 11 deletions
|
@ -18,7 +18,7 @@ fn find_version<'a, V: Iterator<Item=&'a str>>(requirement: &str, version_iter:
|
|||
// Filter for matching versions
|
||||
let mut filtered: Vec<_> = version_iter.filter(|v| {
|
||||
// Remove leading `v` for git tags
|
||||
let ver_str = match v.strip_prefix("s") {
|
||||
let ver_str = match v.strip_prefix('s') {
|
||||
Some(v) => v,
|
||||
None => v,
|
||||
};
|
||||
|
|
|
@ -57,7 +57,7 @@ pub fn extract<S: AsRef<Path>, P: AsRef<Path>>(source: S, fmt: PkgFmt, path: P)
|
|||
|
||||
tar.unpack(path)?;
|
||||
},
|
||||
PkgFmt::Tgz => {
|
||||
PkgFmt::Tgz | PkgFmt::TarGz => {
|
||||
// Extract to install dir
|
||||
debug!("Decompressing from tgz archive '{:?}' to `{:?}`", source.as_ref(), path.as_ref());
|
||||
|
||||
|
@ -129,7 +129,7 @@ pub fn get_install_path<P: AsRef<Path>>(install_path: Option<P>) -> Option<PathB
|
|||
// Local executable dir if no cargo is found
|
||||
if let Some(d) = dirs::executable_dir() {
|
||||
debug!("Fallback to {}", d.display());
|
||||
return Some(d.into());
|
||||
return Some(d);
|
||||
}
|
||||
|
||||
None
|
||||
|
|
11
src/lib.rs
11
src/lib.rs
|
@ -14,13 +14,13 @@ pub use drivers::*;
|
|||
|
||||
|
||||
/// Compiled target triple, used as default for binary fetching
|
||||
pub const TARGET: &'static str = env!("TARGET");
|
||||
pub const TARGET: &str = env!("TARGET");
|
||||
|
||||
/// Default package path template (may be overridden in package Cargo.toml)
|
||||
pub const DEFAULT_PKG_URL: &'static str = "{ repo }/releases/download/v{ version }/{ name }-{ target }-v{ version }.{ format }";
|
||||
pub const DEFAULT_PKG_URL: &str = "{ repo }/releases/download/v{ version }/{ name }-{ target }-v{ version }.{ format }";
|
||||
|
||||
/// Default binary name template (may be overridden in package Cargo.toml)
|
||||
pub const DEFAULT_BIN_PATH: &'static str = "{ name }-{ target }-v{ version }/{ bin }{ format }";
|
||||
pub const DEFAULT_BIN_PATH: &str = "{ name }-{ target }-v{ version }/{ bin }{ format }";
|
||||
|
||||
|
||||
/// Binary format enumeration
|
||||
|
@ -33,6 +33,9 @@ pub enum PkgFmt {
|
|||
Tar,
|
||||
/// Download format is TGZ (TAR + GZip)
|
||||
Tgz,
|
||||
/// Download format is TAR.GZ (TAR + GZip)
|
||||
#[strum(serialize = "tar.gz")]
|
||||
TarGz,
|
||||
/// Download format is TAR + XZ
|
||||
Txz,
|
||||
/// Download format is Zip
|
||||
|
@ -159,7 +162,7 @@ impl Context {
|
|||
let mut tt = TinyTemplate::new();
|
||||
|
||||
// Add template to instance
|
||||
tt.add_template("path", &template)?;
|
||||
tt.add_template("path", template)?;
|
||||
|
||||
// Render output
|
||||
let rendered = tt.render("path", self)?;
|
||||
|
|
24
src/main.rs
24
src/main.rs
|
@ -56,6 +56,18 @@ struct Options {
|
|||
/// Utility log level
|
||||
#[structopt(long, default_value = "info")]
|
||||
log_level: LevelFilter,
|
||||
|
||||
/// Override Cargo.toml package manifest pkg-url.
|
||||
#[structopt(long)]
|
||||
pkg_url: Option<String>,
|
||||
|
||||
/// Override Cargo.toml package manifest pkg-fmt.
|
||||
#[structopt(long)]
|
||||
pkg_fmt: Option<PkgFmt>,
|
||||
|
||||
/// Override Cargo.toml package manifest bin-dir.
|
||||
#[structopt(long)]
|
||||
bin_dir: Option<String>,
|
||||
}
|
||||
|
||||
|
||||
|
@ -72,6 +84,11 @@ async fn main() -> Result<(), anyhow::Error> {
|
|||
|
||||
// Load options
|
||||
let opts = Options::from_iter(args.iter());
|
||||
let cli_overrides = PkgOverride {
|
||||
pkg_url: opts.pkg_url.clone(),
|
||||
pkg_fmt: opts.pkg_fmt,
|
||||
bin_dir: opts.bin_dir.clone(),
|
||||
};
|
||||
|
||||
// Setup logging
|
||||
let mut log_config = ConfigBuilder::new();
|
||||
|
@ -98,7 +115,7 @@ async fn main() -> Result<(), anyhow::Error> {
|
|||
let package = manifest.package.unwrap();
|
||||
|
||||
let (mut meta, binaries) = (
|
||||
package.metadata.map(|m| m.binstall ).flatten().unwrap_or(PkgMeta::default()),
|
||||
package.metadata.map(|m| m.binstall ).flatten().unwrap_or_default(),
|
||||
manifest.bin,
|
||||
);
|
||||
|
||||
|
@ -106,8 +123,7 @@ async fn main() -> Result<(), anyhow::Error> {
|
|||
if let Some(o) = meta.overrides.remove(&opts.target) {
|
||||
meta.merge(&o);
|
||||
}
|
||||
|
||||
debug!("Found metadata: {:?}", meta);
|
||||
meta.merge(&cli_overrides);
|
||||
|
||||
// Generate context for URL interpolation
|
||||
let ctx = Context {
|
||||
|
@ -175,7 +191,7 @@ async fn main() -> Result<(), anyhow::Error> {
|
|||
let _ = temp_dir.into_path();
|
||||
}
|
||||
|
||||
if binaries.len() == 0 {
|
||||
if binaries.is_empty() {
|
||||
error!("No binaries specified (or inferred from file system)");
|
||||
return Err(anyhow::anyhow!("No binaries specified (or inferred from file system)"));
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue