mirror of
https://github.com/cargo-bins/cargo-binstall.git
synced 2025-04-22 21:48:42 +00:00
Use VersionReq
for Options::version_req
and update usage of
`CrateName` in `binstall::install` Signed-off-by: Jiahao XU <Jiahao_XU@outlook.com>
This commit is contained in:
parent
686cae6ae8
commit
065f62a625
4 changed files with 21 additions and 24 deletions
|
@ -1,6 +1,6 @@
|
||||||
use std::path::PathBuf;
|
use std::path::PathBuf;
|
||||||
|
|
||||||
use compact_str::CompactString;
|
use semver::VersionReq;
|
||||||
|
|
||||||
use crate::{metafiles::binstall_v1::MetaData, DesiredTargets, PkgOverride};
|
use crate::{metafiles::binstall_v1::MetaData, DesiredTargets, PkgOverride};
|
||||||
|
|
||||||
|
@ -14,7 +14,7 @@ pub struct Options {
|
||||||
pub no_symlinks: bool,
|
pub no_symlinks: bool,
|
||||||
pub dry_run: bool,
|
pub dry_run: bool,
|
||||||
pub force: bool,
|
pub force: bool,
|
||||||
pub version: Option<CompactString>,
|
pub version_req: Option<VersionReq>,
|
||||||
pub manifest_path: Option<PathBuf>,
|
pub manifest_path: Option<PathBuf>,
|
||||||
pub cli_overrides: PkgOverride,
|
pub cli_overrides: PkgOverride,
|
||||||
pub desired_targets: DesiredTargets,
|
pub desired_targets: DesiredTargets,
|
||||||
|
|
|
@ -19,7 +19,7 @@ pub async fn install(
|
||||||
fetcher,
|
fetcher,
|
||||||
package,
|
package,
|
||||||
name,
|
name,
|
||||||
version,
|
version_req,
|
||||||
bin_path,
|
bin_path,
|
||||||
bin_files,
|
bin_files,
|
||||||
} => {
|
} => {
|
||||||
|
@ -31,7 +31,7 @@ pub async fn install(
|
||||||
.map(|option| {
|
.map(|option| {
|
||||||
option.map(|bins| MetaData {
|
option.map(|bins| MetaData {
|
||||||
name,
|
name,
|
||||||
version_req: version,
|
version_req,
|
||||||
current_version,
|
current_version,
|
||||||
source: Source::cratesio_registry(),
|
source: Source::cratesio_registry(),
|
||||||
target,
|
target,
|
||||||
|
|
|
@ -4,10 +4,11 @@ use std::{
|
||||||
};
|
};
|
||||||
|
|
||||||
use cargo_toml::{Package, Product};
|
use cargo_toml::{Package, Product};
|
||||||
use compact_str::{format_compact, CompactString};
|
use compact_str::{CompactString, ToCompactString};
|
||||||
use log::{debug, error, info, warn};
|
use log::{debug, error, info, warn};
|
||||||
use miette::{miette, Result};
|
use miette::{miette, Result};
|
||||||
use reqwest::Client;
|
use reqwest::Client;
|
||||||
|
use semver::VersionReq;
|
||||||
|
|
||||||
use super::Options;
|
use super::Options;
|
||||||
use crate::{
|
use crate::{
|
||||||
|
@ -21,7 +22,7 @@ pub enum Resolution {
|
||||||
fetcher: Arc<dyn Fetcher>,
|
fetcher: Arc<dyn Fetcher>,
|
||||||
package: Package<Meta>,
|
package: Package<Meta>,
|
||||||
name: CompactString,
|
name: CompactString,
|
||||||
version: CompactString,
|
version_req: CompactString,
|
||||||
bin_path: PathBuf,
|
bin_path: PathBuf,
|
||||||
bin_files: Vec<bins::BinFile>,
|
bin_files: Vec<bins::BinFile>,
|
||||||
},
|
},
|
||||||
|
@ -83,30 +84,26 @@ pub async fn resolve(
|
||||||
) -> Result<Resolution> {
|
) -> Result<Resolution> {
|
||||||
info!("Installing package: '{}'", crate_name);
|
info!("Installing package: '{}'", crate_name);
|
||||||
|
|
||||||
let mut version: CompactString = match (&crate_name.version, &opts.version) {
|
let version_req: VersionReq = match (&crate_name.version_req, &opts.version_req) {
|
||||||
(Some(version), None) => version.clone(),
|
(Some(version), None) => version.clone(),
|
||||||
(None, Some(version)) => version.clone(),
|
(None, Some(version)) => version.clone(),
|
||||||
(Some(_), Some(_)) => Err(BinstallError::SuperfluousVersionOption)?,
|
(Some(_), Some(_)) => Err(BinstallError::SuperfluousVersionOption)?,
|
||||||
(None, None) => "*".into(),
|
(None, None) => VersionReq::STAR,
|
||||||
};
|
};
|
||||||
|
|
||||||
// Treat 0.1.2 as =0.1.2
|
|
||||||
if version
|
|
||||||
.chars()
|
|
||||||
.next()
|
|
||||||
.map(|ch| ch.is_ascii_digit())
|
|
||||||
.unwrap_or(false)
|
|
||||||
{
|
|
||||||
version = format_compact!("={version}");
|
|
||||||
}
|
|
||||||
|
|
||||||
// Fetch crate via crates.io, git, or use a local manifest path
|
// Fetch crate via crates.io, git, or use a local manifest path
|
||||||
// TODO: work out which of these to do based on `opts.name`
|
// TODO: work out which of these to do based on `opts.name`
|
||||||
// TODO: support git-based fetches (whole repo name rather than just crate name)
|
// TODO: support git-based fetches (whole repo name rather than just crate name)
|
||||||
let manifest = match opts.manifest_path.clone() {
|
let manifest = match opts.manifest_path.clone() {
|
||||||
Some(manifest_path) => load_manifest_path(manifest_path)?,
|
Some(manifest_path) => load_manifest_path(manifest_path)?,
|
||||||
None => {
|
None => {
|
||||||
fetch_crate_cratesio(&client, &crates_io_api_client, &crate_name.name, &version).await?
|
fetch_crate_cratesio(
|
||||||
|
&client,
|
||||||
|
&crates_io_api_client,
|
||||||
|
&crate_name.name,
|
||||||
|
&version_req,
|
||||||
|
)
|
||||||
|
.await?
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -175,7 +172,7 @@ pub async fn resolve(
|
||||||
fetcher,
|
fetcher,
|
||||||
package,
|
package,
|
||||||
name: crate_name.name,
|
name: crate_name.name,
|
||||||
version,
|
version_req: version_req.to_compact_string(),
|
||||||
bin_path,
|
bin_path,
|
||||||
bin_files,
|
bin_files,
|
||||||
}
|
}
|
||||||
|
|
|
@ -9,9 +9,9 @@ use std::{
|
||||||
};
|
};
|
||||||
|
|
||||||
use clap::{builder::PossibleValue, AppSettings, Parser};
|
use clap::{builder::PossibleValue, AppSettings, Parser};
|
||||||
use compact_str::CompactString;
|
|
||||||
use log::{debug, error, info, warn, LevelFilter};
|
use log::{debug, error, info, warn, LevelFilter};
|
||||||
use miette::{miette, Result, WrapErr};
|
use miette::{miette, Result, WrapErr};
|
||||||
|
use semver::VersionReq;
|
||||||
use simplelog::{ColorChoice, ConfigBuilder, TermLogger, TerminalMode};
|
use simplelog::{ColorChoice, ConfigBuilder, TermLogger, TerminalMode};
|
||||||
use tokio::{runtime::Runtime, task::block_in_place};
|
use tokio::{runtime::Runtime, task::block_in_place};
|
||||||
|
|
||||||
|
@ -46,8 +46,8 @@ struct Options {
|
||||||
///
|
///
|
||||||
/// Cannot be used when multiple packages are installed at once, use the attached version
|
/// Cannot be used when multiple packages are installed at once, use the attached version
|
||||||
/// syntax in that case.
|
/// syntax in that case.
|
||||||
#[clap(help_heading = "Package selection", long = "version")]
|
#[clap(help_heading = "Package selection", long = "version", parse(try_from_str = parse_version))]
|
||||||
version_req: Option<CompactString>,
|
version_req: Option<VersionReq>,
|
||||||
|
|
||||||
/// Override binary target set.
|
/// Override binary target set.
|
||||||
///
|
///
|
||||||
|
@ -371,7 +371,7 @@ async fn entry(jobserver_client: LazyJobserverClient) -> Result<()> {
|
||||||
no_symlinks: opts.no_symlinks,
|
no_symlinks: opts.no_symlinks,
|
||||||
dry_run: opts.dry_run,
|
dry_run: opts.dry_run,
|
||||||
force: opts.force,
|
force: opts.force,
|
||||||
version: opts.version_req.take(),
|
version_req: opts.version_req.take(),
|
||||||
manifest_path: opts.manifest_path.take(),
|
manifest_path: opts.manifest_path.take(),
|
||||||
cli_overrides,
|
cli_overrides,
|
||||||
desired_targets,
|
desired_targets,
|
||||||
|
|
Loading…
Add table
Reference in a new issue