feat: arguments with clip
This commit is contained in:
parent
09250c59cb
commit
1d3895bd43
6 changed files with 85 additions and 46 deletions
|
@ -1,8 +1,9 @@
|
|||
use std::error::Error;
|
||||
use std::str::FromStr;
|
||||
|
||||
use regex::Regex;
|
||||
|
||||
#[derive(Debug)]
|
||||
#[derive(Debug, Clone)]
|
||||
pub enum PackageIdentifierError {
|
||||
InvalidPackageLocator(String),
|
||||
InvalidURI(String),
|
||||
|
@ -11,13 +12,17 @@ pub enum PackageIdentifierError {
|
|||
impl std::fmt::Display for PackageIdentifierError {
|
||||
fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
|
||||
match self {
|
||||
PackageIdentifierError::InvalidPackageLocator(s) => write!(f, "Invalid package locator: {}", s),
|
||||
PackageIdentifierError::InvalidPackageLocator(s) => {
|
||||
write!(f, "Invalid package locator: {}", s)
|
||||
}
|
||||
PackageIdentifierError::InvalidURI(s) => write!(f, "Invalid URI: {}", s),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug)]
|
||||
impl Error for PackageIdentifierError {}
|
||||
|
||||
#[derive(Debug, Clone)]
|
||||
pub enum PackageIdentifier {
|
||||
PackageLocator(PackageLocator),
|
||||
URI(String),
|
||||
|
@ -32,7 +37,7 @@ impl std::fmt::Display for PackageIdentifier {
|
|||
}
|
||||
}
|
||||
|
||||
#[derive(Debug)]
|
||||
#[derive(Debug, Clone)]
|
||||
pub struct PackageLocator {
|
||||
pub name: String,
|
||||
pub version: Option<u32>,
|
||||
|
@ -102,7 +107,14 @@ impl FromStr for PackageLocator {
|
|||
}
|
||||
|
||||
if let Some(caps) = tags_re.captures(s) {
|
||||
tags = Some(caps.get(1).unwrap().as_str().split(",").map(|s| s.to_string()).collect());
|
||||
tags = Some(
|
||||
caps.get(1)
|
||||
.unwrap()
|
||||
.as_str()
|
||||
.split(",")
|
||||
.map(|s| s.to_string())
|
||||
.collect(),
|
||||
);
|
||||
}
|
||||
|
||||
Ok(PackageLocator {
|
||||
|
@ -111,4 +123,4 @@ impl FromStr for PackageLocator {
|
|||
tags,
|
||||
})
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1 +1 @@
|
|||
pub mod identifier;
|
||||
pub mod identifier;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue