@@ -150,6 +150,12 @@ enum RustupSubcmd {
150
150
#[ command( subcommand) ]
151
151
subcmd : TargetSubcmd ,
152
152
} ,
153
+
154
+ /// Modify a toolchain's installed components
155
+ Component {
156
+ #[ command( subcommand) ]
157
+ subcmd : ComponentSubcmd ,
158
+ } ,
153
159
}
154
160
155
161
#[ derive( Debug , Subcommand ) ]
@@ -294,6 +300,44 @@ enum TargetSubcmd {
294
300
} ,
295
301
}
296
302
303
+ #[ derive( Debug , Subcommand ) ]
304
+ #[ command( arg_required_else_help = true , subcommand_required = true ) ]
305
+ enum ComponentSubcmd {
306
+ /// List installed and available components
307
+ List {
308
+ #[ arg( long, help = OFFICIAL_TOOLCHAIN_ARG_HELP ) ]
309
+ toolchain : Option < PartialToolchainDesc > ,
310
+
311
+ /// List only installed components
312
+ #[ arg( long) ]
313
+ installed : bool ,
314
+ } ,
315
+
316
+ /// Add a component to a Rust toolchain
317
+ Add {
318
+ #[ arg( required = true , num_args = 1 ..) ]
319
+ component : Vec < String > ,
320
+
321
+ #[ arg( long, help = OFFICIAL_TOOLCHAIN_ARG_HELP ) ]
322
+ toolchain : Option < PartialToolchainDesc > ,
323
+
324
+ #[ arg( long) ]
325
+ target : Option < String > ,
326
+ } ,
327
+
328
+ /// Remove a component from a Rust toolchain
329
+ Remove {
330
+ #[ arg( required = true , num_args = 1 ..) ]
331
+ component : Vec < String > ,
332
+
333
+ #[ arg( long, help = OFFICIAL_TOOLCHAIN_ARG_HELP ) ]
334
+ toolchain : Option < PartialToolchainDesc > ,
335
+
336
+ #[ arg( long) ]
337
+ target : Option < String > ,
338
+ } ,
339
+ }
340
+
297
341
impl Rustup {
298
342
fn dispatch ( self , cfg : & mut Cfg ) -> Result < utils:: ExitCode > {
299
343
match self . subcmd {
@@ -338,6 +382,22 @@ impl Rustup {
338
382
TargetSubcmd :: Add { target, toolchain } => target_add ( cfg, target, toolchain) ,
339
383
TargetSubcmd :: Remove { target, toolchain } => target_remove ( cfg, target, toolchain) ,
340
384
} ,
385
+ RustupSubcmd :: Component { subcmd } => match subcmd {
386
+ ComponentSubcmd :: List {
387
+ toolchain,
388
+ installed,
389
+ } => handle_epipe ( component_list ( cfg, toolchain, installed) ) ,
390
+ ComponentSubcmd :: Add {
391
+ component,
392
+ toolchain,
393
+ target,
394
+ } => component_add ( cfg, component, toolchain, target. as_deref ( ) ) ,
395
+ ComponentSubcmd :: Remove {
396
+ component,
397
+ toolchain,
398
+ target,
399
+ } => component_remove ( cfg, component, toolchain, target. as_deref ( ) ) ,
400
+ } ,
341
401
}
342
402
}
343
403
}
@@ -416,18 +476,9 @@ pub fn main() -> Result<utils::ExitCode> {
416
476
( "dump-testament" , _) => common:: dump_testament ( ) ?,
417
477
(
418
478
"show" | "update" | "install" | "uninstall" | "toolchain" | "check" | "default"
419
- | "target" ,
479
+ | "target" | "component" ,
420
480
_,
421
481
) => Rustup :: from_arg_matches ( & matches) ?. dispatch ( cfg) ?,
422
- ( "component" , c) => match c. subcommand ( ) {
423
- Some ( s) => match s {
424
- ( "list" , m) => handle_epipe ( component_list ( cfg, m) ) ?,
425
- ( "add" , m) => component_add ( cfg, m) ?,
426
- ( "remove" , m) => component_remove ( cfg, m) ?,
427
- _ => unreachable ! ( ) ,
428
- } ,
429
- None => unreachable ! ( ) ,
430
- } ,
431
482
( "override" , c) => match c. subcommand ( ) {
432
483
Some ( s) => match s {
433
484
( "list" , _) => handle_epipe ( common:: list_overrides ( cfg) ) ?,
@@ -515,55 +566,6 @@ pub(crate) fn cli() -> Command {
515
566
. about ( "Dump information about the build" )
516
567
. hide ( true ) , // Not for users, only CI
517
568
)
518
- . subcommand (
519
- Command :: new ( "component" )
520
- . about ( "Modify a toolchain's installed components" )
521
- . subcommand_required ( true )
522
- . arg_required_else_help ( true )
523
- . subcommand (
524
- Command :: new ( "list" )
525
- . about ( "List installed and available components" )
526
- . arg (
527
- Arg :: new ( "toolchain" )
528
- . help ( OFFICIAL_TOOLCHAIN_ARG_HELP )
529
- . long ( "toolchain" )
530
- . num_args ( 1 )
531
- . value_parser ( partial_toolchain_desc_parser) ,
532
- )
533
- . arg (
534
- Arg :: new ( "installed" )
535
- . long ( "installed" )
536
- . help ( "List only installed components" )
537
- . action ( ArgAction :: SetTrue ) ,
538
- ) ,
539
- )
540
- . subcommand (
541
- Command :: new ( "add" )
542
- . about ( "Add a component to a Rust toolchain" )
543
- . arg ( Arg :: new ( "component" ) . required ( true ) . num_args ( 1 ..) )
544
- . arg (
545
- Arg :: new ( "toolchain" )
546
- . help ( OFFICIAL_TOOLCHAIN_ARG_HELP )
547
- . long ( "toolchain" )
548
- . num_args ( 1 )
549
- . value_parser ( partial_toolchain_desc_parser) ,
550
- )
551
- . arg ( Arg :: new ( "target" ) . long ( "target" ) . num_args ( 1 ) ) ,
552
- )
553
- . subcommand (
554
- Command :: new ( "remove" )
555
- . about ( "Remove a component from a Rust toolchain" )
556
- . arg ( Arg :: new ( "component" ) . required ( true ) . num_args ( 1 ..) )
557
- . arg (
558
- Arg :: new ( "toolchain" )
559
- . help ( OFFICIAL_TOOLCHAIN_ARG_HELP )
560
- . long ( "toolchain" )
561
- . num_args ( 1 )
562
- . value_parser ( partial_toolchain_desc_parser) ,
563
- )
564
- . arg ( Arg :: new ( "target" ) . long ( "target" ) . num_args ( 1 ) ) ,
565
- ) ,
566
- )
567
569
. subcommand (
568
570
Command :: new ( "override" )
569
571
. about ( "Modify toolchain overrides for directories" )
@@ -1260,40 +1262,56 @@ fn target_remove(
1260
1262
Ok ( utils:: ExitCode ( 0 ) )
1261
1263
}
1262
1264
1263
- fn component_list ( cfg : & Cfg , m : & ArgMatches ) -> Result < utils:: ExitCode > {
1264
- let toolchain = explicit_desc_or_dir_toolchain_old ( cfg, m) ?;
1265
+ fn component_list (
1266
+ cfg : & Cfg ,
1267
+ toolchain : Option < PartialToolchainDesc > ,
1268
+ installed_only : bool ,
1269
+ ) -> Result < utils:: ExitCode > {
1270
+ let toolchain = explicit_desc_or_dir_toolchain ( cfg, toolchain) ?;
1265
1271
// downcasting required because the toolchain files can name any toolchain
1266
1272
let distributable = ( & toolchain) . try_into ( ) ?;
1267
- common:: list_components ( distributable, m . get_flag ( "installed" ) ) ?;
1273
+ common:: list_components ( distributable, installed_only ) ?;
1268
1274
Ok ( utils:: ExitCode ( 0 ) )
1269
1275
}
1270
1276
1271
- fn component_add ( cfg : & Cfg , m : & ArgMatches ) -> Result < utils:: ExitCode > {
1272
- let toolchain = explicit_desc_or_dir_toolchain_old ( cfg, m) ?;
1277
+ fn component_add (
1278
+ cfg : & Cfg ,
1279
+ components : Vec < String > ,
1280
+ toolchain : Option < PartialToolchainDesc > ,
1281
+ target : Option < & str > ,
1282
+ ) -> Result < utils:: ExitCode > {
1283
+ let toolchain = explicit_desc_or_dir_toolchain ( cfg, toolchain) ?;
1273
1284
let distributable = DistributableToolchain :: try_from ( & toolchain) ?;
1274
- let target = get_target ( m , & distributable) ;
1285
+ let target = get_target ( target , & distributable) ;
1275
1286
1276
- for component in m . get_many :: < String > ( "component" ) . unwrap ( ) {
1287
+ for component in & components {
1277
1288
let new_component = Component :: try_new ( component, & distributable, target. as_ref ( ) ) ?;
1278
1289
distributable. add_component ( new_component) ?;
1279
1290
}
1280
1291
1281
1292
Ok ( utils:: ExitCode ( 0 ) )
1282
1293
}
1283
1294
1284
- fn get_target ( m : & ArgMatches , distributable : & DistributableToolchain < ' _ > ) -> Option < TargetTriple > {
1285
- m. get_one :: < String > ( "target" )
1286
- . map ( |s| & * * s)
1295
+ fn get_target (
1296
+ target : Option < & str > ,
1297
+ distributable : & DistributableToolchain < ' _ > ,
1298
+ ) -> Option < TargetTriple > {
1299
+ target
1287
1300
. map ( TargetTriple :: new)
1288
1301
. or_else ( || Some ( distributable. desc ( ) . target . clone ( ) ) )
1289
1302
}
1290
1303
1291
- fn component_remove ( cfg : & Cfg , m : & ArgMatches ) -> Result < utils:: ExitCode > {
1292
- let toolchain = explicit_desc_or_dir_toolchain_old ( cfg, m) ?;
1304
+ fn component_remove (
1305
+ cfg : & Cfg ,
1306
+ components : Vec < String > ,
1307
+ toolchain : Option < PartialToolchainDesc > ,
1308
+ target : Option < & str > ,
1309
+ ) -> Result < utils:: ExitCode > {
1310
+ let toolchain = explicit_desc_or_dir_toolchain ( cfg, toolchain) ?;
1293
1311
let distributable = DistributableToolchain :: try_from ( & toolchain) ?;
1294
- let target = get_target ( m , & distributable) ;
1312
+ let target = get_target ( target , & distributable) ;
1295
1313
1296
- for component in m . get_many :: < String > ( "component" ) . unwrap ( ) {
1314
+ for component in & components {
1297
1315
let new_component = Component :: try_new ( component, & distributable, target. as_ref ( ) ) ?;
1298
1316
distributable. remove_component ( new_component) ?;
1299
1317
}
0 commit comments