@@ -110,15 +110,14 @@ fn complete_arg(
110
110
completions. extend (
111
111
complete_arg_value ( value. to_str ( ) . ok_or ( value) , arg, current_dir)
112
112
. into_iter ( )
113
- . map ( |( os, help) | {
114
- // HACK: Need better `OsStr` manipulation
113
+ . map ( |comp| {
115
114
CompletionCandidate :: new ( format ! (
116
115
"--{}={}" ,
117
116
flag,
118
- os . to_string_lossy( )
117
+ comp . get_content ( ) . to_string_lossy( )
119
118
) )
120
- . help ( help )
121
- . visible ( true )
119
+ . help ( comp . get_help ( ) . cloned ( ) )
120
+ . visible ( comp . is_visible ( ) )
122
121
} ) ,
123
122
) ;
124
123
}
@@ -169,11 +168,7 @@ fn complete_arg(
169
168
. get_positionals ( )
170
169
. find ( |p| p. get_index ( ) == Some ( pos_index) )
171
170
{
172
- completions. extend (
173
- complete_arg_value ( arg. to_value ( ) , positional, current_dir)
174
- . into_iter ( )
175
- . map ( |( os, help) | CompletionCandidate :: new ( os) . help ( help) . visible ( true ) ) ,
176
- ) ;
171
+ completions. extend ( complete_arg_value ( arg. to_value ( ) , positional, current_dir) . into_iter ( ) ) ;
177
172
}
178
173
179
174
if let Ok ( value) = arg. to_value ( ) {
@@ -191,16 +186,19 @@ fn complete_arg_value(
191
186
value : Result < & str , & OsStr > ,
192
187
arg : & clap:: Arg ,
193
188
current_dir : Option < & std:: path:: Path > ,
194
- ) -> Vec < ( OsString , Option < StyledStr > ) > {
189
+ ) -> Vec < CompletionCandidate > {
195
190
let mut values = Vec :: new ( ) ;
196
191
debug ! ( "complete_arg_value: arg={arg:?}, value={value:?}" ) ;
197
192
198
193
if let Some ( possible_values) = possible_values ( arg) {
199
194
if let Ok ( value) = value {
200
195
values. extend ( possible_values. into_iter ( ) . filter_map ( |p| {
201
196
let name = p. get_name ( ) ;
202
- name. starts_with ( value)
203
- . then ( || ( OsString :: from ( name) , p. get_help ( ) . cloned ( ) ) )
197
+ name. starts_with ( value) . then ( || {
198
+ CompletionCandidate :: new ( OsString :: from ( name) )
199
+ . help ( p. get_help ( ) . cloned ( ) )
200
+ . visible ( !p. is_hide_set ( ) )
201
+ } )
204
202
} ) ) ;
205
203
}
206
204
} else {
@@ -249,7 +247,7 @@ fn complete_path(
249
247
value_os : & OsStr ,
250
248
current_dir : Option < & std:: path:: Path > ,
251
249
is_wanted : impl Fn ( & std:: path:: Path ) -> bool ,
252
- ) -> Vec < ( OsString , Option < StyledStr > ) > {
250
+ ) -> Vec < CompletionCandidate > {
253
251
let mut completions = Vec :: new ( ) ;
254
252
255
253
let current_dir = match current_dir {
@@ -281,12 +279,20 @@ fn complete_path(
281
279
let path = entry. path ( ) ;
282
280
let mut suggestion = pathdiff:: diff_paths ( & path, current_dir) . unwrap_or ( path) ;
283
281
suggestion. push ( "" ) ; // Ensure trailing `/`
284
- completions. push ( ( suggestion. as_os_str ( ) . to_owned ( ) , None ) ) ;
282
+ completions. push (
283
+ CompletionCandidate :: new ( suggestion. as_os_str ( ) . to_owned ( ) )
284
+ . help ( None )
285
+ . visible ( true ) ,
286
+ ) ;
285
287
} else {
286
288
let path = entry. path ( ) ;
287
289
if is_wanted ( & path) {
288
290
let suggestion = pathdiff:: diff_paths ( & path, current_dir) . unwrap_or ( path) ;
289
- completions. push ( ( suggestion. as_os_str ( ) . to_owned ( ) , None ) ) ;
291
+ completions. push (
292
+ CompletionCandidate :: new ( suggestion. as_os_str ( ) . to_owned ( ) )
293
+ . help ( None )
294
+ . visible ( true ) ,
295
+ ) ;
290
296
}
291
297
}
292
298
}
0 commit comments