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

View file

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