@@ -93,8 +93,6 @@ you ran it on.
93
93
}
94
94
95
95
fn main ( ) {
96
- std:: panic:: set_hook ( Box :: new ( panic_hook) ) ;
97
-
98
96
let mut args = env:: args ( ) . skip ( 1 ) . collect :: < Vec < String > > ( ) ;
99
97
loop {
100
98
match std:: panic:: catch_unwind ( || {
@@ -115,42 +113,33 @@ fn main() {
115
113
}
116
114
117
115
pub fn run ( args : & [ String ] ) -> ExitCode {
118
- let output_stream = Arc :: new ( StandardStream :: stderr ( ColorChoice :: Auto ) ) ;
119
-
120
116
let mut app = clap:: App :: new ( "run" )
121
117
. about ( "Project script manager and executor" )
122
118
. version ( VERSION )
123
119
. author ( "TheOnlyMrCat" )
124
120
. setting ( clap:: AppSettings :: NoBinaryName )
125
121
. setting ( clap:: AppSettings :: TrailingVarArg )
126
122
. setting ( clap:: AppSettings :: DeriveDisplayOrder )
127
- . override_usage ( "run [OPTIONS] [TARGET] [ARGS]" )
123
+ . override_usage ( "run [OPTIONS] [TARGET:PHASE] [-- ] [ARGS]" )
128
124
. arg ( arg ! ( [ target] "Target to run in the script" ) . hide ( true ) )
129
125
. arg ( arg ! ( [ args] ... "Arguments to pass to the script" ) . hide ( true ) )
130
126
. arg (
131
127
arg ! ( -c --command <COMMAND > "Execute a command" )
132
128
. required ( false )
133
129
. value_hint ( ValueHint :: CommandString )
134
- . conflicts_with_all ( & [ "file" , "list" , "phase " , "target " , "args " ] )
130
+ . conflicts_with_all ( & [ "file" , "list" , "target " , "args " , "build" , "run" , "test "] )
135
131
)
136
132
. arg ( arg ! ( -f --file <FILE > "Explicitly specify a script file to run" ) . required ( false ) . value_hint ( ValueHint :: FilePath ) )
137
- . arg ( arg ! ( -l --list "List targets in the script file" ) )
138
- . help_heading ( "PHASE SELECTION" )
139
- . arg (
140
- arg ! ( -p --phase <PHASE > "Run a specific phase of the script" )
141
- . required ( false )
142
- . use_delimiter ( true )
143
- . default_value_if ( "build" , None , Some ( "build" ) )
144
- . default_value_if ( "run" , None , Some ( "run" ) )
145
- . conflicts_with ( "list" )
146
- )
133
+ . arg ( arg ! ( -l --list "List targets in the script file" ) . conflicts_with_all ( & [ "build" , "run" , "test" ] ) )
134
+ . arg ( arg ! ( --color <WHEN >) . possible_values ( & [ "auto" , "always" , "ansi" , "never" ] ) . required ( false ) . default_value ( "auto" ) )
147
135
. arg ( arg ! ( -b --build "Shorthand for `--phase build`" ) )
148
- . arg ( arg ! ( -r --run "Shorthand for `--phase run`" ) ) ;
136
+ . arg ( arg ! ( -r --run "Shorthand for `--phase run`" ) )
137
+ . arg ( arg ! ( -t --test "Shorthand for `--phase test`" ) ) ;
149
138
150
139
let options = match app. try_get_matches_from_mut ( args) {
151
140
Ok ( m) => m,
152
141
Err ( clap:: Error { kind : clap:: ErrorKind :: DisplayHelp , .. } ) => {
153
- app. print_help ( ) . expect ( "Failed to write clap help" ) ;
142
+ app. print_help ( ) . expect ( "Failed to print clap help" ) ;
154
143
return exitcode:: OK ;
155
144
}
156
145
Err ( clap:: Error { kind : clap:: ErrorKind :: DisplayVersion , .. } ) => {
@@ -171,12 +160,12 @@ pub fn run(args: &[String]) -> ExitCode {
171
160
config. set_default ( "colors.phases.enabled" , true ) . unwrap ( ) ;
172
161
if std:: env:: var_os ( "\x52 \x55 \x4E \x53 \x43 \x52 \x49 \x50 \x54 \x5F \x54 \x52 \x41 \x4E \x53 " ) . is_some ( ) {
173
162
config. set_default ( "colors.phases.build" , 6 ) . unwrap ( ) ;
174
- config. set_default ( "colors.phases.exec" , 7 ) . unwrap ( ) ;
175
163
config. set_default ( "colors.phases.run" , 13 ) . unwrap ( ) ;
164
+ config. set_default ( "colors.phases.test" , 7 ) . unwrap ( ) ;
176
165
} else {
177
166
config. set_default ( "colors.phases.build" , 1 ) . unwrap ( ) ;
178
- config. set_default ( "colors.phases.exec" , 2 ) . unwrap ( ) ;
179
167
config. set_default ( "colors.phases.run" , 4 ) . unwrap ( ) ;
168
+ config. set_default ( "colors.phases.test" , 2 ) . unwrap ( ) ;
180
169
}
181
170
config. set_default ( "dev.panic" , false ) . unwrap ( ) ;
182
171
@@ -195,7 +184,7 @@ pub fn run(args: &[String]) -> ExitCode {
195
184
} else {
196
185
#[ cfg( unix) ]
197
186
{
198
- config_dir = Some ( PathBuf :: from ( "~/.config/runscript" ) ) ;
187
+ config_dir = None ;
199
188
}
200
189
#[ cfg( windows) ]
201
190
unsafe {
@@ -226,8 +215,10 @@ pub fn run(args: &[String]) -> ExitCode {
226
215
config
227
216
} ;
228
217
229
- if config. get_bool ( "dev.panic" ) . unwrap_or ( false ) {
230
- let _ = std:: panic:: take_hook ( ) ;
218
+ let output_stream = Arc :: new ( StandardStream :: stderr ( ColorChoice :: Auto ) ) ;
219
+
220
+ if !config. get_bool ( "dev.panic" ) . unwrap_or ( false ) {
221
+ std:: panic:: set_hook ( Box :: new ( panic_hook) ) ;
231
222
}
232
223
233
224
let cwd = match env:: current_dir ( ) {
@@ -326,59 +317,34 @@ pub fn run(args: &[String]) -> ExitCode {
326
317
positional_args : options. values_of ( "args" ) . into_iter ( ) . flatten ( ) . map ( ToOwned :: to_owned) . collect ( ) ,
327
318
} ;
328
319
329
- let target = options. value_of ( "target" ) ;
320
+ let target = options. value_of ( "target" ) . unwrap_or ( "" ) ;
321
+ let ( target, phase) = target. split_once ( ':' ) . unwrap_or ( ( target, "run" ) ) ;
330
322
331
- match match & target {
332
- Some ( target) => rf. get_target ( target) ,
333
- None => rf. get_target ( "" ) ,
323
+ match if target. is_empty ( ) {
324
+ rf. get_default_target ( )
325
+ } else {
326
+ rf. get_target ( target)
334
327
} {
335
- Some ( target_scripts) => {
336
- let phase = options. value_of ( "phase" ) . unwrap_or ( "exec" ) ;
337
- if let Some ( script) = target_scripts. get ( phase) {
328
+ Some ( ( name, scripts) ) => {
329
+ if let Some ( script) = scripts. get ( phase) {
338
330
out:: phase_message (
339
331
& output_stream,
340
332
& config,
341
333
phase,
342
- target . unwrap_or ( "default" ) ,
334
+ name ,
343
335
) ;
344
336
exec_script ( script, & exec_cfg) . unwrap ( ) ;
345
337
exitcode:: OK
346
- } else if phase == "exec" {
347
- let build_script = target_scripts. get ( "build" ) ;
348
- let run_script = target_scripts. get ( "run" ) ;
349
- if build_script. is_none ( ) && run_script. is_none ( ) {
350
- out:: bad_script_phase ( & output_stream) ;
351
- exitcode:: NOINPUT
352
- } else {
353
- if let Some ( script) = build_script {
354
- out:: phase_message (
355
- & output_stream,
356
- & config,
357
- "build" ,
358
- target. unwrap_or ( "default" ) ,
359
- ) ;
360
- exec_script ( script, & exec_cfg) . unwrap ( ) ;
361
- }
362
- if let Some ( script) = run_script {
363
- out:: phase_message (
364
- & output_stream,
365
- & config,
366
- "run" ,
367
- target. unwrap_or ( "default" ) ,
368
- ) ;
369
- exec_script ( script, & exec_cfg) . unwrap ( ) ;
370
- }
371
- exitcode:: OK
372
- }
373
338
} else {
374
339
out:: bad_script_phase ( & output_stream) ;
375
340
exitcode:: NOINPUT
376
341
}
377
342
}
378
343
None => {
379
- match target {
380
- Some ( name) => out:: bad_target ( & output_stream, name) ,
381
- None => out:: bad_default ( & output_stream) ,
344
+ if target. is_empty ( ) {
345
+ out:: bad_default ( & output_stream) ;
346
+ } else {
347
+ out:: bad_target ( & output_stream, target) ;
382
348
}
383
349
exitcode:: NOINPUT
384
350
}
@@ -468,6 +434,7 @@ fn print_phase_list(
468
434
name_length
469
435
)
470
436
. expect ( "Failed to write" ) ;
437
+ //TODO: This could be configured
471
438
if target. contains_key ( "build" ) {
472
439
lock. set_color (
473
440
ColorSpec :: new ( )
@@ -487,47 +454,47 @@ fn print_phase_list(
487
454
. expect ( "Failed to set colour" ) ;
488
455
write ! ( lock, "." ) . unwrap ( ) ;
489
456
}
490
- if target. contains_key ( "exec " ) {
457
+ if target. contains_key ( "run " ) {
491
458
lock. set_color (
492
459
ColorSpec :: new ( )
493
460
. set_bold ( true )
494
461
. set_intense ( true )
495
- . set_fg ( Some ( out:: phase_color ( config, "exec " ) ) ) ,
462
+ . set_fg ( Some ( out:: phase_color ( config, "run " ) ) ) ,
496
463
)
497
464
. expect ( "Failed to set colour" ) ;
498
- write ! ( lock, "& " ) . unwrap ( ) ;
465
+ write ! ( lock, "R " ) . unwrap ( ) ;
499
466
} else {
500
467
lock. set_color (
501
468
ColorSpec :: new ( )
502
469
. set_bold ( false )
503
470
. set_intense ( false )
504
- . set_fg ( Some ( out:: phase_color ( config, "exec " ) ) ) ,
471
+ . set_fg ( Some ( out:: phase_color ( config, "run " ) ) ) ,
505
472
)
506
473
. expect ( "Failed to set colour" ) ;
507
474
write ! ( lock, "." ) . unwrap ( ) ;
508
475
}
509
- if target. contains_key ( "run " ) {
476
+ if target. contains_key ( "test " ) {
510
477
lock. set_color (
511
478
ColorSpec :: new ( )
512
479
. set_bold ( true )
513
480
. set_intense ( true )
514
- . set_fg ( Some ( out:: phase_color ( config, "run " ) ) ) ,
481
+ . set_fg ( Some ( out:: phase_color ( config, "test " ) ) ) ,
515
482
)
516
483
. expect ( "Failed to set colour" ) ;
517
- write ! ( lock, "R " ) . unwrap ( ) ;
484
+ write ! ( lock, "T " ) . unwrap ( ) ;
518
485
} else {
519
486
lock. set_color (
520
487
ColorSpec :: new ( )
521
488
. set_bold ( false )
522
489
. set_intense ( false )
523
- . set_fg ( Some ( out:: phase_color ( config, "run " ) ) ) ,
490
+ . set_fg ( Some ( out:: phase_color ( config, "test " ) ) ) ,
524
491
)
525
492
. expect ( "Failed to set colour" ) ;
526
493
write ! ( lock, "." ) . unwrap ( ) ;
527
494
}
528
495
529
496
for phase in target. keys ( ) {
530
- if phase == "exec " || phase == "build" || phase == "run" {
497
+ if phase == "test " || phase == "build" || phase == "run" {
531
498
continue ;
532
499
}
533
500
lock. set_color (
0 commit comments