@@ -37,8 +37,7 @@ use crate::{
3737 toolchain:: {
3838 distributable:: DistributableToolchain ,
3939 names:: {
40- partial_toolchain_desc_parser, resolvable_local_toolchainame_parser,
41- resolvable_toolchainame_parser, CustomToolchainName , LocalToolchainName ,
40+ partial_toolchain_desc_parser, CustomToolchainName , LocalToolchainName ,
4241 MaybeResolvableToolchainName , ResolvableLocalToolchainName , ResolvableToolchainName ,
4342 ToolchainName ,
4443 } ,
@@ -95,6 +94,10 @@ enum RustupSubcmd {
9594 opts : UninstallOpts ,
9695 } ,
9796
97+ /// Dump information about the build
98+ #[ command( hide = true ) ]
99+ DumpTestament ,
100+
98101 /// Show the active and installed toolchains or profiles
99102 #[ command( after_help = SHOW_HELP ) ]
100103 Show {
@@ -162,6 +165,28 @@ enum RustupSubcmd {
162165 #[ command( subcommand) ]
163166 subcmd : OverrideSubcmd ,
164167 } ,
168+
169+ /// Run a command with an environment configured for a given toolchain
170+ #[ command( after_help = RUN_HELP , trailing_var_arg = true ) ]
171+ Run {
172+ #[ arg( help = RESOLVABLE_LOCAL_TOOLCHAIN_ARG_HELP ) ]
173+ toolchain : ResolvableLocalToolchainName ,
174+
175+ #[ arg( required = true , num_args = 1 .., use_value_delimiter = false ) ]
176+ command : Vec < String > ,
177+
178+ /// Install the requested toolchain if needed
179+ #[ arg( long) ]
180+ install : bool ,
181+ } ,
182+
183+ /// Display which binary will be run for a given command
184+ Which {
185+ command : String ,
186+
187+ #[ arg( long, help = RESOLVABLE_TOOLCHAIN_ARG_HELP ) ]
188+ toolchain : Option < ResolvableToolchainName > ,
189+ } ,
165190}
166191
167192#[ derive( Debug , Subcommand ) ]
@@ -381,6 +406,7 @@ enum OverrideSubcmd {
381406impl Rustup {
382407 fn dispatch ( self , cfg : & mut Cfg ) -> Result < utils:: ExitCode > {
383408 match self . subcmd {
409+ RustupSubcmd :: DumpTestament => common:: dump_testament ( ) ,
384410 RustupSubcmd :: Install { opts } => update ( cfg, opts) ,
385411 RustupSubcmd :: Uninstall { opts } => toolchain_remove ( cfg, opts) ,
386412 RustupSubcmd :: Show { verbose, subcmd } => match subcmd {
@@ -447,6 +473,12 @@ impl Rustup {
447473 override_remove ( cfg, path. as_deref ( ) , nonexistent)
448474 }
449475 } ,
476+ RustupSubcmd :: Run {
477+ toolchain,
478+ command,
479+ install,
480+ } => run ( cfg, toolchain, command, install) ,
481+ RustupSubcmd :: Which { command, toolchain } => which ( cfg, & command, toolchain) ,
450482 }
451483 }
452484}
@@ -522,14 +554,11 @@ pub fn main() -> Result<utils::ExitCode> {
522554
523555 Ok ( match matches. subcommand ( ) {
524556 Some ( s) => match s {
525- ( "dump-testament" , _) => common:: dump_testament ( ) ?,
526557 (
527- "show " | "update " | "install " | "uninstall " | "toolchain " | "check" | "default "
528- | "target" | "component" | "override" ,
558+ "dump-testament " | "show " | "update " | "install " | "uninstall " | "toolchain "
559+ | "check" | "default" | " target" | "component" | "override" | "run" | "which ",
529560 _,
530561 ) => Rustup :: from_arg_matches ( & matches) ?. dispatch ( cfg) ?,
531- ( "run" , m) => run ( cfg, m) ?,
532- ( "which" , m) => which ( cfg, m) ?,
533562 ( "doc" , m) => doc ( cfg, m) ?,
534563 #[ cfg( not( windows) ) ]
535564 ( "man" , m) => man ( cfg, m) ?,
@@ -601,48 +630,6 @@ pub(crate) fn cli() -> Command {
601630 }
602631 } ) ,
603632 )
604- . subcommand (
605- Command :: new ( "dump-testament" )
606- . about ( "Dump information about the build" )
607- . hide ( true ) , // Not for users, only CI
608- )
609- . subcommand (
610- Command :: new ( "run" )
611- . about ( "Run a command with an environment configured for a given toolchain" )
612- . after_help ( RUN_HELP )
613- . trailing_var_arg ( true )
614- . arg (
615- Arg :: new ( "toolchain" )
616- . help ( RESOLVABLE_LOCAL_TOOLCHAIN_ARG_HELP )
617- . required ( true )
618- . num_args ( 1 )
619- . value_parser ( resolvable_local_toolchainame_parser) ,
620- )
621- . arg (
622- Arg :: new ( "command" )
623- . required ( true )
624- . num_args ( 1 ..)
625- . use_value_delimiter ( false ) ,
626- )
627- . arg (
628- Arg :: new ( "install" )
629- . help ( "Install the requested toolchain if needed" )
630- . long ( "install" )
631- . action ( ArgAction :: SetTrue ) ,
632- ) ,
633- )
634- . subcommand (
635- Command :: new ( "which" )
636- . about ( "Display which binary will be run for a given command" )
637- . arg ( Arg :: new ( "command" ) . required ( true ) )
638- . arg (
639- Arg :: new ( "toolchain" )
640- . help ( RESOLVABLE_TOOLCHAIN_ARG_HELP )
641- . long ( "toolchain" )
642- . num_args ( 1 )
643- . value_parser ( resolvable_toolchainame_parser) ,
644- ) ,
645- )
646633 . subcommand (
647634 Command :: new ( "doc" )
648635 . alias ( "docs" )
@@ -965,22 +952,25 @@ fn update(cfg: &mut Cfg, opts: UpdateOpts) -> Result<utils::ExitCode> {
965952 Ok ( utils:: ExitCode ( 0 ) )
966953}
967954
968- fn run ( cfg : & Cfg , m : & ArgMatches ) -> Result < utils :: ExitCode > {
969- let toolchain = m
970- . get_one :: < ResolvableLocalToolchainName > ( "toolchain" )
971- . unwrap ( ) ;
972- let args = m . get_many :: < String > ( "command" ) . unwrap ( ) ;
973- let args : Vec < _ > = args . collect ( ) ;
955+ fn run (
956+ cfg : & Cfg ,
957+ toolchain : ResolvableLocalToolchainName ,
958+ command : Vec < String > ,
959+ install : bool ,
960+ ) -> Result < utils :: ExitCode > {
974961 let toolchain = toolchain. resolve ( & cfg. get_default_host_triple ( ) ?) ?;
975- let cmd = cfg. create_command_for_toolchain ( & toolchain, m . get_flag ( " install" ) , args [ 0 ] ) ?;
962+ let cmd = cfg. create_command_for_toolchain ( & toolchain, install, & command [ 0 ] ) ?;
976963
977- let code = command:: run_command_for_dir ( cmd, args [ 0 ] , & args [ 1 ..] ) ?;
964+ let code = command:: run_command_for_dir ( cmd, & command [ 0 ] , & command [ 1 ..] ) ?;
978965 Ok ( code)
979966}
980967
981- fn which ( cfg : & Cfg , m : & ArgMatches ) -> Result < utils:: ExitCode > {
982- let binary = m. get_one :: < String > ( "command" ) . unwrap ( ) ;
983- let binary_path = if let Some ( toolchain) = m. get_one :: < ResolvableToolchainName > ( "toolchain" ) {
968+ fn which (
969+ cfg : & Cfg ,
970+ binary : & str ,
971+ toolchain : Option < ResolvableToolchainName > ,
972+ ) -> Result < utils:: ExitCode > {
973+ let binary_path = if let Some ( toolchain) = toolchain {
984974 let desc = toolchain. resolve ( & cfg. get_default_host_triple ( ) ?) ?;
985975 Toolchain :: new ( cfg, desc. into ( ) ) ?. binary_file ( binary)
986976 } else {
0 commit comments