@@ -156,6 +156,12 @@ enum RustupSubcmd {
156
156
#[ command( subcommand) ]
157
157
subcmd : ComponentSubcmd ,
158
158
} ,
159
+
160
+ /// Modify toolchain overrides for directories
161
+ Override {
162
+ #[ command( subcommand) ]
163
+ subcmd : OverrideSubcmd ,
164
+ } ,
159
165
}
160
166
161
167
#[ derive( Debug , Subcommand ) ]
@@ -338,6 +344,40 @@ enum ComponentSubcmd {
338
344
} ,
339
345
}
340
346
347
+ #[ derive( Debug , Subcommand ) ]
348
+ #[ command(
349
+ after_help = OVERRIDE_HELP ,
350
+ arg_required_else_help = true ,
351
+ subcommand_required = true ,
352
+ ) ]
353
+ enum OverrideSubcmd {
354
+ /// List directory toolchain overrides
355
+ List ,
356
+
357
+ /// Set the override toolchain for a directory
358
+ #[ command( alias = "add" ) ]
359
+ Set {
360
+ #[ arg( help = RESOLVABLE_TOOLCHAIN_ARG_HELP ) ]
361
+ toolchain : ResolvableToolchainName ,
362
+
363
+ /// Path to the directory
364
+ #[ arg( long) ]
365
+ path : Option < PathBuf > ,
366
+ } ,
367
+
368
+ /// Remove the override toolchain for a directory
369
+ #[ command( alias = "remove" , after_help = OVERRIDE_UNSET_HELP ) ]
370
+ Unset {
371
+ /// Path to the directory
372
+ #[ arg( long) ]
373
+ path : Option < PathBuf > ,
374
+
375
+ /// Remove override toolchain for all nonexistent directories
376
+ #[ arg( long) ]
377
+ nonexistent : bool ,
378
+ } ,
379
+ }
380
+
341
381
impl Rustup {
342
382
fn dispatch ( self , cfg : & mut Cfg ) -> Result < utils:: ExitCode > {
343
383
match self . subcmd {
@@ -398,6 +438,15 @@ impl Rustup {
398
438
target,
399
439
} => component_remove ( cfg, component, toolchain, target. as_deref ( ) ) ,
400
440
} ,
441
+ RustupSubcmd :: Override { subcmd } => match subcmd {
442
+ OverrideSubcmd :: List => handle_epipe ( common:: list_overrides ( cfg) ) ,
443
+ OverrideSubcmd :: Set { toolchain, path } => {
444
+ override_add ( cfg, toolchain, path. as_deref ( ) )
445
+ }
446
+ OverrideSubcmd :: Unset { path, nonexistent } => {
447
+ override_remove ( cfg, path. as_deref ( ) , nonexistent)
448
+ }
449
+ } ,
401
450
}
402
451
}
403
452
}
@@ -476,18 +525,9 @@ pub fn main() -> Result<utils::ExitCode> {
476
525
( "dump-testament" , _) => common:: dump_testament ( ) ?,
477
526
(
478
527
"show" | "update" | "install" | "uninstall" | "toolchain" | "check" | "default"
479
- | "target" | "component" ,
528
+ | "target" | "component" | "override" ,
480
529
_,
481
530
) => Rustup :: from_arg_matches ( & matches) ?. dispatch ( cfg) ?,
482
- ( "override" , c) => match c. subcommand ( ) {
483
- Some ( s) => match s {
484
- ( "list" , _) => handle_epipe ( common:: list_overrides ( cfg) ) ?,
485
- ( "set" , m) => override_add ( cfg, m) ?,
486
- ( "unset" , m) => override_remove ( cfg, m) ?,
487
- _ => unreachable ! ( ) ,
488
- } ,
489
- None => unreachable ! ( ) ,
490
- } ,
491
531
( "run" , m) => run ( cfg, m) ?,
492
532
( "which" , m) => which ( cfg, m) ?,
493
533
( "doc" , m) => doc ( cfg, m) ?,
@@ -566,50 +606,6 @@ pub(crate) fn cli() -> Command {
566
606
. about ( "Dump information about the build" )
567
607
. hide ( true ) , // Not for users, only CI
568
608
)
569
- . subcommand (
570
- Command :: new ( "override" )
571
- . about ( "Modify toolchain overrides for directories" )
572
- . after_help ( OVERRIDE_HELP )
573
- . subcommand_required ( true )
574
- . arg_required_else_help ( true )
575
- . subcommand ( Command :: new ( "list" ) . about ( "List directory toolchain overrides" ) )
576
- . subcommand (
577
- Command :: new ( "set" )
578
- . about ( "Set the override toolchain for a directory" )
579
- . alias ( "add" )
580
- . arg (
581
- Arg :: new ( "toolchain" )
582
- . help ( RESOLVABLE_TOOLCHAIN_ARG_HELP )
583
- . required ( true )
584
- . num_args ( 1 )
585
- . value_parser ( resolvable_toolchainame_parser) ,
586
- )
587
- . arg (
588
- Arg :: new ( "path" )
589
- . long ( "path" )
590
- . num_args ( 1 )
591
- . help ( "Path to the directory" ) ,
592
- ) ,
593
- )
594
- . subcommand (
595
- Command :: new ( "unset" )
596
- . about ( "Remove the override toolchain for a directory" )
597
- . after_help ( OVERRIDE_UNSET_HELP )
598
- . alias ( "remove" )
599
- . arg (
600
- Arg :: new ( "path" )
601
- . long ( "path" )
602
- . num_args ( 1 )
603
- . help ( "Path to the directory" ) ,
604
- )
605
- . arg (
606
- Arg :: new ( "nonexistent" )
607
- . long ( "nonexistent" )
608
- . help ( "Remove override toolchain for all nonexistent directories" )
609
- . action ( ArgAction :: SetTrue ) ,
610
- ) ,
611
- ) ,
612
- )
613
609
. subcommand (
614
610
Command :: new ( "run" )
615
611
. about ( "Run a command with an environment configured for a given toolchain" )
@@ -1376,11 +1372,14 @@ fn toolchain_remove(cfg: &mut Cfg, opts: UninstallOpts) -> Result<utils::ExitCod
1376
1372
Ok ( utils:: ExitCode ( 0 ) )
1377
1373
}
1378
1374
1379
- fn override_add ( cfg : & Cfg , m : & ArgMatches ) -> Result < utils:: ExitCode > {
1380
- let toolchain_name = m. get_one :: < ResolvableToolchainName > ( "toolchain" ) . unwrap ( ) ;
1381
- let toolchain_name = toolchain_name. resolve ( & cfg. get_default_host_triple ( ) ?) ?;
1375
+ fn override_add (
1376
+ cfg : & Cfg ,
1377
+ toolchain : ResolvableToolchainName ,
1378
+ path : Option < & Path > ,
1379
+ ) -> Result < utils:: ExitCode > {
1380
+ let toolchain_name = toolchain. resolve ( & cfg. get_default_host_triple ( ) ?) ?;
1382
1381
1383
- let path = if let Some ( path) = m . get_one :: < String > ( " path" ) {
1382
+ let path = if let Some ( path) = path {
1384
1383
PathBuf :: from ( path)
1385
1384
} else {
1386
1385
utils:: current_dir ( ) ?
@@ -1415,39 +1414,36 @@ fn override_add(cfg: &Cfg, m: &ArgMatches) -> Result<utils::ExitCode> {
1415
1414
Ok ( utils:: ExitCode ( 0 ) )
1416
1415
}
1417
1416
1418
- fn override_remove ( cfg : & Cfg , m : & ArgMatches ) -> Result < utils:: ExitCode > {
1419
- let paths = if m . get_flag ( " nonexistent" ) {
1417
+ fn override_remove ( cfg : & Cfg , path : Option < & Path > , nonexistent : bool ) -> Result < utils:: ExitCode > {
1418
+ let paths = if nonexistent {
1420
1419
let list: Vec < _ > = cfg. settings_file . with ( |s| {
1421
1420
Ok ( s. overrides
1422
1421
. iter ( )
1423
1422
. filter_map ( |( k, _) | {
1424
- if Path :: new ( k) . is_dir ( ) {
1425
- None
1426
- } else {
1427
- Some ( k. clone ( ) )
1428
- }
1423
+ let path = Path :: new ( k) ;
1424
+ ( !path. is_dir ( ) ) . then ( || path. to_owned ( ) )
1429
1425
} )
1430
1426
. collect ( ) )
1431
1427
} ) ?;
1432
1428
if list. is_empty ( ) {
1433
1429
info ! ( "no nonexistent paths detected" ) ;
1434
1430
}
1435
1431
list
1436
- } else if let Some ( path) = m . get_one :: < String > ( " path" ) {
1432
+ } else if let Some ( path) = path {
1437
1433
vec ! [ path. to_owned( ) ]
1438
1434
} else {
1439
- vec ! [ utils:: current_dir( ) ?. to_str ( ) . unwrap ( ) . to_string ( ) ]
1435
+ vec ! [ utils:: current_dir( ) ?]
1440
1436
} ;
1441
1437
1442
- for path in paths {
1438
+ for p in & paths {
1443
1439
if cfg
1444
1440
. settings_file
1445
- . with_mut ( |s| Ok ( s. remove_override ( Path :: new ( & path ) , cfg. notify_handler . as_ref ( ) ) ) ) ?
1441
+ . with_mut ( |s| Ok ( s. remove_override ( p , cfg. notify_handler . as_ref ( ) ) ) ) ?
1446
1442
{
1447
- info ! ( "override toolchain for '{}' removed" , path ) ;
1443
+ info ! ( "override toolchain for '{}' removed" , p . display ( ) ) ;
1448
1444
} else {
1449
- info ! ( "no override toolchain for '{}'" , path ) ;
1450
- if m . get_one :: < String > ( " path" ) . is_none ( ) && !m . get_flag ( " nonexistent" ) {
1445
+ info ! ( "no override toolchain for '{}'" , p . display ( ) ) ;
1446
+ if path. is_none ( ) && !nonexistent {
1451
1447
info ! (
1452
1448
"you may use `--path <path>` option to remove override toolchain \
1453
1449
for a specific path"
0 commit comments