Rewrite to accept ids from stdin
Signed-off-by: Matthias Beyer <mail@beyermatthias.de>
This commit is contained in:
parent
9dc345c833
commit
fae53aa134
2 changed files with 45 additions and 28 deletions
|
@ -23,6 +23,7 @@ maintenance = { status = "actively-developed" }
|
||||||
log = "0.4.6"
|
log = "0.4.6"
|
||||||
toml = "0.5.1"
|
toml = "0.5.1"
|
||||||
failure = "0.1.5"
|
failure = "0.1.5"
|
||||||
|
resiter = "0.4.0"
|
||||||
|
|
||||||
libimagstore = { version = "0.10.0", path = "../../../lib/core/libimagstore" }
|
libimagstore = { version = "0.10.0", path = "../../../lib/core/libimagstore" }
|
||||||
libimagrt = { version = "0.10.0", path = "../../../lib/core/libimagrt" }
|
libimagrt = { version = "0.10.0", path = "../../../lib/core/libimagrt" }
|
||||||
|
|
|
@ -35,6 +35,7 @@
|
||||||
)]
|
)]
|
||||||
|
|
||||||
extern crate clap;
|
extern crate clap;
|
||||||
|
extern crate resiter;
|
||||||
#[macro_use] extern crate log;
|
#[macro_use] extern crate log;
|
||||||
|
|
||||||
#[cfg(test)] extern crate toml;
|
#[cfg(test)] extern crate toml;
|
||||||
|
@ -63,6 +64,8 @@ use std::io::Write;
|
||||||
use failure::Fallible as Result;
|
use failure::Fallible as Result;
|
||||||
use failure::Error;
|
use failure::Error;
|
||||||
use failure::err_msg;
|
use failure::err_msg;
|
||||||
|
use resiter::AndThen;
|
||||||
|
use resiter::Map;
|
||||||
|
|
||||||
use libimagrt::runtime::Runtime;
|
use libimagrt::runtime::Runtime;
|
||||||
use libimagrt::application::ImagApplication;
|
use libimagrt::application::ImagApplication;
|
||||||
|
@ -82,22 +85,22 @@ mod ui;
|
||||||
pub enum ImagTag {}
|
pub enum ImagTag {}
|
||||||
impl ImagApplication for ImagTag {
|
impl ImagApplication for ImagTag {
|
||||||
fn run(rt: Runtime) -> Result<()> {
|
fn run(rt: Runtime) -> Result<()> {
|
||||||
let ids = rt.ids::<crate::ui::PathProvider>()?
|
let process = |iter: &mut dyn Iterator<Item = Result<StoreId>>| -> Result<()> {
|
||||||
.ok_or_else(|| err_msg("No ids supplied"))?
|
|
||||||
.into_iter();
|
|
||||||
|
|
||||||
if let Some(name) = rt.cli().subcommand_name() {
|
if let Some(name) = rt.cli().subcommand_name() {
|
||||||
match name {
|
match name {
|
||||||
"list" => ids.into_iter().map(|id| list(id, &rt)).collect(),
|
"list" => iter
|
||||||
|
.map_ok(|id| list(id, &rt))
|
||||||
|
.collect::<Result<Vec<_>>>()
|
||||||
|
.map(|_| ()),
|
||||||
|
|
||||||
"remove" => ids.into_iter().map(|id| {
|
"remove" => iter.and_then_ok(|id| {
|
||||||
let add = None;
|
let add = None;
|
||||||
let rem = get_remove_tags(rt.cli())?;
|
let rem = get_remove_tags(rt.cli())?;
|
||||||
debug!("id = {:?}, add = {:?}, rem = {:?}", id, add, rem);
|
debug!("id = {:?}, add = {:?}, rem = {:?}", id, add, rem);
|
||||||
alter(&rt, id, add, rem)
|
alter(&rt, id, add, rem)
|
||||||
}).collect(),
|
}).collect(),
|
||||||
|
|
||||||
"add" => ids.into_iter().map(|id| {
|
"add" => iter.and_then_ok(|id| {
|
||||||
let add = get_add_tags(rt.cli())?;
|
let add = get_add_tags(rt.cli())?;
|
||||||
let rem = None;
|
let rem = None;
|
||||||
debug!("id = {:?}, add = {:?}, rem = {:?}", id, add, rem);
|
debug!("id = {:?}, add = {:?}, rem = {:?}", id, add, rem);
|
||||||
|
@ -116,6 +119,19 @@ impl ImagApplication for ImagTag {
|
||||||
} else {
|
} else {
|
||||||
Ok(())
|
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 {
|
||||||
|
process(&mut rt.store().entries()?)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn build_cli<'a>(app: App<'a, 'a>) -> App<'a, 'a> {
|
fn build_cli<'a>(app: App<'a, 'a>) -> App<'a, 'a> {
|
||||||
|
|
Loading…
Reference in a new issue