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,47 +62,74 @@ fn handle_internal_linking(rt: &Runtime) {
|
||||||
use libimaglink::internal::InternalLinker;
|
use libimaglink::internal::InternalLinker;
|
||||||
use libimagutil::trace::trace_error;
|
use libimagutil::trace::trace_error;
|
||||||
|
|
||||||
let mut from = {
|
debug!("Handle internal linking call");
|
||||||
let mut from = get_from_entry(&rt);
|
let cmd = rt.cli().subcommand_matches("internal").unwrap();
|
||||||
if from.is_none() {
|
|
||||||
warn!("No 'from' entry");
|
|
||||||
exit(1);
|
|
||||||
}
|
|
||||||
from.unwrap()
|
|
||||||
};
|
|
||||||
debug!("Link from = {:?}", from.deref());
|
|
||||||
|
|
||||||
let mut to = {
|
if cmd.is_present("list") {
|
||||||
let mut to = get_to_entries(&rt);
|
debug!("List...");
|
||||||
if to.is_none() {
|
for entry in cmd.value_of("list").unwrap().split(",") {
|
||||||
warn!("No 'to' entry");
|
debug!("Listing for '{}'", entry);
|
||||||
exit(1);
|
match get_entry_by_name(rt, entry) {
|
||||||
}
|
Ok(e) => {
|
||||||
to.unwrap()
|
e.get_internal_links()
|
||||||
};
|
.map(|links| {
|
||||||
debug!("Link to = {:?}", to.iter().map(|f| f.deref()).collect::<Vec<&Entry>>());
|
let mut i = 0;
|
||||||
|
for link in links.iter().map(|l| l.to_str()).filter_map(|x| x) {
|
||||||
|
println!("{: <3}: {}", i, link);
|
||||||
|
i += 1;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
},
|
||||||
|
|
||||||
match rt.cli().subcommand_matches("internal").unwrap().subcommand_name() {
|
Err(e) => {
|
||||||
Some("add") => {
|
|
||||||
for mut to_entry in to {
|
|
||||||
if let Err(e) = to_entry.add_internal_link(&mut from) {
|
|
||||||
trace_error(&e);
|
trace_error(&e);
|
||||||
exit(1);
|
break;
|
||||||
}
|
},
|
||||||
}
|
}
|
||||||
},
|
}
|
||||||
|
debug!("Listing ready!");
|
||||||
Some("remove") => {
|
} else {
|
||||||
for mut to_entry in to {
|
let mut from = {
|
||||||
if let Err(e) = to_entry.remove_internal_link(&mut from) {
|
let mut from = get_from_entry(&rt);
|
||||||
trace_error(&e);
|
if from.is_none() {
|
||||||
exit(1);
|
warn!("No 'from' entry");
|
||||||
}
|
exit(1);
|
||||||
}
|
}
|
||||||
},
|
from.unwrap()
|
||||||
|
};
|
||||||
|
debug!("Link from = {:?}", from.deref());
|
||||||
|
|
||||||
_ => unreachable!(),
|
let mut to = {
|
||||||
// as the get_from_entry()/get_to_entries() would have errored
|
let mut to = get_to_entries(&rt);
|
||||||
|
if to.is_none() {
|
||||||
|
warn!("No 'to' entry");
|
||||||
|
exit(1);
|
||||||
|
}
|
||||||
|
to.unwrap()
|
||||||
|
};
|
||||||
|
debug!("Link to = {:?}", to.iter().map(|f| f.deref()).collect::<Vec<&Entry>>());
|
||||||
|
|
||||||
|
match cmd.subcommand_name() {
|
||||||
|
Some("add") => {
|
||||||
|
for mut to_entry in to {
|
||||||
|
if let Err(e) = to_entry.add_internal_link(&mut from) {
|
||||||
|
trace_error(&e);
|
||||||
|
exit(1);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
|
||||||
|
Some("remove") => {
|
||||||
|
for mut to_entry in to {
|
||||||
|
if let Err(e) = to_entry.remove_internal_link(&mut from) {
|
||||||
|
trace_error(&e);
|
||||||
|
exit(1);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
|
||||||
|
_ => unreachable!(),
|
||||||
|
};
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -41,12 +41,12 @@ pub fn build_ui<'a>(app: App<'a, 'a>) -> App<'a, 'a> {
|
||||||
.help("Remove links to these entries"))
|
.help("Remove links to these entries"))
|
||||||
)
|
)
|
||||||
|
|
||||||
.arg(Arg::with_name("list")
|
.arg(Arg::with_name("list")
|
||||||
.long("list")
|
.long("list")
|
||||||
.short("l")
|
.short("l")
|
||||||
.takes_value(false)
|
.takes_value(true)
|
||||||
.required(false)
|
.required(false)
|
||||||
.help("List links to this entry"))
|
.help("List links to this entry"))
|
||||||
)
|
)
|
||||||
.subcommand(SubCommand::with_name("external")
|
.subcommand(SubCommand::with_name("external")
|
||||||
.about("Add and remove external links")
|
.about("Add and remove external links")
|
||||||
|
|
Loading…
Reference in a new issue