Add is_tag clap validator helper

This commit is contained in:
Matthias Beyer 2016-09-28 19:51:21 +02:00
parent 6999f95c4d
commit d6f705dc90
1 changed files with 9 additions and 0 deletions

View File

@ -24,3 +24,12 @@ pub fn is_url(s: String) -> Result<(), String> {
Url::parse(&s).map(|_| ()).map_err(|_| format!("Not a URL: {}", s))
}
pub fn is_tag(s: String) -> Result<(), String> {
use regex::Regex;
lazy_static! { static ref TAG_RE : Regex = Regex::new("[:alpha:][:word:]*").unwrap(); }
TAG_RE
.is_match(&s)
.as_result((), format!("Not a valid Tag: '{}' - Valid is [a-zA-Z][0-9a-zA-Z]*", s))
}