Merge pull request #337 from matthiasbeyer/imag-link/list-implementation
Imag link/list implementation
This commit is contained in:
commit
17610efd74
2 changed files with 68 additions and 41 deletions
|
@ -62,6 +62,33 @@ fn handle_internal_linking(rt: &Runtime) {
|
|||
use libimaglink::internal::InternalLinker;
|
||||
use libimagutil::trace::trace_error;
|
||||
|
||||
debug!("Handle internal linking call");
|
||||
let cmd = rt.cli().subcommand_matches("internal").unwrap();
|
||||
|
||||
if cmd.is_present("list") {
|
||||
debug!("List...");
|
||||
for entry in cmd.value_of("list").unwrap().split(",") {
|
||||
debug!("Listing for '{}'", entry);
|
||||
match get_entry_by_name(rt, entry) {
|
||||
Ok(e) => {
|
||||
e.get_internal_links()
|
||||
.map(|links| {
|
||||
let mut i = 0;
|
||||
for link in links.iter().map(|l| l.to_str()).filter_map(|x| x) {
|
||||
println!("{: <3}: {}", i, link);
|
||||
i += 1;
|
||||
}
|
||||
});
|
||||
},
|
||||
|
||||
Err(e) => {
|
||||
trace_error(&e);
|
||||
break;
|
||||
},
|
||||
}
|
||||
}
|
||||
debug!("Listing ready!");
|
||||
} else {
|
||||
let mut from = {
|
||||
let mut from = get_from_entry(&rt);
|
||||
if from.is_none() {
|
||||
|
@ -82,7 +109,7 @@ fn handle_internal_linking(rt: &Runtime) {
|
|||
};
|
||||
debug!("Link to = {:?}", to.iter().map(|f| f.deref()).collect::<Vec<&Entry>>());
|
||||
|
||||
match rt.cli().subcommand_matches("internal").unwrap().subcommand_name() {
|
||||
match cmd.subcommand_name() {
|
||||
Some("add") => {
|
||||
for mut to_entry in to {
|
||||
if let Err(e) = to_entry.add_internal_link(&mut from) {
|
||||
|
@ -102,7 +129,7 @@ fn handle_internal_linking(rt: &Runtime) {
|
|||
},
|
||||
|
||||
_ => unreachable!(),
|
||||
// as the get_from_entry()/get_to_entries() would have errored
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -44,7 +44,7 @@ pub fn build_ui<'a>(app: App<'a, 'a>) -> App<'a, 'a> {
|
|||
.arg(Arg::with_name("list")
|
||||
.long("list")
|
||||
.short("l")
|
||||
.takes_value(false)
|
||||
.takes_value(true)
|
||||
.required(false)
|
||||
.help("List links to this entry"))
|
||||
)
|
||||
|
|
Loading…
Reference in a new issue