@@ -8,7 +8,7 @@ use std::{format as f, path::PathBuf};
8
8
9
9
use super :: shstream:: ShStream ;
10
10
11
- pub ( super ) fn command ( ) -> clap:: Command < ' static > {
11
+ pub ( super ) fn command ( ) -> clap:: Command {
12
12
clap:: Command :: new ( "bash" )
13
13
. about ( "Generate bash completion script" )
14
14
. arg (
@@ -139,11 +139,14 @@ fn write_command_func(script: &mut ShStream, fname: &str, command: &clap::Comman
139
139
140
140
let mut pos_index = 0 ;
141
141
for arg in command. get_positionals ( ) {
142
+ let value_range = arg. get_num_args ( ) . expect ( "num_args is some for built arg" ) ;
143
+ let num_vals = ( value_range. max_values ( ) > 1 && value_range. max_values ( ) < usize:: MAX )
144
+ . then_some ( value_range. max_values ( ) ) ;
142
145
script. ensure_blank_line ( ) ;
143
146
if matches ! ( arg. get_action( ) , clap:: ArgAction :: Append )
144
- || ( arg . is_multiple_values_set ( ) && arg. get_value_delimiter ( ) == Some ( ' ' ) )
147
+ || ( num_vals . is_some ( ) && arg. get_value_delimiter ( ) == Some ( ' ' ) )
145
148
{
146
- if let Some ( num_vals) = arg . get_num_vals ( ) {
149
+ if let Some ( num_vals) = num_vals {
147
150
script. line ( & f ! (
148
151
"if (( pos_index >= {pos_index} && pos_index < {})); then" ,
149
152
pos_index + num_vals
@@ -167,7 +170,7 @@ fn write_command_func(script: &mut ShStream, fname: &str, command: &clap::Comman
167
170
}
168
171
script. dedent ( ) ;
169
172
170
- pos_index += 1 + arg . get_num_vals ( ) . unwrap_or ( 0 ) ;
173
+ pos_index += 1 + num_vals . unwrap_or ( 0 ) ;
171
174
172
175
script. line ( "fi" ) ;
173
176
}
@@ -191,7 +194,7 @@ fn write_command_func(script: &mut ShStream, fname: &str, command: &clap::Comman
191
194
192
195
/// Insert COMPREPLY line into script for given arg.
193
196
fn insert_compreply ( script : & mut ShStream , arg : & clap:: Arg ) {
194
- assert ! ( arg. is_takes_value_set ( ) ) ;
197
+ assert ! ( arg. get_num_args ( ) . unwrap ( ) . takes_values ( ) ) ;
195
198
196
199
if let Some ( possible_values) = arg. get_value_parser ( ) . possible_values ( ) {
197
200
let mut possible = ShStream :: new ( ) ;
@@ -205,7 +208,7 @@ fn insert_compreply(script: &mut ShStream, arg: &clap::Arg) {
205
208
arg. get_value_hint( ) ,
206
209
clap:: ValueHint :: Unknown | clap:: ValueHint :: Other
207
210
) {
208
- match arg. get_id ( ) {
211
+ match arg. get_id ( ) . as_str ( ) {
209
212
"branch" | "ref-branch" => {
210
213
script. line ( "mapfile -t COMPREPLY < <(compgen -W \" $(_stg_branches)\" -- \" $cur\" )" )
211
214
}
@@ -301,7 +304,11 @@ fn get_flags(command: &clap::Command) -> (ShStream, ShStream) {
301
304
}
302
305
if let Some ( longs) = arg. get_long_and_visible_aliases ( ) {
303
306
for name in longs {
304
- if arg. is_takes_value_set ( ) {
307
+ if arg
308
+ . get_num_args ( )
309
+ . map ( |value_range| value_range. takes_values ( ) )
310
+ . unwrap_or ( false )
311
+ {
305
312
long_flags. word ( & f ! ( "--{name}=" ) ) ;
306
313
} else {
307
314
long_flags. word ( & f ! ( "'--{name} '" ) ) ;
@@ -400,10 +407,13 @@ fn get_options_pattern(command: &clap::Command) -> ShStream {
400
407
fn get_cmd_flags_pattern ( command : & clap:: Command ) -> ShStream {
401
408
let mut flags = ShStream :: new ( ) ;
402
409
flags. word_sep ( '|' ) ;
403
- for arg in command
404
- . get_arguments ( )
405
- . filter ( |arg| !arg. is_positional ( ) && !arg. is_takes_value_set ( ) )
406
- {
410
+ for arg in command. get_arguments ( ) . filter ( |arg| {
411
+ !arg. is_positional ( )
412
+ && !arg
413
+ . get_num_args ( )
414
+ . expect ( "num_args is some for built arg" )
415
+ . takes_values ( )
416
+ } ) {
407
417
flags. word ( get_arg_flags_pattern ( arg) . as_ref ( ) ) ;
408
418
}
409
419
flags
0 commit comments