This commit is contained in:
parent
a689abbc5d
commit
c12b78b3c1
9 changed files with 157 additions and 38 deletions
|
@ -128,3 +128,36 @@ impl FromStr for PackageLocator {
|
|||
})
|
||||
}
|
||||
}
|
||||
|
||||
impl From<(String, String)> for PackageLocator {
|
||||
fn from((name, locate_str): (String, String)) -> Self {
|
||||
// name = "pkg"
|
||||
// locate_str = "1.0.0:tag1,tag2" or "1.0.0" or "tag1,tag2"
|
||||
let mut version = None;
|
||||
let mut tags = None;
|
||||
|
||||
let version_re = Regex::new("^([0-9]+)").unwrap();
|
||||
let tags_re = Regex::new("^:([a-zA-Z0-9,._]+)").unwrap();
|
||||
|
||||
if let Some(caps) = version_re.captures(locate_str.as_str()) {
|
||||
version = Some(caps.get(1).unwrap().as_str().parse::<u32>().unwrap());
|
||||
}
|
||||
|
||||
if let Some(caps) = tags_re.captures(locate_str.as_str()) {
|
||||
tags = Some(
|
||||
caps.get(1)
|
||||
.unwrap()
|
||||
.as_str()
|
||||
.split(",")
|
||||
.map(|s| s.to_string())
|
||||
.collect(),
|
||||
);
|
||||
}
|
||||
|
||||
PackageLocator {
|
||||
name,
|
||||
version,
|
||||
tags,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue