11package root
22
33import (
4- "os"
5-
64 "github.com/MakeNowJust/heredoc/v2"
75
86 "github.com/charmbracelet/log"
@@ -14,6 +12,7 @@ import (
1412 "github.com/ctrlplanedev/cli/cmd/ctrlc/root/sync"
1513 "github.com/ctrlplanedev/cli/cmd/ctrlc/root/version"
1614 "github.com/spf13/cobra"
15+ "github.com/spf13/viper"
1716)
1817
1918func NewRootCmd () * cobra.Command {
@@ -28,7 +27,11 @@ func NewRootCmd() *cobra.Command {
2827 $ ctrlc connect <agent-name>
2928 ` ),
3029 PersistentPreRunE : func (cmd * cobra.Command , args []string ) error {
31- switch logLevel {
30+ level := viper .GetString ("log-level" )
31+ if level == "" {
32+ level = logLevel
33+ }
34+ switch level {
3235 case "debug" :
3336 log .SetLevel (log .DebugLevel )
3437 case "info" :
@@ -45,7 +48,7 @@ func NewRootCmd() *cobra.Command {
4548 },
4649 }
4750
48- cmd .PersistentFlags ().StringVar (& logLevel , "log-level" , defaultOrEnv ( "info" , "CTRLC_LOG_LEVEL" ) , "Set the logging level (debug, info, warn, error)" )
51+ cmd .PersistentFlags ().StringVar (& logLevel , "log-level" , "info" , "Set the logging level (debug, info, warn, error)" )
4952
5053 cmd .AddCommand (agent .NewAgentCmd ())
5154 cmd .AddCommand (api .NewAPICmd ())
@@ -58,14 +61,3 @@ func NewRootCmd() *cobra.Command {
5861
5962 return cmd
6063}
61-
62- func defaultOrEnv (defaultValue string , envVarName string ) string {
63- if envVarName == "" {
64- return defaultValue
65- }
66- value , set := os .LookupEnv (envVarName )
67- if ! set {
68- value = defaultValue
69- }
70- return value
71- }
0 commit comments