@@ -230,26 +230,8 @@ impl<'s, F: Fn() -> clap::Command> CompleteEnv<'s, F> {
230
230
. unwrap_or ( args. len ( ) ) ;
231
231
args. drain ( 0 ..escape_index) ;
232
232
if args. is_empty ( ) {
233
- let name = cmd. get_name ( ) ;
234
- let bin = self
235
- . bin
236
- . as_deref ( )
237
- . or_else ( || cmd. get_bin_name ( ) )
238
- . unwrap_or_else ( || cmd. get_name ( ) ) ;
239
- let completer = if let Some ( completer) = self . completer . as_deref ( ) {
240
- completer. to_owned ( )
241
- } else {
242
- let mut completer = std:: path:: PathBuf :: from ( completer) ;
243
- if let Some ( current_dir) = current_dir {
244
- if 1 < completer. components ( ) . count ( ) {
245
- completer = current_dir. join ( completer) ;
246
- }
247
- }
248
- completer. to_string_lossy ( ) . into_owned ( )
249
- } ;
250
-
251
233
let mut buf = Vec :: new ( ) ;
252
- shell . write_registration ( self . var , name , bin , & completer, & mut buf) ?;
234
+ self . write_registration ( & cmd , current_dir , shell , completer, & mut buf) ?;
253
235
std:: io:: stdout ( ) . write_all ( & buf) ?;
254
236
} else {
255
237
let mut buf = Vec :: new ( ) ;
@@ -284,6 +266,37 @@ impl<'s, F: Fn() -> clap::Command> CompleteEnv<'s, F> {
284
266
} ) ?;
285
267
Ok ( shell)
286
268
}
269
+
270
+ fn write_registration (
271
+ & self ,
272
+ cmd : & clap:: Command ,
273
+ current_dir : Option < & std:: path:: Path > ,
274
+ shell : & dyn EnvCompleter ,
275
+ completer : OsString ,
276
+ buf : & mut dyn std:: io:: Write ,
277
+ ) -> Result < ( ) , std:: io:: Error > {
278
+ let name = cmd. get_name ( ) ;
279
+ let bin = self
280
+ . bin
281
+ . as_deref ( )
282
+ . or_else ( || cmd. get_bin_name ( ) )
283
+ . unwrap_or_else ( || cmd. get_name ( ) ) ;
284
+ let completer = if let Some ( completer) = self . completer . as_deref ( ) {
285
+ completer. to_owned ( )
286
+ } else {
287
+ let mut completer = std:: path:: PathBuf :: from ( completer) ;
288
+ if let Some ( current_dir) = current_dir {
289
+ if 1 < completer. components ( ) . count ( ) {
290
+ completer = current_dir. join ( completer) ;
291
+ }
292
+ }
293
+ completer. to_string_lossy ( ) . into_owned ( )
294
+ } ;
295
+
296
+ shell. write_registration ( self . var , name, bin, & completer, buf) ?;
297
+
298
+ Ok ( ( ) )
299
+ }
287
300
}
288
301
289
302
/// Collection of shell-specific completers
0 commit comments