File tree Expand file tree Collapse file tree 6 files changed +70
-17
lines changed Expand file tree Collapse file tree 6 files changed +70
-17
lines changed Original file line number Diff line number Diff line change @@ -3553,6 +3553,15 @@ impl Command {
3553
3553
self . long_flag_aliases . iter ( ) . map ( |a| a. 0 . as_str ( ) )
3554
3554
}
3555
3555
3556
+ /// Iterate through the *hidden* aliases for this subcommand.
3557
+ #[ inline]
3558
+ pub fn get_aliases ( & self ) -> impl Iterator < Item = & str > + ' _ {
3559
+ self . aliases
3560
+ . iter ( )
3561
+ . filter ( |( _, vis) | !* vis)
3562
+ . map ( |a| a. 0 . as_str ( ) )
3563
+ }
3564
+
3556
3565
#[ inline]
3557
3566
pub ( crate ) fn is_set ( & self , s : AppSettings ) -> bool {
3558
3567
self . settings . is_set ( s) || self . g_settings . is_set ( s)
Original file line number Diff line number Diff line change @@ -386,11 +386,18 @@ fn subcommands(p: &clap::Command) -> Vec<CompletionCandidate> {
386
386
debug ! ( "subcommands: Has subcommands...{:?}" , p. has_subcommands( ) ) ;
387
387
p. get_subcommands ( )
388
388
. flat_map ( |sc| {
389
- sc. get_name_and_visible_aliases ( ) . into_iter ( ) . map ( |s| {
390
- CompletionCandidate :: new ( s. to_string ( ) )
391
- . help ( sc. get_about ( ) . cloned ( ) )
392
- . visible ( true )
393
- } )
389
+ sc. get_name_and_visible_aliases ( )
390
+ . into_iter ( )
391
+ . map ( |s| {
392
+ CompletionCandidate :: new ( s. to_string ( ) )
393
+ . help ( sc. get_about ( ) . cloned ( ) )
394
+ . visible ( !sc. is_hide_set ( ) )
395
+ } )
396
+ . chain ( sc. get_aliases ( ) . into_iter ( ) . map ( |s| {
397
+ CompletionCandidate :: new ( s. to_string ( ) )
398
+ . help ( sc. get_about ( ) . cloned ( ) )
399
+ . visible ( false )
400
+ } ) )
394
401
} )
395
402
. collect ( )
396
403
}
Original file line number Diff line number Diff line change @@ -54,6 +54,44 @@ fn suggest_hidden_long_flags() {
54
54
)
55
55
}
56
56
57
+ #[ test]
58
+ fn suggest_hidden_subcommand_and_aliases ( ) {
59
+ let mut cmd = Command :: new ( "exhaustive" )
60
+ . subcommand (
61
+ Command :: new ( "test_visible" )
62
+ . visible_alias ( "test_visible-alias_visible" )
63
+ . alias ( "test_visible-alias_hidden" ) ,
64
+ )
65
+ . subcommand (
66
+ Command :: new ( "test_hidden" )
67
+ . visible_alias ( "test_hidden-alias_visible" )
68
+ . alias ( "test_hidden-alias_hidden" )
69
+ . hide ( true ) ,
70
+ ) ;
71
+
72
+ assert_data_eq ! (
73
+ complete!( cmd, "test" ) ,
74
+ snapbox:: str ![
75
+ "test_visible
76
+ test_visible-alias_visible"
77
+ ]
78
+ ) ;
79
+
80
+ assert_data_eq ! (
81
+ complete!( cmd, "test_h" ) ,
82
+ snapbox:: str ![
83
+ "test_hidden
84
+ test_hidden-alias_hidden
85
+ test_hidden-alias_visible"
86
+ ]
87
+ ) ;
88
+
89
+ assert_data_eq ! (
90
+ complete!( cmd, "test_hidden-alias_h" ) ,
91
+ snapbox:: str ![ "test_hidden-alias_hidden" ]
92
+ )
93
+ }
94
+
57
95
#[ test]
58
96
fn suggest_subcommand_aliases ( ) {
59
97
let mut cmd = Command :: new ( "exhaustive" )
Original file line number Diff line number Diff line change @@ -196,8 +196,8 @@ fn complete_dynamic() {
196
196
let expected = snapbox:: str![
197
197
r#"% exhaustive --generate
198
198
COMPLETING argument
199
- --generate --help -V action complete hint pacman value
200
- --global --version -h alias help last quote "#
199
+ --generate --help -V action help last quote
200
+ --global --version -h alias hint pacman value "#
201
201
] ;
202
202
let actual = runtime. complete ( input, & term) . unwrap ( ) ;
203
203
assert_data_eq ! ( actual, expected) ;
@@ -213,4 +213,4 @@ fn complete_dynamic() {
213
213
] ;
214
214
let actual = runtime. complete ( input, & term) . unwrap ( ) ;
215
215
assert_data_eq ! ( actual, expected) ;
216
- }
216
+ }
Original file line number Diff line number Diff line change @@ -185,11 +185,11 @@ fn complete_dynamic() {
185
185
let input = "exhaustive \t \t " ;
186
186
let expected = snapbox:: str![ [ r#"
187
187
% exhaustive action
188
- action last -V (Print version )
189
- alias pacman --generate (generate )
190
- complete (Register shell completions for this program) quote --global (everywhere )
191
- help (Print this message or the help of the given subcommand(s)) value --help (Print help)
192
- hint -h (Print help ) --version (Print version)
188
+ action pacman --generate (generate )
189
+ alias quote --global (everywhere )
190
+ help (Print this message or the help of the given subcommand(s)) value --help (Print help )
191
+ hint -h (Print help) --version (Print version )
192
+ last -V (Print version )
193
193
"# ] ] ;
194
194
let actual = runtime. complete ( input, & term) . unwrap ( ) ;
195
195
assert_data_eq ! ( actual, expected) ;
Original file line number Diff line number Diff line change @@ -163,7 +163,6 @@ pacman action alias value quote hint last --
163
163
assert_data_eq ! ( actual, expected) ;
164
164
}
165
165
166
-
167
166
#[ cfg( all( unix, feature = "unstable-dynamic" ) ) ]
168
167
#[ test]
169
168
fn register_dynamic ( ) {
@@ -184,8 +183,8 @@ fn complete_dynamic() {
184
183
let input = "exhaustive \t \t " ;
185
184
let expected = snapbox:: str![
186
185
r#"% exhaustive
187
- --generate --help -V action complete hint pacman value
188
- --global --version -h alias help last quote "#
186
+ --generate --help -V action help last quote
187
+ --global --version -h alias hint pacman value "#
189
188
] ;
190
189
let actual = runtime. complete ( input, & term) . unwrap ( ) ;
191
190
assert_data_eq ! ( actual, expected) ;
@@ -200,4 +199,4 @@ fn complete_dynamic() {
200
199
] ;
201
200
let actual = runtime. complete ( input, & term) . unwrap ( ) ;
202
201
assert_data_eq ! ( actual, expected) ;
203
- }
202
+ }
You can’t perform that action at this time.
0 commit comments