@@ -17,8 +17,9 @@ mod watch;
17
17
mod ws;
18
18
19
19
use anyhow:: { Context , Result } ;
20
- use clap:: { ArgAction , Parser , Subcommand } ;
20
+ use clap:: { ArgAction , Parser , Subcommand , ValueEnum } ;
21
21
use common:: STARTING ;
22
+ use std:: fmt:: Display ;
22
23
use std:: io:: IsTerminal ;
23
24
use std:: path:: PathBuf ;
24
25
use std:: process:: ExitCode ;
@@ -28,7 +29,13 @@ use tracing_subscriber::prelude::*;
28
29
async fn main ( ) -> Result < ExitCode > {
29
30
let cli = Trunk :: parse ( ) ;
30
31
31
- let colored = std:: io:: stdout ( ) . is_terminal ( ) && std:: env:: var_os ( "NO_COLOR" ) . is_none ( ) ;
32
+ let colored = match cli. color {
33
+ TrunkColorArgs :: Always => true ,
34
+ TrunkColorArgs :: Never => false ,
35
+ TrunkColorArgs :: Auto => {
36
+ std:: io:: stdout ( ) . is_terminal ( ) && std:: env:: var_os ( "NO_COLOR" ) . is_none ( )
37
+ }
38
+ } ;
32
39
33
40
#[ cfg( windows) ]
34
41
if colored {
@@ -117,6 +124,27 @@ struct Trunk {
117
124
/// Skip the version check
118
125
#[ arg( long, global( true ) , env = "TRUNK_SKIP_VERSION_CHECK" ) ]
119
126
pub skip_version_check : bool ,
127
+
128
+ /// Arg to specify ansi colored output for tracing logs
129
+ #[ arg( long, default_value_t = TrunkColorArgs :: Auto ) ]
130
+ pub color : TrunkColorArgs ,
131
+ }
132
+
133
+ #[ derive( ValueEnum , Clone ) ]
134
+ enum TrunkColorArgs {
135
+ Always ,
136
+ Auto ,
137
+ Never ,
138
+ }
139
+
140
+ impl Display for TrunkColorArgs {
141
+ fn fmt ( & self , f : & mut std:: fmt:: Formatter < ' _ > ) -> std:: fmt:: Result {
142
+ match self {
143
+ TrunkColorArgs :: Always => write ! ( f, "always" ) ,
144
+ TrunkColorArgs :: Auto => write ! ( f, "auto" ) ,
145
+ TrunkColorArgs :: Never => write ! ( f, "never" ) ,
146
+ }
147
+ }
120
148
}
121
149
122
150
impl Trunk {
0 commit comments