diff --git a/src/build/arg/mod.rs b/src/build/arg/mod.rs index e22760d40c88..469f93a0f2fa 100644 --- a/src/build/arg/mod.rs +++ b/src/build/arg/mod.rs @@ -105,6 +105,8 @@ pub struct Arg<'help> { #[doc(hidden)] pub default_vals_ifs: Option, &'help OsStr)>>, #[doc(hidden)] + pub default_missing_value: Option<&'help OsStr>, + #[doc(hidden)] pub env: Option<(&'help OsStr, Option)>, #[doc(hidden)] pub terminator: Option<&'help str>, @@ -208,6 +210,7 @@ impl<'help> Arg<'help> { "default_value" => yaml_to_str!(a, v, default_value), "default_value_if" => yaml_tuple3!(a, v, default_value_if), "default_value_ifs" => yaml_tuple3!(a, v, default_value_if), + "default_missing_value" => yaml_to_str!(a, v, default_missing_value), "env" => yaml_to_str!(a, v, env), "value_names" => yaml_vec_or_str!(v, a, value_name), "groups" => yaml_vec_or_str!(v, a, group), @@ -2268,6 +2271,16 @@ impl<'help> Arg<'help> { self.default_values_os(&[OsStr::from_bytes(val.as_bytes())]) } + /// ... docs ... + pub fn default_missing_value(self, val: &'help str) -> Self { + self.default_missing_value_os(OsStr::from_bytes(val.as_bytes())) + } + /// ... docs ... + pub fn default_missing_value_os(mut self, val: &'help OsStr) -> Self { + self.default_missing_value = Some(val); + self + } + /// Provides a default value in the exact same manner as [`Arg::default_value`] /// only using [`OsStr`]s instead. /// [`Arg::default_value`]: ./struct.Arg.html#method.default_value @@ -4218,6 +4231,7 @@ impl<'help> fmt::Debug for Arg<'help> { max_values: {:?}, min_values: {:?}, value_delimiter: {:?}, default_value_ifs: {:?}, \ value_terminator: {:?}, display_order: {:?}, env: {:?}, unified_ord: {:?}, \ default_value: {:?}, validator: {}, validator_os: {} \ + default_missing_value: {:?}, \ }}", self.id, self.name, @@ -4247,7 +4261,8 @@ impl<'help> fmt::Debug for Arg<'help> { self.unified_ord, self.default_vals, self.validator.as_ref().map_or("None", |_| "Some(Fn)"), - self.validator_os.as_ref().map_or("None", |_| "Some(Fn)") + self.validator_os.as_ref().map_or("None", |_| "Some(Fn)"), + self.default_missing_value ) } } diff --git a/src/parse/parser.rs b/src/parse/parser.rs index 4334fabab013..188b17f0c95f 100644 --- a/src/parse/parser.rs +++ b/src/parse/parser.rs @@ -1177,6 +1177,15 @@ where )); } else { sdebugln!("None"); + if needs_eq && min_vals_zero { + // OPTION with missing optional value? + let default_missing_value = opt.default_missing_value; + debugln!("default_missing_value = {:?}", default_missing_value); + if let Some(ref value) = default_missing_value { + debugln!("setting value from default_missing_value = {:?}", value); + self.add_val_to_arg(opt, value, matcher)?; + }; + } } matcher.inc_occurrence_of(opt.id);