Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Don't show default_vals in smart usage #2609

Merged
merged 1 commit into from
Jul 25, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
5 changes: 4 additions & 1 deletion src/parse/validator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
25 changes: 25 additions & 0 deletions tests/default_vals.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
mod utils;
use clap::{App, Arg, ErrorKind};

#[test]
Expand Down Expand Up @@ -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")
Expand Down