@@ -43,9 +43,9 @@ import (
4343)
4444
4545var (
46- cfgFile string
47- verbosity int
48- pretty bool
46+ cfgFile string
47+ verbosityInput string
48+ pretty bool
4949)
5050
5151// rootCmd represents the base command when called without any subcommands
@@ -97,20 +97,32 @@ func NewPolycliCommand() *cobra.Command {
9797 Use : "polycli" ,
9898 Short : "A Swiss Army knife of blockchain tools." ,
9999 Long : "Polycli is a collection of tools that are meant to be useful while building, testing, and running block chain applications." ,
100- PersistentPreRun : func (cmd * cobra.Command , args []string ) {
100+ PersistentPreRunE : func (cmd * cobra.Command , args []string ) error {
101+ verbosity , err := util .ParseVerbosity (verbosityInput )
102+ if err != nil {
103+ return err
104+ }
101105 util .SetLogLevel (verbosity )
102106 logMode := util .JSON
103107 if pretty {
104108 logMode = util .Console
105109 }
106- _ = util .SetLogMode (logMode )
110+ return util .SetLogMode (logMode )
107111 },
108112 }
109113
110114 // Define flags and configuration settings.
111115 f := cmd .PersistentFlags ()
112116 f .StringVar (& cfgFile , "config" , "" , "config file (default is $HOME/.polygon-cli.yaml)" )
113- f .IntVarP (& verbosity , "verbosity" , "v" , 500 , "0 - silent\n 100 panic\n 200 fatal\n 300 error\n 400 warning\n 500 info\n 600 debug\n 700 trace" )
117+ f .StringVarP (& verbosityInput , "verbosity" , "v" , "info" , `log level (string or int):
118+ 0 - silent
119+ 100 - panic
120+ 200 - fatal
121+ 300 - error
122+ 400 - warn
123+ 500 - info (default)
124+ 600 - debug
125+ 700 - trace` )
114126 f .BoolVar (& pretty , "pretty-logs" , true , "output logs in pretty format instead of JSON" )
115127
116128 // Define local flags which will only run when this action is called directly.
0 commit comments