From 1a81813e17c76266cd691436eba9b85599c5502c Mon Sep 17 00:00:00 2001 From: c9s Date: Thu, 6 May 2021 23:44:05 +0800 Subject: [PATCH] add --session option check --- pkg/cmd/account.go | 14 +++++++++----- pkg/cmd/balances.go | 14 ++++++++++---- 2 files changed, 19 insertions(+), 9 deletions(-) diff --git a/pkg/cmd/account.go b/pkg/cmd/account.go index 31d39fdea..94861e5cf 100644 --- a/pkg/cmd/account.go +++ b/pkg/cmd/account.go @@ -33,6 +33,15 @@ var accountCmd = &cobra.Command{ return errors.New("--config option is required") } + sessionName, err := cmd.Flags().GetString("session") + if err != nil { + return err + } + + if len(sessionName) == 0 { + return errors.New("--session option is required") + } + var userConfig *bbgo.Config if _, err := os.Stat(configFile); err == nil { // load successfully @@ -57,11 +66,6 @@ var accountCmd = &cobra.Command{ return err } - sessionName, err := cmd.Flags().GetString("session") - if err != nil { - return err - } - session, ok := environ.Session(sessionName) if !ok { return fmt.Errorf("session %s not found", sessionName) diff --git a/pkg/cmd/balances.go b/pkg/cmd/balances.go index 3694b1da8..b84d83eca 100644 --- a/pkg/cmd/balances.go +++ b/pkg/cmd/balances.go @@ -24,6 +24,7 @@ var balancesCmd = &cobra.Command{ RunE: func(cmd *cobra.Command, args []string) error { ctx := context.Background() + configFile, err := cmd.Flags().GetString("config") if err != nil { return err @@ -33,6 +34,15 @@ var balancesCmd = &cobra.Command{ return errors.New("--config option is required") } + sessionName, err := cmd.Flags().GetString("session") + if err != nil { + return err + } + + if len(sessionName) == 0 { + return errors.New("--session option is required") + } + // if config file exists, use the config loaded from the config file. // otherwise, use a empty config object var userConfig *bbgo.Config @@ -56,10 +66,6 @@ var balancesCmd = &cobra.Command{ return err } - sessionName, err := cmd.Flags().GetString("session") - if err != nil { - return err - } session, ok := environ.Session(sessionName) if !ok {