use clap::Args;
use semver::{Error, VersionReq};
use std::{ffi::OsString, path::PathBuf, str::FromStr};
use url::Url;
use crate::options::SharedOptions;
#[derive(Debug, Args)]
pub struct AddCommand {
name_version: PackageVersion,
#[arg(long)]
path: Option<PathBuf>,
#[arg(long)]
git: Option<Url>,
#[arg(long, short = 'F')]
features: Vec<String>,
#[arg(long, default_value_t = true)]
default_features: bool,
#[command(flatten)]
options: SharedOptions,
}
#[derive(Clone, Debug)]
pub struct PackageVersion {
name: String,
version: Option<VersionReq>,
}
impl FromStr for PackageVersion {
type Err = std::io::Error;
fn from_str(s: &str) -> Result<Self, Self::Err> {
match s.split_once("=") {
Some((name, version)) => match VersionReq::from_str(version) {
Ok(o) => Ok(PackageVersion { name: name.to_string(), version: Some(o) }),
Err(e) => Err(std::io::Error::new(std::io::ErrorKind::InvalidInput, e)),
},
None => Ok(PackageVersion { name: s.to_string(), version: None }),
}
}
}
impl AddCommand {
pub(crate) fn run(&self) {
println!("{self:#?}")
}
}
#[derive(Debug, Args)]
pub struct UpdateCommand {
#[command(flatten)]
options: SharedOptions,
}
impl UpdateCommand {
pub(crate) fn run(&self) {
todo!()
}
}
#[derive(Debug, Args)]
pub struct RemoveCommand {
#[command(flatten)]
options: SharedOptions,
}
impl RemoveCommand {
pub(crate) fn run(&self) {
todo!()
}
}