diff options
author | Matthias Beyer <mail@beyermatthias.de> | 2019-11-02 12:12:05 +0100 |
---|---|---|
committer | Matthias Beyer <mail@beyermatthias.de> | 2019-11-02 12:12:05 +0100 |
commit | a79f902d701405c040f7118004eff2881d27a54e (patch) | |
tree | 565f35f2e3f8642786728d911919b7a76419ea6d | |
parent | 69ea42dcad4c4a3870356f6a7fa6235396a1f1a4 (diff) |
imag-link: Add option for directional linking
Signed-off-by: Matthias Beyer <mail@beyermatthias.de>
-rw-r--r-- | bin/core/imag-link/src/lib.rs | 7 | ||||
-rw-r--r-- | bin/core/imag-link/src/ui.rs | 9 |
2 files changed, 15 insertions, 1 deletions
diff --git a/bin/core/imag-link/src/lib.rs b/bin/core/imag-link/src/lib.rs index 1da4172a..9d4f6409 100644 --- a/bin/core/imag-link/src/lib.rs +++ b/bin/core/imag-link/src/lib.rs @@ -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<()> 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"))?; 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)? .ok_or_else(|| format_err!("No 'to' entry: {}", entry))?; - from_entry.add_link(&mut to_entry)?; + if directional { + from_entry.add_link_to(&mut to_entry)?; + } else { + from_entry.add_link(&mut to_entry)?; + } rt.report_touched(to_entry.get_location())?; } diff --git a/bin/core/imag-link/src/ui.rs b/bin/core/imag-link/src/ui.rs index 634a6092..cde5fefd 100644 --- a/bin/core/imag-link/src/ui.rs +++ b/bin/core/imag-link/src/ui.rs @@ -107,6 +107,15 @@ pub fn build_ui<'a>(app: App<'a, 'a>) -> App<'a, 'a> { .help("Link to this entries") .requires("from") .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 |