@@ -1191,6 +1191,37 @@ fn should_print_version() -> bool {
1191
1191
print_version_state == PrintVersionState :: Enabled && ci_state == CIState :: Outside
1192
1192
}
1193
1193
1194
+ fn default_to_run_command ( cli_args : & Args ) -> Result < Command , Error > {
1195
+ let run_args = cli_args. run_args . clone ( ) . unwrap_or_default ( ) ;
1196
+ let execution_args = cli_args
1197
+ . execution_args
1198
+ // We clone instead of take as take would leave the command base a copy of cli_args
1199
+ // missing any execution args.
1200
+ . clone ( )
1201
+ . ok_or_else ( || Error :: NoCommand ( Backtrace :: capture ( ) ) ) ?;
1202
+
1203
+ if execution_args. tasks . is_empty ( ) {
1204
+ let mut cmd = <Args as CommandFactory >:: command ( ) ;
1205
+ let _ = cmd. print_help ( ) ;
1206
+ process:: exit ( 1 ) ;
1207
+ }
1208
+
1209
+ Ok ( Command :: Run {
1210
+ run_args : Box :: new ( run_args) ,
1211
+ execution_args : Box :: new ( execution_args) ,
1212
+ } )
1213
+ }
1214
+
1215
+ fn get_command ( cli_args : & mut Args ) -> Result < Command , Error > {
1216
+ if let Some ( command) = mem:: take ( & mut cli_args. command ) {
1217
+ Ok ( command)
1218
+ } else {
1219
+ // If there is no command, we set the command to `Command::Run` with
1220
+ // `self.parsed_args.run_args` as arguments.
1221
+ default_to_run_command ( cli_args)
1222
+ }
1223
+ }
1224
+
1194
1225
/// Runs the CLI by parsing arguments with clap, then either calling Rust code
1195
1226
/// directly or returning a payload for the Go code to use.
1196
1227
///
@@ -1227,30 +1258,7 @@ pub async fn run(
1227
1258
eprintln ! ( "{}\n " , GREY . apply_to( format!( "turbo {}" , get_version( ) ) ) ) ;
1228
1259
}
1229
1260
1230
- // If there is no command, we set the command to `Command::Run` with
1231
- // `self.parsed_args.run_args` as arguments.
1232
- let mut command = if let Some ( command) = mem:: take ( & mut cli_args. command ) {
1233
- command
1234
- } else {
1235
- let run_args = cli_args. run_args . clone ( ) . unwrap_or_default ( ) ;
1236
- let execution_args = cli_args
1237
- . execution_args
1238
- // We clone instead of take as take would leave the command base a copy of cli_args
1239
- // missing any execution args.
1240
- . clone ( )
1241
- . ok_or_else ( || Error :: NoCommand ( Backtrace :: capture ( ) ) ) ?;
1242
-
1243
- if execution_args. tasks . is_empty ( ) {
1244
- let mut cmd = <Args as CommandFactory >:: command ( ) ;
1245
- let _ = cmd. print_help ( ) ;
1246
- process:: exit ( 1 ) ;
1247
- }
1248
-
1249
- Command :: Run {
1250
- run_args : Box :: new ( run_args) ,
1251
- execution_args : Box :: new ( execution_args) ,
1252
- }
1253
- } ;
1261
+ let mut command = get_command ( & mut cli_args) ?;
1254
1262
1255
1263
// Set some run flags if we have the data and are executing a Run
1256
1264
match & mut command {
0 commit comments