Rewrite BMModule::get_filtered_files_from_backend() with the backend speaking Result<> now instead of Option<>
This commit is contained in:
parent
40ae26d0f2
commit
04df3fdf3c
1 changed files with 48 additions and 41 deletions
|
@ -66,7 +66,7 @@ pub fn remove_command(module: &Module, env: CommandEnv) -> CommandResult {
|
|||
} else {
|
||||
debug!("Remove more than one file");
|
||||
|
||||
let files = get_filtered_files_from_backend(module, &env);
|
||||
get_filtered_files_from_backend(module, &env).and_then(|files| {
|
||||
let nfiles = files.len();
|
||||
info!("Removing {} Files", nfiles);
|
||||
|
||||
|
@ -94,6 +94,7 @@ pub fn remove_command(module: &Module, env: CommandEnv) -> CommandResult {
|
|||
} else {
|
||||
Ok(())
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -104,12 +105,14 @@ pub fn remove_command(module: &Module, env: CommandEnv) -> CommandResult {
|
|||
*/
|
||||
|
||||
fn get_filtered_files_from_backend<'a>(module: &'a Module,
|
||||
env: &CommandEnv) -> IntoIter<File<'a>>
|
||||
env: &CommandEnv)
|
||||
-> Result<IntoIter<File<'a>>, ModuleError>
|
||||
{
|
||||
let parser = Parser::new(JsonHeaderParser::new(None));
|
||||
let tags = get_tags(env.rt, env.matches);
|
||||
debug!("Tags: {:?}", tags);
|
||||
env.bk.iter_files(module, &parser).and_then(|files| {
|
||||
env.bk.iter_files(module, &parser)
|
||||
.map(|files| {
|
||||
let f = files.filter(|file| {
|
||||
if tags.len() != 0 {
|
||||
debug!("Checking tags of: {:?}", file.id());
|
||||
|
@ -124,8 +127,12 @@ fn get_filtered_files_from_backend<'a>(module: &'a Module,
|
|||
.and_then(|r| Some(file.matches_with(&r)))
|
||||
.unwrap_or(true)
|
||||
}).collect::<Vec<File>>();
|
||||
Some(f)
|
||||
}).unwrap_or(Vec::<File>::new()).into_iter()
|
||||
f.into_iter()
|
||||
}).map_err(|e| {
|
||||
let mut merr = ModuleError::new("Could not filter files");
|
||||
merr.caused_by = Some(Box::new(e));
|
||||
merr
|
||||
})
|
||||
}
|
||||
|
||||
fn get_tags<'a>(rt: &Runtime, sub: &ArgMatches<'a, 'a>) -> Vec<String> {
|
||||
|
|
Loading…
Reference in a new issue