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

View File

@ -17,7 +17,10 @@
// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA // 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> { pub fn build_ui<'a>(app: App<'a, 'a>) -> App<'a, 'a> {
app 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")) .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)
}
}