#![deny(missing_docs)]
use anyhow::Context;
use semver::VersionReq;
use std::str::FromStr;
use warg_protocol::registry::PackageName;
pub mod command;
pub mod lock;
pub mod progress;
pub mod registry;
pub mod terminal;
#[derive(Clone)]
pub struct VersionedPackageName {
pub name: PackageName,
pub version: Option<VersionReq>,
}
impl FromStr for VersionedPackageName {
type Err = anyhow::Error;
fn from_str(s: &str) -> std::result::Result<Self, Self::Err> {
match s.split_once('@') {
Some((name, version)) => Ok(Self {
name: name.parse()?,
version: Some(
version
.parse()
.with_context(|| format!("invalid package version `{version}`"))?,
),
}),
None => Ok(Self {
name: s.parse()?,
version: None,
}),
}
}
}