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",
SilenceUsage: true,
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")
if err != nil {
return err
@ -39,6 +51,7 @@ var BacktestCmd = &cobra.Command{
return errors.New("--config option is required")
}
wantSync, err := cmd.Flags().GetBool("sync")
if err != nil {
return err
@ -119,18 +132,6 @@ var BacktestCmd = &cobra.Command{
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 {
return err
}