vpp 0.0.1

Valkyie Package Portal
Documentation
use clap::Args;
use semver::{Error, VersionReq};
use std::{ffi::OsString, path::PathBuf, str::FromStr};
use url::Url;

use crate::options::SharedOptions;

/// Add a
#[derive(Debug, Args)]
pub struct AddCommand {
    /// Reference to a package to add as a dependency
    name_version: PackageVersion,
    /// Filesystem path to local crate to add
    #[arg(long)]
    path: Option<PathBuf>,
    /// Git repository location
    #[arg(long)]
    git: Option<Url>,
    // Space or comma separated list of features to activate
    #[arg(long, short = 'F')]
    features: Vec<String>,
    /// Weather to enable the default features (default = true)
    #[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!()
    }
}