Merge branch 'imag-link-direction' into master

This commit is contained in:
Matthias Beyer 2019-11-02 17:50:08 +01:00
commit 1f858cf4bd
2 changed files with 15 additions and 1 deletions

View file

@ -140,6 +140,7 @@ fn get_entry_by_name<'a>(rt: &'a Runtime, name: &str) -> Result<Option<FileLockE
fn link_from_to<'a, I>(rt: &'a Runtime, from: &'a str, to: I) -> Result<()> fn link_from_to<'a, I>(rt: &'a Runtime, from: &'a str, to: I) -> Result<()>
where I: Iterator<Item = &'a str> where I: Iterator<Item = &'a str>
{ {
let directional = rt.cli().is_present("directional");
let mut from_entry = get_entry_by_name(rt, from)?.ok_or_else(|| err_msg("No 'from' entry"))?; let mut from_entry = get_entry_by_name(rt, from)?.ok_or_else(|| err_msg("No 'from' entry"))?;
for entry in to { for entry in to {
@ -168,7 +169,11 @@ fn link_from_to<'a, I>(rt: &'a Runtime, from: &'a str, to: I) -> Result<()>
.get(entr_id)? .get(entr_id)?
.ok_or_else(|| format_err!("No 'to' entry: {}", entry))?; .ok_or_else(|| format_err!("No 'to' entry: {}", entry))?;
if directional {
from_entry.add_link_to(&mut to_entry)?;
} else {
from_entry.add_link(&mut to_entry)?; from_entry.add_link(&mut to_entry)?;
}
rt.report_touched(to_entry.get_location())?; rt.report_touched(to_entry.get_location())?;
} }

View file

@ -107,6 +107,15 @@ pub fn build_ui<'a>(app: App<'a, 'a>) -> App<'a, 'a> {
.help("Link to this entries") .help("Link to this entries")
.requires("from") .requires("from")
.value_name("ENTRIES")) .value_name("ENTRIES"))
.arg(Arg::with_name("directional")
.long("direction")
.takes_value(false)
.required(false)
.multiple(false)
.help("When creating links, make them directional")
.requires_all(&["from", "to"]))
} }
/// PathProvider /// PathProvider