Explain how AppSettings::ArgRequiredElseHelp and Arg::default_value interact

When calling the executable without arguments one expects a help message. However, if even one argument has a default value, the validation step of the parser will always see at least one argument, and therefore report success. This effectively disables the settings.
This commit is contained in:
Richard Janis Goldschmidt 2017-01-18 17:14:06 +01:00
parent ea5ef4f930
commit f1b11886dc
2 changed files with 7 additions and 0 deletions

View file

@ -297,6 +297,9 @@ pub enum AppSettings {
///
/// **NOTE:** [`SubCommand`]s count as arguments
///
/// **NOTE:** Setting [`Arg::default_value`] effectively disables this option as it will
/// ensure that some argument is always present.
///
/// # Examples
///
/// ```rust
@ -306,6 +309,7 @@ pub enum AppSettings {
/// # ;
/// ```
/// [`SubCommand`]: ./struct.SubCommand.html
/// [`Arg::default_value`]: ./struct.Arg.html#method.default_value
ArgRequiredElseHelp,
/// Uses colorized help messages.

View file

@ -2775,6 +2775,9 @@ impl<'a, 'b> Arg<'a, 'b> {
///
/// **NOTE:** This implicitly sets [`Arg::takes_value(true)`].
///
/// **NOTE:** This setting effectively disables `AppSettings::ArgRequiredElseHelp` if used in
/// conjuction as it ensures that some argument will always be present.
///
/// # Examples
///
/// First we use the default value without providing any value at runtime.