From 25ee6f2ce427cc53a2d9f89ed74a854c4651189a Mon Sep 17 00:00:00 2001 From: Matthias Beyer Date: Wed, 31 Oct 2018 23:07:41 +0100 Subject: [PATCH] Fix: Forward flags as well This is a bugfix. The old implementation did not forward simple commandline flags (as in `--debug`, arguments with no value) because it only used `ArgMatches::value_of()`. But if there is no value, the method returns `None` and the flag is not forwarded. This patch fixes that issue. Signed-off-by: Matthias Beyer --- bin/core/imag/src/main.rs | 21 ++++++++++++++------- 1 file changed, 14 insertions(+), 7 deletions(-) diff --git a/bin/core/imag/src/main.rs b/bin/core/imag/src/main.rs index 37279dd0..2afa0461 100644 --- a/bin/core/imag/src/main.rs +++ b/bin/core/imag/src/main.rs @@ -366,13 +366,20 @@ fn fetch_aliases(config: Option<&Value>) -> Result, Str fn forward_commandline_arguments(m: &ArgMatches, scmd: &mut Vec) { let push = |flag: Option<&str>, val_name: &str, m: &ArgMatches, v: &mut Vec| { - let _ = m - .value_of(val_name) - .map(|val| { - let flag = format!("--{}", flag.unwrap_or(val_name)); - v.insert(0, String::from(val)); - v.insert(0, flag); - }); + if m.is_present(val_name) { + let _ = m + .value_of(val_name) + .map(|val| { + debug!("Found '{:?}' = {:?}", val_name, val); + let flag = format!("--{}", flag.unwrap_or(val_name)); + v.insert(0, String::from(val)); + v.insert(0, flag); + }) + .unwrap_or_else(|| { + let flag = format!("--{}", flag.unwrap_or(val_name)); + v.insert(0, flag); + }); + } }; push(Some("verbose"),