Refactor get_tags to return no Option
This commit is contained in:
parent
51f6af6346
commit
006724a184
1 changed files with 10 additions and 13 deletions
|
@ -61,7 +61,7 @@ impl Module for BMModule {
|
||||||
fn add<'a>(rt: &Runtime, sub: &ArgMatches<'a, 'a>) -> ModuleResult {
|
fn add<'a>(rt: &Runtime, sub: &ArgMatches<'a, 'a>) -> ModuleResult {
|
||||||
let url = sub.value_of("url").unwrap();
|
let url = sub.value_of("url").unwrap();
|
||||||
let tags = get_tags(rt, sub);
|
let tags = get_tags(rt, sub);
|
||||||
info!("Adding url '{}' with tags '{:?}'", url, tags.unwrap_or(vec!()));
|
info!("Adding url '{}' with tags '{:?}'", url, tags);
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
@ -74,10 +74,10 @@ fn list<'a>(rt: &Runtime, sub: &ArgMatches<'a, 'a>) -> ModuleResult {
|
||||||
Some(reg) => {
|
Some(reg) => {
|
||||||
info!("Listing urls with matcher '{}' and with tags {:?}",
|
info!("Listing urls with matcher '{}' and with tags {:?}",
|
||||||
reg.as_str(),
|
reg.as_str(),
|
||||||
tags.unwrap_or(vec!()));
|
tags);
|
||||||
}
|
}
|
||||||
None => {
|
None => {
|
||||||
info!("Listing urls with tags {:?}", tags.unwrap_or(vec!()));
|
info!("Listing urls with tags {:?}", tags);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -97,11 +97,10 @@ fn remove<'a>(rt: &Runtime, sub: &ArgMatches<'a, 'a>) -> ModuleResult {
|
||||||
match matcher {
|
match matcher {
|
||||||
Some(reg) => {
|
Some(reg) => {
|
||||||
info!("Removing urls with matcher '{}' and with tags {:?}",
|
info!("Removing urls with matcher '{}' and with tags {:?}",
|
||||||
reg.as_str(),
|
reg.as_str(), tags);
|
||||||
tags.unwrap_or(vec!()));
|
|
||||||
}
|
}
|
||||||
None => {
|
None => {
|
||||||
info!("Listing urls with tags {:?}", tags.unwrap_or(vec!()));
|
info!("Listing urls with tags {:?}", tags);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -110,23 +109,21 @@ fn remove<'a>(rt: &Runtime, sub: &ArgMatches<'a, 'a>) -> ModuleResult {
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
fn get_tags<'a>(rt: &Runtime, sub: &ArgMatches<'a, 'a>) -> Option<Vec<String>> {
|
fn get_tags<'a>(rt: &Runtime, sub: &ArgMatches<'a, 'a>) -> Vec<String> {
|
||||||
debug!("Fetching tags from commandline");
|
debug!("Fetching tags from commandline");
|
||||||
sub.value_of("tags").and_then(|tags|
|
sub.value_of("tags").and_then(|tags|
|
||||||
Some(tags.split(",")
|
Some(tags.split(",")
|
||||||
.collect::<Vec<_>>()
|
.into_iter()
|
||||||
.iter()
|
.map(|s| s.to_string())
|
||||||
.filter(|e|
|
.filter(|e|
|
||||||
if e.contains(" ") {
|
if e.contains(" ") {
|
||||||
warn!("Tag contains spaces: '{}'", e);
|
warn!("Tag contains spaces: '{}'", e);
|
||||||
true
|
true
|
||||||
} else {
|
} else {
|
||||||
false
|
false
|
||||||
})
|
}).collect()
|
||||||
.map(|s| s.to_string())
|
|
||||||
.collect()
|
|
||||||
)
|
|
||||||
)
|
)
|
||||||
|
).or(Some(vec![])).unwrap()
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue