@@ -44,12 +44,14 @@ pub(crate) struct Run {
4444 #[ arg( long = "env" , value_name = "NAME=value" , num_args = 1 ) ]
4545 envs : Vec < String > ,
4646
47- /// The command to run
48- command : OsString ,
49-
50- /// Arguments to pass to the command
51- #[ arg( allow_hyphen_values = true , trailing_var_arg = true ) ]
52- args : Vec < OsString > ,
47+ /// The command to run, along with any arguments
48+ #[ arg(
49+ allow_hyphen_values = true ,
50+ trailing_var_arg = true ,
51+ value_name = "COMMAND" ,
52+ required = true
53+ ) ]
54+ command_and_args : Vec < OsString > ,
5355}
5456
5557impl Command for Run {
@@ -59,7 +61,13 @@ impl Command for Run {
5961 let envs = self . parse_envs ( ) ;
6062 let platform = self . parse_platform ( session) ?;
6163
62- match execute_tool ( & self . command , & self . args , & envs, platform, session) . into_result ( ) {
64+ // Safety: At least one value is required for `command_and_args`, so there must be at
65+ // least one value in the list. If no value is provided, Clap will show a "required
66+ // argument missing" message and this function won't be called.
67+ let command = & self . command_and_args [ 0 ] ;
68+ let args = & self . command_and_args [ 1 ..] ;
69+
70+ match execute_tool ( command, args, & envs, platform, session) . into_result ( ) {
6371 Ok ( ( ) ) => {
6472 session. add_event_end ( ActivityKind :: Run , ExitCode :: Success ) ;
6573 Ok ( ExitCode :: Success )
0 commit comments