mirror of
https://github.com/cargo-bins/cargo-binstall.git
synced 2025-05-05 11:40:04 +00:00
Clippy suggestions
This commit is contained in:
parent
13a8e1e5fe
commit
ac74da4a27
6 changed files with 17 additions and 25 deletions
|
@ -22,7 +22,7 @@ fn find_version<'a, V: Iterator<Item = &'a String>>(
|
|||
let filtered: BTreeSet<_> = version_iter
|
||||
.filter_map(|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,
|
||||
};
|
||||
|
@ -47,7 +47,7 @@ fn find_version<'a, V: Iterator<Item = &'a String>>(
|
|||
.iter()
|
||||
.max()
|
||||
.cloned()
|
||||
.ok_or_else(|| BinstallError::VersionMismatch { req: version_req })
|
||||
.ok_or(BinstallError::VersionMismatch { req: version_req })
|
||||
}
|
||||
|
||||
/// Fetch a crate by name and version from crates.io
|
||||
|
|
|
@ -54,14 +54,16 @@ impl MultiFetcher {
|
|||
|
||||
pub async fn first_available(&self) -> Option<&dyn Fetcher> {
|
||||
for fetcher in &self.fetchers {
|
||||
if fetcher.check().await.unwrap_or_else(|err| {
|
||||
let available = fetcher.check().await.unwrap_or_else(|err| {
|
||||
debug!(
|
||||
"Error while checking fetcher {}: {}",
|
||||
fetcher.source_name(),
|
||||
err
|
||||
);
|
||||
false
|
||||
}) {
|
||||
});
|
||||
|
||||
if available {
|
||||
return Some(&**fetcher);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -16,7 +16,7 @@ impl GhCrateMeta {
|
|||
fn url(&self) -> Result<Url, BinstallError> {
|
||||
let ctx = Context::from_data(&self.data);
|
||||
debug!("Using context: {:?}", ctx);
|
||||
Ok(ctx.render_url(&self.data.meta.pkg_url)?)
|
||||
ctx.render_url(&self.data.meta.pkg_url)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -194,7 +194,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
|
||||
|
@ -226,7 +226,7 @@ pub trait Template: Serialize {
|
|||
let mut tt = TinyTemplate::new();
|
||||
|
||||
// Add template to instance
|
||||
tt.add_template("path", &template)?;
|
||||
tt.add_template("path", template)?;
|
||||
|
||||
// Render output
|
||||
Ok(tt.render("path", self)?)
|
||||
|
|
20
src/lib.rs
20
src/lib.rs
|
@ -16,14 +16,14 @@ pub mod bins;
|
|||
pub mod fetchers;
|
||||
|
||||
/// 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 =
|
||||
pub const DEFAULT_PKG_URL: &str =
|
||||
"{ repo }/releases/download/v{ version }/{ name }-{ target }-v{ version }.{ archive-format }";
|
||||
|
||||
/// Default binary name template (may be overridden in package Cargo.toml)
|
||||
pub const DEFAULT_BIN_DIR: &'static str = "{ name }-{ target }-v{ version }/{ bin }{ binary-ext }";
|
||||
pub const DEFAULT_BIN_DIR: &str = "{ name }-{ target }-v{ version }/{ bin }{ binary-ext }";
|
||||
|
||||
/// Binary format enumeration
|
||||
#[derive(
|
||||
|
@ -113,7 +113,7 @@ impl PkgMeta {
|
|||
/// Target specific overrides for binary installation
|
||||
///
|
||||
/// Exposed via `[package.metadata.TARGET]` in `Cargo.toml`
|
||||
#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)]
|
||||
#[derive(Clone, Debug, Default, PartialEq, Serialize, Deserialize)]
|
||||
#[serde(rename_all = "kebab-case", default)]
|
||||
pub struct PkgOverride {
|
||||
/// URL template override for package downloads
|
||||
|
@ -126,16 +126,6 @@ pub struct PkgOverride {
|
|||
pub bin_dir: Option<String>,
|
||||
}
|
||||
|
||||
impl Default for PkgOverride {
|
||||
fn default() -> Self {
|
||||
Self {
|
||||
pkg_url: None,
|
||||
pkg_fmt: None,
|
||||
bin_dir: None,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)]
|
||||
#[serde(rename_all = "kebab-case")]
|
||||
pub struct BinMeta {
|
||||
|
@ -164,7 +154,7 @@ mod test {
|
|||
|
||||
let manifest = load_manifest_path(&manifest_dir).expect("Error parsing metadata");
|
||||
let package = manifest.package.unwrap();
|
||||
let meta = package.metadata.map(|m| m.binstall).flatten().unwrap();
|
||||
let meta = package.metadata.and_then(|m| m.binstall).unwrap();
|
||||
|
||||
assert_eq!(&package.name, "cargo-binstall");
|
||||
|
||||
|
|
|
@ -191,9 +191,8 @@ async fn entry() -> Result<()> {
|
|||
package
|
||||
.metadata
|
||||
.as_ref()
|
||||
.map(|m| m.binstall.clone())
|
||||
.flatten()
|
||||
.unwrap_or(PkgMeta::default()),
|
||||
.and_then(|m| m.binstall.clone())
|
||||
.unwrap_or_default(),
|
||||
manifest.bin,
|
||||
);
|
||||
|
||||
|
@ -254,6 +253,7 @@ async fn entry() -> Result<()> {
|
|||
}
|
||||
}
|
||||
|
||||
#[allow(clippy::too_many_arguments)]
|
||||
async fn install_from_package(
|
||||
binaries: Vec<Product>,
|
||||
fetcher: &dyn Fetcher,
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue