@@ -92,7 +92,7 @@ pub fn complete(
9292 if value. is_some ( ) {
9393 ParseState :: ValueDone
9494 } else {
95- ParseState :: Opt ( opt. unwrap ( ) )
95+ ParseState :: Opt ( ( opt. unwrap ( ) , 1 ) )
9696 }
9797 }
9898 Some ( clap:: ArgAction :: SetTrue ) | Some ( clap:: ArgAction :: SetFalse ) => {
@@ -115,7 +115,7 @@ pub fn complete(
115115 Some ( opt) => {
116116 state = match short. next_value_os ( ) {
117117 Some ( _) => ParseState :: ValueDone ,
118- None => ParseState :: Opt ( opt) ,
118+ None => ParseState :: Opt ( ( opt, 1 ) ) ,
119119 } ;
120120 }
121121 None => {
@@ -128,9 +128,19 @@ pub fn complete(
128128 pos_index += 1 ;
129129 state = ParseState :: ValueDone ;
130130 }
131- ParseState :: Opt ( _) => {
132- state = ParseState :: ValueDone ;
133- }
131+ ParseState :: Opt ( ( ref opt, count) ) => match opt. get_num_args ( ) {
132+ Some ( range) => {
133+ let max = range. max_values ( ) ;
134+ if count < max {
135+ state = ParseState :: Opt ( ( opt. clone ( ) , count + 1 ) ) ;
136+ } else {
137+ state = ParseState :: ValueDone ;
138+ }
139+ }
140+ None => {
141+ state = ParseState :: ValueDone ;
142+ }
143+ } ,
134144 }
135145 }
136146 }
@@ -150,7 +160,7 @@ enum ParseState<'a> {
150160 Pos ( usize ) ,
151161
152162 /// Parsing a optional flag argument
153- Opt ( & ' a clap:: Arg ) ,
163+ Opt ( ( & ' a clap:: Arg , usize ) ) ,
154164}
155165
156166fn complete_arg (
@@ -298,8 +308,19 @@ fn complete_arg(
298308 completions. extend ( complete_arg_value ( arg. to_value ( ) , positional, current_dir) ) ;
299309 }
300310 }
301- ParseState :: Opt ( opt) => {
311+ ParseState :: Opt ( ( opt, count ) ) => {
302312 completions. extend ( complete_arg_value ( arg. to_value ( ) , opt, current_dir) ) ;
313+ let min = opt. get_num_args ( ) . map ( |r| r. min_values ( ) ) . unwrap_or ( 0 ) ;
314+ if count > min {
315+ // Also complete this raw_arg as a positional argument, flags, options and subcommand.
316+ completions. extend ( complete_arg (
317+ arg,
318+ cmd,
319+ current_dir,
320+ pos_index,
321+ ParseState :: ValueDone ,
322+ ) ?) ;
323+ }
303324 }
304325 }
305326 if completions. iter ( ) . any ( |a| a. is_visible ( ) ) {
0 commit comments