Skip to content

Commit

Permalink
fixed awkward semver version in issue #204
Browse files Browse the repository at this point in the history
  • Loading branch information
calvinrp committed May 2, 2024
1 parent dc0d96d commit 66206b5
Showing 1 changed file with 8 additions and 6 deletions.
14 changes: 8 additions & 6 deletions src/commands/download.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ pub struct DownloadCommand {
pub name: PackageName,
#[clap(long, short, value_name = "VERSION")]
/// The version requirement of the package to download; defaults to `*`.
pub version: Option<VersionReq>,
pub version: Option<String>,
}

impl DownloadCommand {
Expand All @@ -26,17 +26,19 @@ impl DownloadCommand {

println!("downloading package `{name}`...", name = self.name);

// if user specifies exact verion, then set the `VersionReq` to exact match
let version = match &self.version {
Some(version) => VersionReq::parse(&format!("={}", version))?,
None => VersionReq::STAR,
};

let res = client
.download(
&self.name,
self.version.as_ref().unwrap_or(&VersionReq::STAR),
)
.download(&self.name, &version)
.await?
.ok_or_else(|| {
anyhow!(
"a version of package `{name}` that satisfies `{version}` was not found",
name = self.name,
version = self.version.as_ref().unwrap_or(&VersionReq::STAR)
)
})?;

Expand Down

0 comments on commit 66206b5

Please sign in to comment.