move verbose flag detection before we setup the environment

This commit is contained in:
c9s 2020-11-09 16:49:03 +08:00
parent 6c2aef31a3
commit f5b17193c5

View File

@ -30,6 +30,18 @@ var BacktestCmd = &cobra.Command{
Short: "backtest your strategies", Short: "backtest your strategies",
SilenceUsage: true, SilenceUsage: true,
RunE: func(cmd *cobra.Command, args []string) error { RunE: func(cmd *cobra.Command, args []string) error {
log.SetLevel(log.ErrorLevel)
verboseCnt, err := cmd.Flags().GetCount("verbose")
if err != nil {
return err
}
if verboseCnt == 2 {
log.SetLevel(log.DebugLevel)
} else if verboseCnt > 0 {
log.SetLevel(log.InfoLevel)
}
configFile, err := cmd.Flags().GetString("config") configFile, err := cmd.Flags().GetString("config")
if err != nil { if err != nil {
return err return err
@ -39,6 +51,7 @@ var BacktestCmd = &cobra.Command{
return errors.New("--config option is required") return errors.New("--config option is required")
} }
wantSync, err := cmd.Flags().GetBool("sync") wantSync, err := cmd.Flags().GetBool("sync")
if err != nil { if err != nil {
return err return err
@ -119,18 +132,6 @@ var BacktestCmd = &cobra.Command{
log.Warnf("backtest does not support CrossExchangeStrategy, strategies won't be added.") log.Warnf("backtest does not support CrossExchangeStrategy, strategies won't be added.")
} }
log.SetLevel(log.ErrorLevel)
verboseCnt, err := cmd.Flags().GetCount("verbose")
if err != nil {
return err
}
if verboseCnt == 2 {
log.SetLevel(log.DebugLevel)
} else if verboseCnt > 0 {
log.SetLevel(log.InfoLevel)
}
if err := trader.Run(ctx); err != nil { if err := trader.Run(ctx); err != nil {
return err return err
} }