@@ -60,7 +60,11 @@ pub fn main(config: &mut Config) -> CliResult {
60
60
// (appearing before the subcommand).
61
61
let ( expanded_args, global_args) = expand_aliases ( config, args, vec ! [ ] ) ?;
62
62
63
- if expanded_args. value_of ( "unstable-features" ) == Some ( "help" ) {
63
+ if expanded_args
64
+ . get_one :: < String > ( "unstable-features" )
65
+ . map ( String :: as_str)
66
+ == Some ( "help" )
67
+ {
64
68
let options = CliUnstable :: help ( ) ;
65
69
let non_hidden_options: Vec < ( String , String ) > = options
66
70
. iter ( )
@@ -112,20 +116,20 @@ Run with 'cargo -Z [FLAG] [SUBCOMMAND]'",
112
116
return Ok ( ( ) ) ;
113
117
}
114
118
115
- let is_verbose = expanded_args. occurrences_of ( " verbose" ) > 0 ;
116
- if expanded_args. is_present ( "version" ) {
119
+ let is_verbose = expanded_args. verbose ( ) > 0 ;
120
+ if expanded_args. flag ( "version" ) {
117
121
let version = get_version_string ( is_verbose) ;
118
122
drop_print ! ( config, "{}" , version) ;
119
123
return Ok ( ( ) ) ;
120
124
}
121
125
122
- if let Some ( code) = expanded_args. value_of ( "explain" ) {
126
+ if let Some ( code) = expanded_args. get_one :: < String > ( "explain" ) {
123
127
let mut procss = config. load_global_rustc ( None ) ?. process ( ) ;
124
128
procss. arg ( "--explain" ) . arg ( code) . exec ( ) ?;
125
129
return Ok ( ( ) ) ;
126
130
}
127
131
128
- if expanded_args. is_present ( "list" ) {
132
+ if expanded_args. flag ( "list" ) {
129
133
drop_println ! ( config, "Installed Commands:" ) ;
130
134
for ( name, command) in list_commands ( config) {
131
135
let known_external_desc = KNOWN_EXTERNAL_COMMAND_DESCRIPTIONS . get ( name. as_str ( ) ) ;
@@ -262,7 +266,7 @@ fn expand_aliases(
262
266
}
263
267
( Some ( _) , None ) => {
264
268
// Command is built-in and is not conflicting with alias, but contains ignored values.
265
- if let Some ( mut values) = args. values_of ( "" ) {
269
+ if let Some ( mut values) = args. get_many :: < String > ( "" ) {
266
270
config. shell ( ) . warn ( format ! (
267
271
"trailing arguments after built-in command `{}` are ignored: `{}`" ,
268
272
cmd,
@@ -287,11 +291,7 @@ For more information, see issue #10049 <https://github.com/rust-lang/cargo/issue
287
291
) ) ?;
288
292
}
289
293
290
- alias. extend (
291
- args. values_of ( "" )
292
- . unwrap_or_default ( )
293
- . map ( |s| s. to_string ( ) ) ,
294
- ) ;
294
+ alias. extend ( args. get_many :: < String > ( "" ) . unwrap_or_default ( ) . cloned ( ) ) ;
295
295
// new_args strips out everything before the subcommand, so
296
296
// capture those global options now.
297
297
// Note that an alias to an external command will not receive
@@ -327,28 +327,26 @@ fn config_configure(
327
327
subcommand_args : & ArgMatches ,
328
328
global_args : GlobalArgs ,
329
329
) -> CliResult {
330
- let arg_target_dir = & subcommand_args
331
- . _is_valid_arg ( "target-dir" )
332
- . then ( || subcommand_args. value_of_path ( "target-dir" , config) )
333
- . flatten ( ) ;
334
- let verbose = global_args. verbose + args. occurrences_of ( "verbose" ) as u32 ;
330
+ let arg_target_dir = & subcommand_args. value_of_path ( "target-dir" , config) ;
331
+ let verbose = global_args. verbose + args. verbose ( ) ;
335
332
// quiet is unusual because it is redefined in some subcommands in order
336
333
// to provide custom help text.
337
- let quiet = args. is_present ( "quiet" )
338
- || subcommand_args. is_valid_and_present ( "quiet" )
339
- || global_args. quiet ;
334
+ let quiet = args. flag ( "quiet" ) || subcommand_args. flag ( "quiet" ) || global_args. quiet ;
340
335
let global_color = global_args. color ; // Extract so it can take reference.
341
- let color = args. value_of ( "color" ) . or_else ( || global_color. as_deref ( ) ) ;
342
- let frozen = args. is_present ( "frozen" ) || global_args. frozen ;
343
- let locked = args. is_present ( "locked" ) || global_args. locked ;
344
- let offline = args. is_present ( "offline" ) || global_args. offline ;
336
+ let color = args
337
+ . get_one :: < String > ( "color" )
338
+ . map ( String :: as_str)
339
+ . or_else ( || global_color. as_deref ( ) ) ;
340
+ let frozen = args. flag ( "frozen" ) || global_args. frozen ;
341
+ let locked = args. flag ( "locked" ) || global_args. locked ;
342
+ let offline = args. flag ( "offline" ) || global_args. offline ;
345
343
let mut unstable_flags = global_args. unstable_flags ;
346
- if let Some ( values) = args. values_of ( "unstable-features" ) {
347
- unstable_flags. extend ( values. map ( |s| s . to_string ( ) ) ) ;
344
+ if let Some ( values) = args. get_many :: < String > ( "unstable-features" ) {
345
+ unstable_flags. extend ( values. cloned ( ) ) ;
348
346
}
349
347
let mut config_args = global_args. config_args ;
350
- if let Some ( values) = args. values_of ( "config" ) {
351
- config_args. extend ( values. map ( |s| s . to_string ( ) ) ) ;
348
+ if let Some ( values) = args. get_many :: < String > ( "config" ) {
349
+ config_args. extend ( values. cloned ( ) ) ;
352
350
}
353
351
config. configure (
354
352
verbose,
@@ -370,7 +368,12 @@ fn execute_subcommand(config: &mut Config, cmd: &str, subcommand_args: &ArgMatch
370
368
}
371
369
372
370
let mut ext_args: Vec < & str > = vec ! [ cmd] ;
373
- ext_args. extend ( subcommand_args. values_of ( "" ) . unwrap_or_default ( ) ) ;
371
+ ext_args. extend (
372
+ subcommand_args
373
+ . get_many :: < String > ( "" )
374
+ . unwrap_or_default ( )
375
+ . map ( String :: as_str) ,
376
+ ) ;
374
377
super :: execute_external_subcommand ( config, cmd, & ext_args)
375
378
}
376
379
@@ -389,19 +392,21 @@ struct GlobalArgs {
389
392
impl GlobalArgs {
390
393
fn new ( args : & ArgMatches ) -> GlobalArgs {
391
394
GlobalArgs {
392
- verbose : args. occurrences_of ( " verbose" ) as u32 ,
393
- quiet : args. is_present ( "quiet" ) ,
394
- color : args. value_of ( "color" ) . map ( |s| s . to_string ( ) ) ,
395
- frozen : args. is_present ( "frozen" ) ,
396
- locked : args. is_present ( "locked" ) ,
397
- offline : args. is_present ( "offline" ) ,
395
+ verbose : args. verbose ( ) ,
396
+ quiet : args. flag ( "quiet" ) ,
397
+ color : args. get_one :: < String > ( "color" ) . cloned ( ) ,
398
+ frozen : args. flag ( "frozen" ) ,
399
+ locked : args. flag ( "locked" ) ,
400
+ offline : args. flag ( "offline" ) ,
398
401
unstable_flags : args
399
- . values_of_lossy ( "unstable-features" )
400
- . unwrap_or_default ( ) ,
402
+ . get_many :: < String > ( "unstable-features" )
403
+ . unwrap_or_default ( )
404
+ . cloned ( )
405
+ . collect ( ) ,
401
406
config_args : args
402
- . values_of ( "config" )
407
+ . get_many :: < String > ( "config" )
403
408
. unwrap_or_default ( )
404
- . map ( |s| s . to_string ( ) )
409
+ . cloned ( )
405
410
. collect ( ) ,
406
411
}
407
412
}
@@ -416,7 +421,7 @@ fn cli() -> App {
416
421
} ;
417
422
App :: new ( "cargo" )
418
423
. allow_external_subcommands ( true )
419
- . setting ( AppSettings :: DeriveDisplayOrder | AppSettings :: NoAutoVersion )
424
+ . setting ( AppSettings :: DeriveDisplayOrder )
420
425
// Doesn't mix well with our list of common cargo commands. See clap-rs/clap#3108 for
421
426
// opening clap up to allow us to style our help template
422
427
. disable_colored_help ( true )
@@ -450,16 +455,16 @@ Some common cargo commands are (see all commands with --list):
450
455
451
456
See 'cargo help <command>' for more information on a specific command.\n " ,
452
457
)
453
- . arg ( opt ( "version" , "Print version info and exit" ) . short ( 'V' ) )
454
- . arg ( opt ( "list" , "List installed commands" ) )
458
+ . arg ( flag ( "version" , "Print version info and exit" ) . short ( 'V' ) )
459
+ . arg ( flag ( "list" , "List installed commands" ) )
455
460
. arg ( opt ( "explain" , "Run `rustc --explain CODE`" ) . value_name ( "CODE" ) )
456
461
. arg (
457
462
opt (
458
463
"verbose" ,
459
464
"Use verbose output (-vv very verbose/build.rs output)" ,
460
465
)
461
466
. short ( 'v' )
462
- . multiple_occurrences ( true )
467
+ . action ( ArgAction :: Count )
463
468
. global ( true ) ,
464
469
)
465
470
. arg_quiet ( )
@@ -468,9 +473,9 @@ See 'cargo help <command>' for more information on a specific command.\n",
468
473
. value_name ( "WHEN" )
469
474
. global ( true ) ,
470
475
)
471
- . arg ( opt ( "frozen" , "Require Cargo.lock and cache are up to date" ) . global ( true ) )
472
- . arg ( opt ( "locked" , "Require Cargo.lock is up to date" ) . global ( true ) )
473
- . arg ( opt ( "offline" , "Run without accessing the network" ) . global ( true ) )
476
+ . arg ( flag ( "frozen" , "Require Cargo.lock and cache are up to date" ) . global ( true ) )
477
+ . arg ( flag ( "locked" , "Require Cargo.lock is up to date" ) . global ( true ) )
478
+ . arg ( flag ( "offline" , "Run without accessing the network" ) . global ( true ) )
474
479
. arg (
475
480
multi_opt (
476
481
"config" ,
@@ -484,7 +489,7 @@ See 'cargo help <command>' for more information on a specific command.\n",
484
489
. help ( "Unstable (nightly-only) flags to Cargo, see 'cargo -Z help' for details" )
485
490
. short ( 'Z' )
486
491
. value_name ( "FLAG" )
487
- . multiple_occurrences ( true )
492
+ . action ( ArgAction :: Append )
488
493
. global ( true ) ,
489
494
)
490
495
. subcommands ( commands:: builtin ( ) )
0 commit comments