summaryrefslogtreecommitdiffstats
path: root/bin/core/imag-tag/src/lib.rs
diff options
context:
space:
mode:
Diffstat (limited to 'bin/core/imag-tag/src/lib.rs')
-rw-r--r--bin/core/imag-tag/src/lib.rs78
1 files changed, 47 insertions, 31 deletions
diff --git a/bin/core/imag-tag/src/lib.rs b/bin/core/imag-tag/src/lib.rs
index 1a2a2b8e..83f58722 100644
--- a/bin/core/imag-tag/src/lib.rs
+++ b/bin/core/imag-tag/src/lib.rs
@@ -35,6 +35,7 @@
)]
extern crate clap;
+extern crate resiter;
#[macro_use] extern crate log;
#[cfg(test)] extern crate toml;
@@ -63,6 +64,8 @@ use std::io::Write;
use failure::Fallible as Result;
use failure::Error;
use failure::err_msg;
+use resiter::AndThen;
+use resiter::Map;
use libimagrt::runtime::Runtime;
use libimagrt::application::ImagApplication;
@@ -82,39 +85,52 @@ mod ui;
pub enum ImagTag {}
impl ImagApplication for ImagTag {
fn run(rt: Runtime) -> Result<()> {
- let ids = rt.ids::<crate::ui::PathProvider>()?
- .ok_or_else(|| err_msg("No ids supplied"))?
- .into_iter();
-
- if let Some(name) = rt.cli().subcommand_name() {
- match name {
- "list" => ids.into_iter().map(|id| list(id, &rt)).collect(),
-
- "remove" => ids.into_iter().map(|id| {
- let add = None;
- let rem = get_remove_tags(rt.cli())?;
- debug!("id = {:?}, add = {:?}, rem = {:?}", id, add, rem);
- alter(&rt, id, add, rem)
- }).collect(),
-
- "add" => ids.into_iter().map(|id| {
- let add = get_add_tags(rt.cli())?;
- let rem = None;
- debug!("id = {:?}, add = {:?}, rem = {:?}", id, add, rem);
- alter(&rt, id, add, rem)
- }).collect(),
-
- other => {
- debug!("Unknown command");
- if rt.handle_unknown_subcommand("imag-tag", other, rt.cli())?.success() {
- Ok(())
- } else {
- Err(format_err!("Subcommand failed"))
- }
- },
+ let process = |iter: &mut dyn Iterator<Item = Result<StoreId>>| -> Result<()> {
+ if let Some(name) = rt.cli().subcommand_name() {
+ match name {
+ "list" => iter
+ .map_ok(|id| list(id, &rt))
+ .collect::<Result<Vec<_>>>()
+ .map(|_| ()),
+
+ "remove" => iter.and_then_ok(|id| {
+ let add = None;
+ let rem = get_remove_tags(rt.cli())?;
+ debug!("id = {:?}, add = {:?}, rem = {:?}", id, add, rem);
+ alter(&rt, id, add, rem)
+ }).collect(),
+
+ "add" => iter.and_then_ok(|id| {
+ let add = get_add_tags(rt.cli())?;
+ let rem = None;
+ debug!("id = {:?}, add = {:?}, rem = {:?}", id, add, rem);
+ alter(&rt, id, add, rem)
+ }).collect(),
+
+ other => {
+ debug!("Unknown command");
+ if rt.handle_unknown_subcommand("imag-tag", other, rt.cli())?.success() {
+ Ok(())
+ } else {
+ Err(format_err!("Subcommand failed"))
+ }
+ },
+ }
+ } else {
+ Ok(())
}
+ };
+
+ if rt.ids_from_stdin() {
+ debug!("Fetching IDs from stdin...");
+ let mut iter = rt.ids::<crate::ui::PathProvider>()?
+ .ok_or_else(|| err_msg("No ids supplied"))?
+ .into_iter()
+ .map(Ok);
+
+ process(&mut iter)
} else {
- Ok(())
+ process(&mut rt.store().entries()?)
}
}