Merge pull request #2609 from ldm0/default_val_usage

Don't show default_vals in smart usage
This commit is contained in:
Pavan Kumar Sunkara 2021-07-25 14:20:29 +01:00 committed by GitHub
commit 378797a20e
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 29 additions and 1 deletions

View file

@ -681,8 +681,11 @@ impl<'help, 'app, 'parser> Validator<'help, 'app, 'parser> {
let used: Vec<Id> = matcher
.arg_names()
.filter(|n| {
// Filter out the args we don't want to specify.
self.p.app.find(n).map_or(true, |a| {
!(a.is_set(ArgSettings::Hidden) || self.p.required.contains(&a.id))
!a.is_set(ArgSettings::Hidden)
&& a.default_vals.is_empty()
&& !self.p.required.contains(&a.id)
})
})
.cloned()

View file

@ -1,3 +1,4 @@
mod utils;
use clap::{App, Arg, ErrorKind};
#[test]
@ -588,6 +589,30 @@ fn multiple_defaults_override() {
assert_eq!(m.values_of_lossy("files").unwrap(), vec!["other", "mine"]);
}
#[test]
fn default_vals_donnot_show_in_smart_usage() {
let app = App::new("bug")
.arg(
Arg::new("foo")
.long("config")
.takes_value(true)
.default_value("bar"),
)
.arg(Arg::new("input").required(true));
assert!(utils::compare_output(
app,
"bug",
"error: The following required arguments were not provided:
<input>
USAGE:
bug [OPTIONS] <input>
For more information try --help",
true,
));
}
#[test]
fn issue_1050_num_vals_and_defaults() {
let res = App::new("hello")