Move imag-ids to ID provider infrastructure

This commit is contained in:
Matthias Beyer 2018-09-29 17:44:36 +02:00
parent a805db2a88
commit 70014e04b1
2 changed files with 46 additions and 30 deletions

View File

@ -53,6 +53,7 @@ use std::process::exit;
use filters::filter::Filter;
use libimagstore::storeid::StoreId;
use libimagrt::setup::generate_runtime_setup;
use libimagerror::trace::MapErrTrace;
use libimagerror::iter::TraceIterator;
@ -88,35 +89,40 @@ fn main() {
id_filters::header_filter_lang::parse(&query)
});
rt.store()
.entries()
.map_err_trace_exit_unwrap(1)
.trace_unwrap_exit(1)
.filter(|id| collection_filter.filter(id))
.filter(|id| match query_filter.as_ref() {
None => true,
Some(qf) => {
let entry = rt
.store()
.get(id.clone())
.map_err_trace_exit_unwrap(1)
.unwrap_or_else(|| {
error!("Tried to get '{}', but it does not exist!", id);
exit(1)
});
if rt.ids_from_stdin() {
let ids = rt.ids::<::ui::PathProvider>().map_err_trace_exit_unwrap(1);
Box::new(ids.into_iter().map(Ok))
as Box<Iterator<Item = Result<StoreId, _>>>
} else {
Box::new(rt.store().entries().map_err_trace_exit_unwrap(1))
as Box<Iterator<Item = Result<StoreId, _>>>
}
.trace_unwrap_exit(1)
.filter(|id| collection_filter.filter(id))
.filter(|id| match query_filter.as_ref() {
None => true,
Some(qf) => {
let entry = rt
.store()
.get(id.clone())
.map_err_trace_exit_unwrap(1)
.unwrap_or_else(|| {
error!("Tried to get '{}', but it does not exist!", id);
exit(1)
});
qf.filter(&entry)
}
})
.map(|id| if print_storepath {
id
} else {
id.without_base()
})
.for_each(|id| {
let _ = writeln!(rt.stdout(), "{}", id.to_str().map_err_trace_exit_unwrap(1))
.to_exit_code()
.unwrap_or_exit();
})
qf.filter(&entry)
}
})
.map(|id| if print_storepath {
id
} else {
id.without_base()
})
.for_each(|id| {
let _ = writeln!(rt.stdout(), "{}", id.to_str().map_err_trace_exit_unwrap(1))
.to_exit_code()
.unwrap_or_exit();
});
}

View File

@ -17,7 +17,10 @@
// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
//
use clap::{Arg, App, SubCommand};
use clap::{Arg, ArgMatches, App, SubCommand};
use libimagstore::storeid::StoreId;
use libimagrt::runtime::IdPathProvider;
pub fn build_ui<'a>(app: App<'a, 'a>) -> App<'a, 'a> {
app
@ -49,3 +52,10 @@ pub fn build_ui<'a>(app: App<'a, 'a>) -> App<'a, 'a> {
.after_help(include_str!("../static/language-doc.md"))
}
pub struct PathProvider;
impl IdPathProvider for PathProvider {
fn get_ids(_matches: &ArgMatches) -> Vec<StoreId> {
error!("imag-ids does not get IDs via CLI, only via stdin if applying a filter!");
::std::process::exit(1)
}
}