22// Licensed under the MIT License.
33
44use atty:: Stream ;
5- use clap:: { Parser } ;
5+ use clap:: Parser ;
66use std:: { io:: { self , Read } , process:: exit} ;
77use tracing:: { error, warn, debug} ;
88
9- use args:: { Arguments , SubCommand } ;
10- use runcommand:: { RunCommand } ;
9+ use args:: { Arguments , SubCommand , TraceLevel } ;
10+ use runcommand:: RunCommand ;
1111use utils:: { enable_tracing, invoke_command, parse_input, EXIT_INVALID_ARGS } ;
1212
1313pub mod args;
@@ -16,7 +16,29 @@ pub mod utils;
1616
1717fn main ( ) {
1818 let args = Arguments :: parse ( ) ;
19- enable_tracing ( & args. trace_level , & args. trace_format ) ;
19+ let trace_level = match args. trace_level {
20+ Some ( trace_level) => trace_level,
21+ None => {
22+ // get from DSC_TRACE_LEVEL env var
23+ if let Ok ( trace_level) = std:: env:: var ( "DSC_TRACE_LEVEL" ) {
24+ match trace_level. to_lowercase ( ) . as_str ( ) {
25+ "error" => TraceLevel :: Error ,
26+ "warn" => TraceLevel :: Warn ,
27+ "info" => TraceLevel :: Info ,
28+ "debug" => TraceLevel :: Debug ,
29+ "trace" => TraceLevel :: Trace ,
30+ _ => {
31+ warn ! ( "Invalid trace level: {trace_level}" ) ;
32+ TraceLevel :: Info
33+ }
34+ }
35+ } else {
36+ // default to info
37+ TraceLevel :: Info
38+ }
39+ }
40+ } ;
41+ enable_tracing ( & trace_level, & args. trace_format ) ;
2042 warn ! ( "This resource is not idempotent" ) ;
2143
2244 let stdin = if atty:: is ( Stream :: Stdin ) {
0 commit comments