mirror of
https://github.com/clap-rs/clap
synced 2025-03-04 23:37:32 +00:00
Merge pull request #2609 from ldm0/default_val_usage
Don't show default_vals in smart usage
This commit is contained in:
commit
378797a20e
2 changed files with 29 additions and 1 deletions
|
@ -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()
|
||||
|
|
|
@ -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")
|
||||
|
|
Loading…
Add table
Reference in a new issue