Provide unlink() CLI interface
This commit is contained in:
parent
6055520519
commit
35ac7ba927
2 changed files with 35 additions and 0 deletions
|
@ -52,6 +52,7 @@ extern crate libimagutil;
|
|||
|
||||
use std::io::Write;
|
||||
use std::path::PathBuf;
|
||||
use std::process::exit;
|
||||
|
||||
use libimagentrylink::external::ExternalLinker;
|
||||
use libimagentrylink::internal::InternalLinker;
|
||||
|
@ -99,6 +100,7 @@ fn main() {
|
|||
.map(|name| {
|
||||
match name {
|
||||
"remove" => remove_linking(&rt),
|
||||
"unlink" => unlink(&rt),
|
||||
"list" => list_linkings(&rt),
|
||||
_ => panic!("BUG"),
|
||||
}
|
||||
|
@ -224,6 +226,28 @@ fn remove_linking(rt: &Runtime) {
|
|||
});
|
||||
}
|
||||
|
||||
fn unlink(rt: &Runtime) {
|
||||
use libimagerror::iter::TraceIterator;
|
||||
use libimagstore::iter::get::StoreIdGetIteratorExtension;
|
||||
|
||||
let _ = rt
|
||||
.cli()
|
||||
.subcommand_matches("unlink")
|
||||
.unwrap() // checked in main()
|
||||
.values_of("from")
|
||||
.unwrap() // checked by clap
|
||||
.map(PathBuf::from)
|
||||
.collect::<Vec<PathBuf>>().into_iter() // for lifetime inference
|
||||
.map(StoreId::new_baseless)
|
||||
.unwrap_with(|e| { trace_error(&e); exit(1) })
|
||||
.into_get_iter(rt.store())
|
||||
.unwrap_with(|e| { trace_error(&e); exit(1) })
|
||||
.filter_map(|e| e)
|
||||
.map(|mut entry| entry.unlink(rt.store()))
|
||||
.unwrap_with(|e| { trace_error(&e); exit(1) })
|
||||
.collect::<Vec<_>>();
|
||||
}
|
||||
|
||||
fn list_linkings(rt: &Runtime) {
|
||||
let cmd = rt.cli()
|
||||
.subcommand_matches("list")
|
||||
|
|
|
@ -39,6 +39,17 @@ pub fn build_ui<'a>(app: App<'a, 'a>) -> App<'a, 'a> {
|
|||
.help("Remove links to these entries")
|
||||
.value_name("ENTRIES"))
|
||||
)
|
||||
.subcommand(SubCommand::with_name("unlink")
|
||||
.about("Remove all links from an entry")
|
||||
.version("0.1")
|
||||
.arg(Arg::with_name("from")
|
||||
.index(1)
|
||||
.takes_value(true)
|
||||
.required(true)
|
||||
.multiple(true)
|
||||
.help("Remove links from these entries")
|
||||
.value_name("ENTRY"))
|
||||
)
|
||||
|
||||
.subcommand(SubCommand::with_name("list")
|
||||
.about("List links to this entry")
|
||||
|
|
Loading…
Reference in a new issue