Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 36afe99

Browse files
committed
fix(help): Skip [OPTIONS] if help/version action
Our code for detecting when to skip this in the usage was never updated for actions.
1 parent 22b545b commit 36afe99

2 files changed

Lines changed: 18 additions & 3 deletions

File tree

clap_builder/src/output/usage.rs

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
#![cfg_attr(not(feature = "usage"), allow(dead_code))]
55

66
// Internal
7+
use crate::builder::ArgAction;
78
use crate::builder::StyledStr;
89
use crate::builder::Styles;
910
use crate::builder::{ArgPredicate, Command};
@@ -210,6 +211,20 @@ impl<'cmd> Usage<'cmd> {
210211
debug!("Usage::needs_options_tag:iter Option is built-in");
211212
continue;
212213
}
214+
match f.get_action() {
215+
ArgAction::Set
216+
| ArgAction::Append
217+
| ArgAction::SetTrue
218+
| ArgAction::SetFalse
219+
| ArgAction::Count => {}
220+
ArgAction::Help
221+
| ArgAction::HelpShort
222+
| ArgAction::HelpLong
223+
| ArgAction::Version => {
224+
debug!("Usage::needs_options_tag:iter Option is built-in");
225+
continue;
226+
}
227+
}
213228

214229
if f.is_hide_set() {
215230
debug!("Usage::needs_options_tag:iter Option is hidden");

tests/builder/help.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1068,7 +1068,7 @@ fn explicit_short_long_help() {
10681068
static SHORT_ABOUT: &str = "\
10691069
bar
10701070
1071-
Usage: myapp [OPTIONS] [arg1]
1071+
Usage: myapp [arg1]
10721072
10731073
Arguments:
10741074
[arg1] some option
@@ -1084,7 +1084,7 @@ something really really long, with
10841084
multiple lines of text
10851085
that should be displayed
10861086
1087-
Usage: myapp [OPTIONS] [arg1]
1087+
Usage: myapp [arg1]
10881088
10891089
Arguments:
10901090
[arg1]
@@ -1351,7 +1351,7 @@ fn override_help_short() {
13511351
}
13521352

13531353
static OVERRIDE_HELP_LONG: &str = "\
1354-
Usage: test [OPTIONS]
1354+
Usage: test
13551355
13561356
Options:
13571357
-h, --hell Print help

0 commit comments

Comments
 (0)