Rewrite link listing to work with positional argument

This commit is contained in:
Matthias Beyer 2017-09-01 21:29:29 +02:00
parent 46dcbb828e
commit 2a20306099
2 changed files with 41 additions and 39 deletions

View File

@ -108,17 +108,18 @@ fn handle_internal_linking(rt: &Runtime) {
}
}
match cmd.value_of("list") {
Some(list) => handle_internal_linking_list_call(rt, cmd, list),
None => {
match cmd.subcommand_name() {
Some("list") => {
cmd.subcommand_matches("list")
.map(|matches| handle_internal_linking_list_call(rt, cmd, matches));
},
Some("add") => {
let (mut from, to) = get_from_to_entry(&rt, "add");
for mut to_entry in to {
if let Err(e) = to_entry.add_internal_link(&mut from) {
trace_error_exit(&e, 1);
}
}
};
},
Some("remove") => {
@ -127,21 +128,19 @@ fn handle_internal_linking(rt: &Runtime) {
if let Err(e) = to_entry.remove_internal_link(&mut from) {
trace_error_exit(&e, 1);
}
}
};
},
_ => unreachable!(),
};
}
}
}
#[inline]
fn handle_internal_linking_list_call(rt: &Runtime, cmd: &ArgMatches, list: &str) {
fn handle_internal_linking_list_call(rt: &Runtime, cmd: &ArgMatches, list: &ArgMatches) {
use libimagentrylink::external::is_external_link_storeid;
debug!("List...");
for entry in list.split(',') {
for entry in list.values_of("entries").unwrap() { // clap has our back
debug!("Listing for '{}'", entry);
match get_entry_by_name(rt, entry) {
Ok(Some(e)) => {

View File

@ -62,20 +62,23 @@ pub fn build_ui<'a>(app: App<'a, 'a>) -> App<'a, 'a> {
.value_name("ENTRIES"))
)
.arg(Arg::with_name("list")
.long("list")
.short("l")
.subcommand(SubCommand::with_name("list")
.about("List links to this entry")
.version("0.1")
.arg(Arg::with_name("entries")
.index(1)
.takes_value(true)
.required(false)
.help("List links to this entry")
.value_name("ENTRY"))
.multiple(true)
.required(true)
.help("List these entries, seperate by comma")
.value_name("ENTRIES"))
.arg(Arg::with_name("list-externals-too")
.long("list-external")
.takes_value(false)
.required(false)
.help("If --list is provided, also list external links (debugging helper that might be removed at some point"))
)
.arg(Arg::with_name("check-consistency")
.long("check-consistency")