Skip to content

Commit

Permalink
Auto merge of #819 - SuperFluffy:add_note_to_doc, r=kbknapp
Browse files Browse the repository at this point in the history
Explain how `ArgRequiredElseHelp` and `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.
  • Loading branch information
homu committed Jan 19, 2017
2 parents ea5ef4f + f1b1188 commit 90b65a5
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 0 deletions.
4 changes: 4 additions & 0 deletions src/app/settings.rs
Expand Up @@ -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
Expand All @@ -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.
Expand Down
3 changes: 3 additions & 0 deletions src/args/arg.rs
Expand Up @@ -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.
Expand Down

0 comments on commit 90b65a5

Please sign in to comment.