@@ -144,6 +144,12 @@ enum RustupSubcmd {
144
144
#[ command( subcommand) ]
145
145
subcmd : ToolchainSubcmd ,
146
146
} ,
147
+
148
+ /// Modify a toolchain's supported targets
149
+ Target {
150
+ #[ command( subcommand) ]
151
+ subcmd : TargetSubcmd ,
152
+ } ,
147
153
}
148
154
149
155
#[ derive( Debug , Subcommand ) ]
@@ -249,6 +255,45 @@ struct UninstallOpts {
249
255
toolchain : Vec < ResolvableToolchainName > ,
250
256
}
251
257
258
+ #[ derive( Debug , Subcommand ) ]
259
+ #[ command( arg_required_else_help = true , subcommand_required = true ) ]
260
+ enum TargetSubcmd {
261
+ /// List installed and available targets
262
+ List {
263
+ #[ arg(
264
+ long,
265
+ help = OFFICIAL_TOOLCHAIN_ARG_HELP ,
266
+ ) ]
267
+ toolchain : Option < PartialToolchainDesc > ,
268
+
269
+ /// List only installed targets
270
+ #[ arg( long) ]
271
+ installed : bool ,
272
+ } ,
273
+
274
+ /// Add a target to a Rust toolchain
275
+ #[ command( alias = "install" ) ]
276
+ Add {
277
+ /// List of targets to install; "all" installs all available targets
278
+ #[ arg( required = true , num_args = 1 ..) ]
279
+ target : Vec < String > ,
280
+
281
+ #[ arg( long, help = OFFICIAL_TOOLCHAIN_ARG_HELP ) ]
282
+ toolchain : Option < PartialToolchainDesc > ,
283
+ } ,
284
+
285
+ /// Remove a target from a Rust toolchain
286
+ #[ command( alias = "uninstall" ) ]
287
+ Remove {
288
+ /// List of targets to uninstall
289
+ #[ arg( required = true , num_args = 1 ..) ]
290
+ target : Vec < String > ,
291
+
292
+ #[ arg( long, help = OFFICIAL_TOOLCHAIN_ARG_HELP ) ]
293
+ toolchain : Option < PartialToolchainDesc > ,
294
+ } ,
295
+ }
296
+
252
297
impl Rustup {
253
298
fn dispatch ( self , cfg : & mut Cfg ) -> Result < utils:: ExitCode > {
254
299
match self . subcmd {
@@ -285,6 +330,14 @@ impl Rustup {
285
330
} ,
286
331
RustupSubcmd :: Check => check_updates ( cfg) ,
287
332
RustupSubcmd :: Default { toolchain } => default_ ( cfg, toolchain) ,
333
+ RustupSubcmd :: Target { subcmd } => match subcmd {
334
+ TargetSubcmd :: List {
335
+ toolchain,
336
+ installed,
337
+ } => handle_epipe ( target_list ( cfg, toolchain, installed) ) ,
338
+ TargetSubcmd :: Add { target, toolchain } => target_add ( cfg, target, toolchain) ,
339
+ TargetSubcmd :: Remove { target, toolchain } => target_remove ( cfg, target, toolchain) ,
340
+ } ,
288
341
}
289
342
}
290
343
}
@@ -362,18 +415,10 @@ pub fn main() -> Result<utils::ExitCode> {
362
415
Some ( s) => match s {
363
416
( "dump-testament" , _) => common:: dump_testament ( ) ?,
364
417
(
365
- "show" | "update" | "install" | "uninstall" | "toolchain" | "check" | "default" ,
418
+ "show" | "update" | "install" | "uninstall" | "toolchain" | "check" | "default"
419
+ | "target" ,
366
420
_,
367
421
) => Rustup :: from_arg_matches ( & matches) ?. dispatch ( cfg) ?,
368
- ( "target" , c) => match c. subcommand ( ) {
369
- Some ( s) => match s {
370
- ( "list" , m) => handle_epipe ( target_list ( cfg, m) ) ?,
371
- ( "add" , m) => target_add ( cfg, m) ?,
372
- ( "remove" , m) => target_remove ( cfg, m) ?,
373
- _ => unreachable ! ( ) ,
374
- } ,
375
- None => unreachable ! ( ) ,
376
- } ,
377
422
( "component" , c) => match c. subcommand ( ) {
378
423
Some ( s) => match s {
379
424
( "list" , m) => handle_epipe ( component_list ( cfg, m) ) ?,
@@ -470,63 +515,6 @@ pub(crate) fn cli() -> Command {
470
515
. about ( "Dump information about the build" )
471
516
. hide ( true ) , // Not for users, only CI
472
517
)
473
- . subcommand (
474
- Command :: new ( "target" )
475
- . about ( "Modify a toolchain's supported targets" )
476
- . subcommand_required ( true )
477
- . arg_required_else_help ( true )
478
- . subcommand (
479
- Command :: new ( "list" )
480
- . about ( "List installed and available targets" )
481
- . arg (
482
- Arg :: new ( "toolchain" )
483
- . help ( OFFICIAL_TOOLCHAIN_ARG_HELP )
484
- . long ( "toolchain" )
485
- . value_parser ( partial_toolchain_desc_parser)
486
- . num_args ( 1 ) ,
487
- )
488
- . arg (
489
- Arg :: new ( "installed" )
490
- . long ( "installed" )
491
- . help ( "List only installed targets" )
492
- . action ( ArgAction :: SetTrue ) ,
493
- ) ,
494
- )
495
- . subcommand (
496
- Command :: new ( "add" )
497
- . about ( "Add a target to a Rust toolchain" )
498
- . alias ( "install" )
499
- . arg ( Arg :: new ( "target" ) . required ( true ) . num_args ( 1 ..) . help (
500
- "List of targets to install; \
501
- \" all\" installs all available targets",
502
- ) )
503
- . arg (
504
- Arg :: new ( "toolchain" )
505
- . help ( OFFICIAL_TOOLCHAIN_ARG_HELP )
506
- . long ( "toolchain" )
507
- . num_args ( 1 )
508
- . value_parser ( partial_toolchain_desc_parser) ,
509
- ) ,
510
- )
511
- . subcommand (
512
- Command :: new ( "remove" )
513
- . about ( "Remove a target from a Rust toolchain" )
514
- . alias ( "uninstall" )
515
- . arg (
516
- Arg :: new ( "target" )
517
- . help ( "List of targets to uninstall" )
518
- . required ( true )
519
- . num_args ( 1 ..) ,
520
- )
521
- . arg (
522
- Arg :: new ( "toolchain" )
523
- . help ( OFFICIAL_TOOLCHAIN_ARG_HELP )
524
- . long ( "toolchain" )
525
- . num_args ( 1 )
526
- . value_parser ( partial_toolchain_desc_parser) ,
527
- ) ,
528
- ) ,
529
- )
530
518
. subcommand (
531
519
Command :: new ( "component" )
532
520
. about ( "Modify a toolchain's installed components" )
@@ -1176,27 +1164,30 @@ fn show_rustup_home(cfg: &Cfg) -> Result<utils::ExitCode> {
1176
1164
Ok ( utils:: ExitCode ( 0 ) )
1177
1165
}
1178
1166
1179
- fn target_list ( cfg : & Cfg , m : & ArgMatches ) -> Result < utils:: ExitCode > {
1180
- let toolchain = explicit_desc_or_dir_toolchain ( cfg, m) ?;
1167
+ fn target_list (
1168
+ cfg : & Cfg ,
1169
+ toolchain : Option < PartialToolchainDesc > ,
1170
+ installed_only : bool ,
1171
+ ) -> Result < utils:: ExitCode > {
1172
+ let toolchain = explicit_desc_or_dir_toolchain ( cfg, toolchain) ?;
1181
1173
// downcasting required because the toolchain files can name any toolchain
1182
1174
let distributable = ( & toolchain) . try_into ( ) ?;
1183
- common:: list_targets ( distributable, m . get_flag ( "installed" ) )
1175
+ common:: list_targets ( distributable, installed_only )
1184
1176
}
1185
1177
1186
- fn target_add ( cfg : & Cfg , m : & ArgMatches ) -> Result < utils:: ExitCode > {
1187
- let toolchain = explicit_desc_or_dir_toolchain ( cfg, m) ?;
1178
+ fn target_add (
1179
+ cfg : & Cfg ,
1180
+ mut targets : Vec < String > ,
1181
+ toolchain : Option < PartialToolchainDesc > ,
1182
+ ) -> Result < utils:: ExitCode > {
1183
+ let toolchain = explicit_desc_or_dir_toolchain ( cfg, toolchain) ?;
1188
1184
// XXX: long term move this error to cli ? the normal .into doesn't work
1189
1185
// because Result here is the wrong sort and expression type ascription
1190
1186
// isn't a feature yet.
1191
1187
// list_components *and* add_component would both be inappropriate for
1192
1188
// custom toolchains.
1193
1189
let distributable = DistributableToolchain :: try_from ( & toolchain) ?;
1194
1190
let components = distributable. components ( ) ?;
1195
- let mut targets: Vec < _ > = m
1196
- . get_many :: < String > ( "target" )
1197
- . unwrap ( )
1198
- . map ( ToOwned :: to_owned)
1199
- . collect ( ) ;
1200
1191
1201
1192
if targets. contains ( & "all" . to_string ( ) ) {
1202
1193
if targets. len ( ) != 1 {
@@ -1234,12 +1225,16 @@ fn target_add(cfg: &Cfg, m: &ArgMatches) -> Result<utils::ExitCode> {
1234
1225
Ok ( utils:: ExitCode ( 0 ) )
1235
1226
}
1236
1227
1237
- fn target_remove ( cfg : & Cfg , m : & ArgMatches ) -> Result < utils:: ExitCode > {
1238
- let toolchain = explicit_desc_or_dir_toolchain ( cfg, m) ?;
1228
+ fn target_remove (
1229
+ cfg : & Cfg ,
1230
+ targets : Vec < String > ,
1231
+ toolchain : Option < PartialToolchainDesc > ,
1232
+ ) -> Result < utils:: ExitCode > {
1233
+ let toolchain = explicit_desc_or_dir_toolchain ( cfg, toolchain) ?;
1239
1234
let distributable = DistributableToolchain :: try_from ( & toolchain) ?;
1240
1235
1241
- for target in m . get_many :: < String > ( "target" ) . unwrap ( ) {
1242
- let target = TargetTriple :: new ( target) ;
1236
+ for target in targets {
1237
+ let target = TargetTriple :: new ( & target) ;
1243
1238
let default_target = cfg. get_default_host_triple ( ) ?;
1244
1239
if target == default_target {
1245
1240
warn ! ( "after removing the default host target, proc-macros and build scripts might no longer build" ) ;
@@ -1266,15 +1261,15 @@ fn target_remove(cfg: &Cfg, m: &ArgMatches) -> Result<utils::ExitCode> {
1266
1261
}
1267
1262
1268
1263
fn component_list ( cfg : & Cfg , m : & ArgMatches ) -> Result < utils:: ExitCode > {
1269
- let toolchain = explicit_desc_or_dir_toolchain ( cfg, m) ?;
1264
+ let toolchain = explicit_desc_or_dir_toolchain_old ( cfg, m) ?;
1270
1265
// downcasting required because the toolchain files can name any toolchain
1271
1266
let distributable = ( & toolchain) . try_into ( ) ?;
1272
1267
common:: list_components ( distributable, m. get_flag ( "installed" ) ) ?;
1273
1268
Ok ( utils:: ExitCode ( 0 ) )
1274
1269
}
1275
1270
1276
1271
fn component_add ( cfg : & Cfg , m : & ArgMatches ) -> Result < utils:: ExitCode > {
1277
- let toolchain = explicit_desc_or_dir_toolchain ( cfg, m) ?;
1272
+ let toolchain = explicit_desc_or_dir_toolchain_old ( cfg, m) ?;
1278
1273
let distributable = DistributableToolchain :: try_from ( & toolchain) ?;
1279
1274
let target = get_target ( m, & distributable) ;
1280
1275
@@ -1294,7 +1289,7 @@ fn get_target(m: &ArgMatches, distributable: &DistributableToolchain<'_>) -> Opt
1294
1289
}
1295
1290
1296
1291
fn component_remove ( cfg : & Cfg , m : & ArgMatches ) -> Result < utils:: ExitCode > {
1297
- let toolchain = explicit_desc_or_dir_toolchain ( cfg, m) ?;
1292
+ let toolchain = explicit_desc_or_dir_toolchain_old ( cfg, m) ?;
1298
1293
let distributable = DistributableToolchain :: try_from ( & toolchain) ?;
1299
1294
let target = get_target ( m, & distributable) ;
1300
1295
@@ -1308,13 +1303,21 @@ fn component_remove(cfg: &Cfg, m: &ArgMatches) -> Result<utils::ExitCode> {
1308
1303
1309
1304
// Make *sure* only to use this for a subcommand whose "toolchain" argument
1310
1305
// has .value_parser(partial_toolchain_desc_parser), or it will panic.
1311
- fn explicit_desc_or_dir_toolchain < ' a > ( cfg : & ' a Cfg , m : & ArgMatches ) -> Result < Toolchain < ' a > > {
1306
+ // FIXME: Delete this.
1307
+ fn explicit_desc_or_dir_toolchain_old < ' a > ( cfg : & ' a Cfg , m : & ArgMatches ) -> Result < Toolchain < ' a > > {
1312
1308
let toolchain = m
1313
1309
. get_one :: < PartialToolchainDesc > ( "toolchain" )
1314
1310
. map ( Into :: into) ;
1315
1311
explicit_or_dir_toolchain2 ( cfg, toolchain)
1316
1312
}
1317
1313
1314
+ fn explicit_desc_or_dir_toolchain (
1315
+ cfg : & Cfg ,
1316
+ toolchain : Option < PartialToolchainDesc > ,
1317
+ ) -> Result < Toolchain < ' _ > > {
1318
+ explicit_or_dir_toolchain2 ( cfg, toolchain. map ( |it| ( & it) . into ( ) ) )
1319
+ }
1320
+
1318
1321
fn explicit_or_dir_toolchain2 (
1319
1322
cfg : & Cfg ,
1320
1323
toolchain : Option < ResolvableToolchainName > ,
@@ -1458,7 +1461,7 @@ const DOCS_DATA: &[(&str, &str, &str)] = &[
1458
1461
] ;
1459
1462
1460
1463
fn doc ( cfg : & Cfg , m : & ArgMatches ) -> Result < utils:: ExitCode > {
1461
- let toolchain = explicit_desc_or_dir_toolchain ( cfg, m) ?;
1464
+ let toolchain = explicit_desc_or_dir_toolchain_old ( cfg, m) ?;
1462
1465
1463
1466
if let Ok ( distributable) = DistributableToolchain :: try_from ( & toolchain) {
1464
1467
if let [ _] = distributable
@@ -1522,7 +1525,7 @@ fn man(cfg: &Cfg, m: &ArgMatches) -> Result<utils::ExitCode> {
1522
1525
1523
1526
let command = m. get_one :: < String > ( "command" ) . unwrap ( ) ;
1524
1527
1525
- let toolchain = explicit_desc_or_dir_toolchain ( cfg, m) ?;
1528
+ let toolchain = explicit_desc_or_dir_toolchain_old ( cfg, m) ?;
1526
1529
let mut path = toolchain. path ( ) . to_path_buf ( ) ;
1527
1530
path. push ( "share" ) ;
1528
1531
path. push ( "man" ) ;
0 commit comments