@@ -5,7 +5,10 @@ use console::style;
5
5
use indicatif:: { ProgressBar , ProgressStyle } ;
6
6
use tokio:: { io:: AsyncBufReadExt , process:: Command } ;
7
7
8
- use crate :: { app:: App , model:: { HookEvent , HookFailBehavior } } ;
8
+ use crate :: {
9
+ app:: App ,
10
+ model:: { HookEvent , HookFailBehavior } ,
11
+ } ;
9
12
10
13
pub struct HooksAPI < ' a > ( pub & ' a App ) ;
11
14
@@ -45,7 +48,8 @@ impl<'a> HooksAPI<'a> {
45
48
continue ;
46
49
}
47
50
48
- let spinner = self . 0
51
+ let spinner = self
52
+ . 0
49
53
. multi_progress
50
54
. add (
51
55
ProgressBar :: new_spinner ( ) . with_style ( ProgressStyle :: with_template (
@@ -54,10 +58,11 @@ impl<'a> HooksAPI<'a> {
54
58
) ;
55
59
56
60
spinner. enable_steady_tick ( Duration :: from_millis ( 200 ) ) ;
57
- spinner. set_prefix ( format ! (
58
- "Running hook {}" ,
59
- style( filename. clone( ) ) . blue( )
60
- ) ) ;
61
+ spinner. set_prefix ( format ! ( "Running hook {}" , style( filename. clone( ) ) . blue( ) ) ) ;
62
+
63
+ if hook. show_output {
64
+ self . 0 . log_dev ( format ! ( "Running {filename}" ) ) ;
65
+ }
61
66
62
67
let mut cmd = Command :: new ( path) ;
63
68
cmd. kill_on_drop ( true )
@@ -68,8 +73,7 @@ impl<'a> HooksAPI<'a> {
68
73
cmd. env ( k, v) ;
69
74
}
70
75
71
- let mut child = cmd. spawn ( )
72
- . context ( format ! ( "Spawning hook {filename}" ) ) ?;
76
+ let mut child = cmd. spawn ( ) . context ( format ! ( "Spawning hook {filename}" ) ) ?;
73
77
74
78
let stdout = child. stdout . take ( ) . unwrap ( ) ;
75
79
let mut lines = tokio:: io:: BufReader :: new ( stdout) . lines ( ) ;
@@ -78,23 +82,21 @@ impl<'a> HooksAPI<'a> {
78
82
spinner. set_message ( line. clone ( ) ) ;
79
83
if hook. show_output {
80
84
self . 0 . multi_progress . suspend ( || {
81
- println ! (
82
- "{}{}" ,
83
- style( "| " ) . bold( ) ,
84
- line. trim( )
85
- ) ;
85
+ println ! ( "{}{}" , style( "| " ) . bold( ) , line. trim( ) ) ;
86
86
} ) ;
87
87
}
88
88
}
89
89
90
- let status = child. wait ( ) . await
90
+ let status = child
91
+ . wait ( )
92
+ . await
91
93
. context ( format ! ( "waiting hook {filename}" ) ) ?;
92
94
spinner. finish_and_clear ( ) ;
93
95
if status. success ( ) {
94
96
self . 0 . success ( format ! ( "Hook {filename}" ) ) ;
95
97
} else {
96
98
match hook. onfail {
97
- HookFailBehavior :: Ignore => { } ,
99
+ HookFailBehavior :: Ignore => { }
98
100
HookFailBehavior :: Warn => self . 0 . warn ( format ! ( "Hook {filename} failed" ) ) ,
99
101
HookFailBehavior :: Error => bail ! ( "Hook {filename} failed" ) ,
100
102
}
0 commit comments