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,9 +89,14 @@ 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))
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) .trace_unwrap_exit(1)
.filter(|id| collection_filter.filter(id)) .filter(|id| collection_filter.filter(id))
.filter(|id| match query_filter.as_ref() { .filter(|id| match query_filter.as_ref() {
@ -117,6 +123,6 @@ fn main() {
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)
}
}