mirror of
https://github.com/clap-rs/clap
synced 2024-12-14 14:52:33 +00:00
fix: fixes a bug where args with last(true) and required(true) set were not being printed in the usage string
Closes #944
This commit is contained in:
parent
3223f21a90
commit
9f9364b1d8
1 changed files with 4 additions and 2 deletions
|
@ -100,7 +100,7 @@ pub fn create_help_usage(p: &Parser, incl_reqs: bool) -> String {
|
||||||
usage.push_str(" [--]");
|
usage.push_str(" [--]");
|
||||||
}
|
}
|
||||||
let not_req_or_hidden =
|
let not_req_or_hidden =
|
||||||
|p: &PosBuilder| !p.is_set(ArgSettings::Required) && !p.is_set(ArgSettings::Hidden);
|
|p: &PosBuilder| (!p.is_set(ArgSettings::Required) || p.is_set(ArgSettings::Last)) && !p.is_set(ArgSettings::Hidden);
|
||||||
if p.has_positionals() && p.positionals.values().any(not_req_or_hidden) {
|
if p.has_positionals() && p.positionals.values().any(not_req_or_hidden) {
|
||||||
if let Some(args_tag) = get_args_tag(p, incl_reqs) {
|
if let Some(args_tag) = get_args_tag(p, incl_reqs) {
|
||||||
usage.push_str(&*args_tag);
|
usage.push_str(&*args_tag);
|
||||||
|
@ -114,8 +114,10 @@ pub fn create_help_usage(p: &Parser, incl_reqs: bool) -> String {
|
||||||
.expect(INTERNAL_ERROR_MSG);
|
.expect(INTERNAL_ERROR_MSG);
|
||||||
debugln!("usage::create_help_usage: '{}' has .last(true)", pos.name());
|
debugln!("usage::create_help_usage: '{}' has .last(true)", pos.name());
|
||||||
let req = pos.is_set(ArgSettings::Required);
|
let req = pos.is_set(ArgSettings::Required);
|
||||||
if req {
|
if req && p.positionals.values().any(|p| !p.is_set(ArgSettings::Required)) {
|
||||||
usage.push_str(" -- <");
|
usage.push_str(" -- <");
|
||||||
|
} else if req {
|
||||||
|
usage.push_str(" [--] <");
|
||||||
} else {
|
} else {
|
||||||
usage.push_str(" [-- <");
|
usage.push_str(" [-- <");
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue