@@ -166,14 +166,15 @@ impl State {
166
166
}
167
167
168
168
impl Complete {
169
- pub ( crate ) fn push_shell ( & mut self , op : ShellComp , depth : usize ) {
169
+ pub ( crate ) fn push_shell ( & mut self , op : ShellComp , is_argument : bool , depth : usize ) {
170
170
self . comps . push ( Comp :: Shell {
171
171
extra : CompExtra {
172
172
depth,
173
173
group : None ,
174
174
help : None ,
175
175
} ,
176
176
script : op,
177
+ is_argument,
177
178
} ) ;
178
179
}
179
180
@@ -224,10 +225,7 @@ pub(crate) struct CompExtra {
224
225
#[ derive( Clone , Debug ) ]
225
226
pub ( crate ) enum Comp {
226
227
/// short or long flag
227
- Flag {
228
- extra : CompExtra ,
229
- name : ShortLong ,
230
- } ,
228
+ Flag { extra : CompExtra , name : ShortLong } ,
231
229
232
230
/// argument + metadata
233
231
Argument {
@@ -256,12 +254,15 @@ pub(crate) enum Comp {
256
254
Metavariable {
257
255
extra : CompExtra ,
258
256
meta : & ' static str ,
257
+ /// AKA not positional
259
258
is_argument : bool ,
260
259
} ,
261
260
262
261
Shell {
263
262
extra : CompExtra ,
264
263
script : ShellComp ,
264
+ /// AKA not positional
265
+ is_argument : bool ,
265
266
} ,
266
267
}
267
268
@@ -348,6 +349,9 @@ fn pair_to_os_string<'a>(pair: (&'a Arg, &'a OsStr)) -> Option<(&'a Arg, &'a str
348
349
Some ( ( pair. 0 , pair. 1 . to_str ( ) ?) )
349
350
}
350
351
352
+ /// What is the preceeding item, if any
353
+ ///
354
+ /// Mostly is there to tell if we are trying to complete and argument or not...
351
355
#[ derive( Debug , Copy , Clone ) ]
352
356
enum Prefix < ' a > {
353
357
NA ,
@@ -374,7 +378,7 @@ impl State {
374
378
// try get a current item to complete - must be non-virtual right most one
375
379
// value must be present here, and can fail only for non-utf8 values
376
380
// can't do much completing with non-utf8 values since bpaf needs to print them to stdout
377
- let ( _ , lit) = items. next ( ) ?;
381
+ let ( cur , lit) = items. next ( ) ?;
378
382
379
383
// For cases like "-k=val", "-kval", "--key=val", "--key val"
380
384
// last value is going to be either Arg::Word or Arg::ArgWord
@@ -389,13 +393,18 @@ impl State {
389
393
_ => ( false , lit) ,
390
394
} ;
391
395
396
+ let is_named = match cur {
397
+ Arg :: Short ( _, _, _) | Arg :: Long ( _, _, _) => true ,
398
+ Arg :: ArgWord ( _) | Arg :: Word ( _) | Arg :: PosWord ( _) => false ,
399
+ } ;
400
+
392
401
let prefix = match preceeding {
393
402
Some ( ( Arg :: Short ( s, true , _os) , _lit) ) => Prefix :: Short ( * s) ,
394
403
Some ( ( Arg :: Long ( l, true , _os) , _lit) ) => Prefix :: Long ( l. as_str ( ) ) ,
395
404
_ => Prefix :: NA ,
396
405
} ;
397
406
398
- let ( items, shell) = comp. complete ( lit, pos_only, prefix) ;
407
+ let ( items, shell) = comp. complete ( lit, pos_only, is_named , prefix) ;
399
408
400
409
Some ( match comp. output_rev {
401
410
0 => render_test ( & items, & shell, full_lit) ,
@@ -480,10 +489,9 @@ impl Comp {
480
489
fn only_value ( & self ) -> bool {
481
490
match self {
482
491
Comp :: Flag { .. } | Comp :: Argument { .. } | Comp :: Command { .. } => false ,
483
- Comp :: Metavariable { is_argument, .. } | Comp :: Value { is_argument, .. } => {
484
- * is_argument
485
- }
486
- Comp :: Shell { .. } => true ,
492
+ Comp :: Metavariable { is_argument, .. }
493
+ | Comp :: Value { is_argument, .. }
494
+ | Comp :: Shell { is_argument, .. } => * is_argument,
487
495
}
488
496
}
489
497
fn is_pos ( & self ) -> bool {
@@ -500,6 +508,7 @@ impl Complete {
500
508
& self ,
501
509
arg : & str ,
502
510
pos_only : bool ,
511
+ is_named : bool ,
503
512
prefix : Prefix ,
504
513
) -> ( Vec < ShowComp > , Vec < ShellComp > ) {
505
514
let mut items: Vec < ShowComp > = Vec :: new ( ) ;
@@ -588,7 +597,9 @@ impl Complete {
588
597
}
589
598
590
599
Comp :: Shell { script, .. } => {
591
- shell. push ( * script) ;
600
+ if !is_named {
601
+ shell. push ( * script) ;
602
+ }
592
603
}
593
604
}
594
605
}
0 commit comments