Add support for piping entry ids into command
This commit is contained in:
parent
1d5171d770
commit
5061faaa74
2 changed files with 48 additions and 14 deletions
|
@ -46,6 +46,7 @@ extern crate libimagstore;
|
||||||
|
|
||||||
use std::collections::BTreeMap;
|
use std::collections::BTreeMap;
|
||||||
use std::io::Write;
|
use std::io::Write;
|
||||||
|
use std::io::Read;
|
||||||
use std::path::PathBuf;
|
use std::path::PathBuf;
|
||||||
use std::process::Command;
|
use std::process::Command;
|
||||||
use std::process::exit;
|
use std::process::exit;
|
||||||
|
@ -187,13 +188,35 @@ fn main() {
|
||||||
}
|
}
|
||||||
|
|
||||||
fn entry_ids(rt: &Runtime) -> Vec<StoreId> {
|
fn entry_ids(rt: &Runtime) -> Vec<StoreId> {
|
||||||
rt.cli()
|
match rt.cli().values_of("id") {
|
||||||
.values_of("id")
|
Some(pathes) => pathes
|
||||||
.unwrap() // enforced by clap
|
.map(PathBuf::from)
|
||||||
|
.map(PathBuf::into_storeid)
|
||||||
|
.trace_unwrap_exit(1)
|
||||||
|
.collect(),
|
||||||
|
|
||||||
|
None => if rt.cli().is_present("entries-from-stdin") {
|
||||||
|
let stdin = rt.stdin().unwrap_or_else(|| {
|
||||||
|
error!("Cannot get handle to stdin");
|
||||||
|
::std::process::exit(1)
|
||||||
|
});
|
||||||
|
|
||||||
|
let mut buf = String::new();
|
||||||
|
let _ = stdin.lock().read_to_string(&mut buf).unwrap_or_else(|_| {
|
||||||
|
error!("Failed to read from stdin");
|
||||||
|
::std::process::exit(1)
|
||||||
|
});
|
||||||
|
|
||||||
|
buf.lines()
|
||||||
.map(PathBuf::from)
|
.map(PathBuf::from)
|
||||||
.map(PathBuf::into_storeid)
|
.map(PathBuf::into_storeid)
|
||||||
.trace_unwrap_exit(1)
|
.trace_unwrap_exit(1)
|
||||||
.collect()
|
.collect()
|
||||||
|
} else {
|
||||||
|
error!("Something weird happened. I was not able to find the path of the entries to edit");
|
||||||
|
::std::process::exit(1)
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn create_tempfile_for<'a>(entry: &FileLockEntry<'a>, view_header: bool, hide_content: bool)
|
fn create_tempfile_for<'a>(entry: &FileLockEntry<'a>, view_header: bool, hide_content: bool)
|
||||||
|
|
|
@ -17,17 +17,28 @@
|
||||||
// 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, ArgGroup, App, SubCommand};
|
||||||
|
|
||||||
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
|
||||||
|
.arg(Arg::with_name("entries-from-stdin")
|
||||||
|
.long("ids-from-stdin")
|
||||||
|
.short("I")
|
||||||
|
.required(false)
|
||||||
|
.multiple(true)
|
||||||
|
.help("The entry/entries are piped in via stdin"))
|
||||||
|
|
||||||
.arg(Arg::with_name("id")
|
.arg(Arg::with_name("id")
|
||||||
.index(1)
|
.index(1)
|
||||||
.takes_value(true)
|
.takes_value(true)
|
||||||
.required(true)
|
.required(false)
|
||||||
.multiple(true)
|
.multiple(true)
|
||||||
.help("View this entry at this store path")
|
.help("View these entries at this store path")
|
||||||
.value_name("ID"))
|
.value_name("IDs"))
|
||||||
|
|
||||||
|
.group(ArgGroup::with_name("input-method")
|
||||||
|
.args(&["id", "entries-from-stdin"])
|
||||||
|
.required(true))
|
||||||
|
|
||||||
.arg(Arg::with_name("view-header")
|
.arg(Arg::with_name("view-header")
|
||||||
.long("header")
|
.long("header")
|
||||||
|
|
Loading…
Reference in a new issue