@@ -60,7 +60,11 @@ pub fn main(config: &mut Config) -> CliResult {
6060 // (appearing before the subcommand).
6161 let ( expanded_args, global_args) = expand_aliases ( config, args, vec ! [ ] ) ?;
6262
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+ {
6468 let options = CliUnstable :: help ( ) ;
6569 let non_hidden_options: Vec < ( String , String ) > = options
6670 . iter ( )
@@ -112,20 +116,20 @@ Run with 'cargo -Z [FLAG] [SUBCOMMAND]'",
112116 return Ok ( ( ) ) ;
113117 }
114118
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" ) {
117121 let version = get_version_string ( is_verbose) ;
118122 drop_print ! ( config, "{}" , version) ;
119123 return Ok ( ( ) ) ;
120124 }
121125
122- if let Some ( code) = expanded_args. value_of ( "explain" ) {
126+ if let Some ( code) = expanded_args. get_one :: < String > ( "explain" ) {
123127 let mut procss = config. load_global_rustc ( None ) ?. process ( ) ;
124128 procss. arg ( "--explain" ) . arg ( code) . exec ( ) ?;
125129 return Ok ( ( ) ) ;
126130 }
127131
128- if expanded_args. is_present ( "list" ) {
132+ if expanded_args. flag ( "list" ) {
129133 drop_println ! ( config, "Installed Commands:" ) ;
130134 for ( name, command) in list_commands ( config) {
131135 let known_external_desc = KNOWN_EXTERNAL_COMMAND_DESCRIPTIONS . get ( name. as_str ( ) ) ;
@@ -262,7 +266,7 @@ fn expand_aliases(
262266 }
263267 ( Some ( _) , None ) => {
264268 // 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 > ( "" ) {
266270 config. shell ( ) . warn ( format ! (
267271 "trailing arguments after built-in command `{}` are ignored: `{}`" ,
268272 cmd,
@@ -287,11 +291,7 @@ For more information, see issue #10049 <https://github.com/rust-lang/cargo/issue
287291 ) ) ?;
288292 }
289293
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 ( ) ) ;
295295 // new_args strips out everything before the subcommand, so
296296 // capture those global options now.
297297 // Note that an alias to an external command will not receive
@@ -327,28 +327,26 @@ fn config_configure(
327327 subcommand_args : & ArgMatches ,
328328 global_args : GlobalArgs ,
329329) -> 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 ( ) ;
335332 // quiet is unusual because it is redefined in some subcommands in order
336333 // 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 ;
340335 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 ;
345343 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 ( ) ) ;
348346 }
349347 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 ( ) ) ;
352350 }
353351 config. configure (
354352 verbose,
@@ -370,7 +368,12 @@ fn execute_subcommand(config: &mut Config, cmd: &str, subcommand_args: &ArgMatch
370368 }
371369
372370 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+ ) ;
374377 super :: execute_external_subcommand ( config, cmd, & ext_args)
375378}
376379
@@ -389,19 +392,21 @@ struct GlobalArgs {
389392impl GlobalArgs {
390393 fn new ( args : & ArgMatches ) -> GlobalArgs {
391394 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" ) ,
398401 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 ( ) ,
401406 config_args : args
402- . values_of ( "config" )
407+ . get_many :: < String > ( "config" )
403408 . unwrap_or_default ( )
404- . map ( |s| s . to_string ( ) )
409+ . cloned ( )
405410 . collect ( ) ,
406411 }
407412 }
@@ -416,7 +421,7 @@ fn cli() -> App {
416421 } ;
417422 App :: new ( "cargo" )
418423 . allow_external_subcommands ( true )
419- . setting ( AppSettings :: DeriveDisplayOrder | AppSettings :: NoAutoVersion )
424+ . setting ( AppSettings :: DeriveDisplayOrder )
420425 // Doesn't mix well with our list of common cargo commands. See clap-rs/clap#3108 for
421426 // opening clap up to allow us to style our help template
422427 . disable_colored_help ( true )
@@ -450,16 +455,16 @@ Some common cargo commands are (see all commands with --list):
450455
451456See 'cargo help <command>' for more information on a specific command.\n " ,
452457 )
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" ) )
455460 . arg ( opt ( "explain" , "Run `rustc --explain CODE`" ) . value_name ( "CODE" ) )
456461 . arg (
457462 opt (
458463 "verbose" ,
459464 "Use verbose output (-vv very verbose/build.rs output)" ,
460465 )
461466 . short ( 'v' )
462- . multiple_occurrences ( true )
467+ . action ( ArgAction :: Count )
463468 . global ( true ) ,
464469 )
465470 . arg_quiet ( )
@@ -468,9 +473,9 @@ See 'cargo help <command>' for more information on a specific command.\n",
468473 . value_name ( "WHEN" )
469474 . global ( true ) ,
470475 )
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 ) )
474479 . arg (
475480 multi_opt (
476481 "config" ,
@@ -484,7 +489,7 @@ See 'cargo help <command>' for more information on a specific command.\n",
484489 . help ( "Unstable (nightly-only) flags to Cargo, see 'cargo -Z help' for details" )
485490 . short ( 'Z' )
486491 . value_name ( "FLAG" )
487- . multiple_occurrences ( true )
492+ . action ( ArgAction :: Append )
488493 . global ( true ) ,
489494 )
490495 . subcommands ( commands:: builtin ( ) )
0 commit comments