diff --git a/app/client/cli/account.go b/app/client/cli/account.go index f171639db..e2650bf99 100644 --- a/app/client/cli/account.go +++ b/app/client/cli/account.go @@ -2,10 +2,11 @@ package cli import ( "fmt" + "github.com/spf13/cobra" + "github.com/pokt-network/pocket/app/client/cli/flags" "github.com/pokt-network/pocket/shared/crypto" "github.com/pokt-network/pocket/utility/types" - "github.com/spf13/cobra" ) func init() { @@ -48,7 +49,7 @@ func accountCommands() []*cobra.Command { return err } - if !nonInteractive { + if !flags.NonInteractive { pwd = readPassphrase(pwd) } diff --git a/app/client/cli/actor.go b/app/client/cli/actor.go index 04a0ab81f..6486d4910 100644 --- a/app/client/cli/actor.go +++ b/app/client/cli/actor.go @@ -6,10 +6,12 @@ import ( "regexp" "strings" + "github.com/spf13/cobra" + + "github.com/pokt-network/pocket/app/client/cli/flags" coreTypes "github.com/pokt-network/pocket/shared/core/types" "github.com/pokt-network/pocket/shared/crypto" typesUtil "github.com/pokt-network/pocket/utility/types" - "github.com/spf13/cobra" ) func init() { @@ -100,7 +102,7 @@ If no changes are desired for the parameter, just enter the current param value return err } - if !nonInteractive { + if !flags.NonInteractive { pwd = readPassphrase(pwd) } @@ -169,7 +171,7 @@ func newEditStakeCmd(cmdDef actorCmdDef) *cobra.Command { return err } - if !nonInteractive { + if !flags.NonInteractive { pwd = readPassphrase(pwd) } @@ -233,7 +235,7 @@ func newUnstakeCmd(cmdDef actorCmdDef) *cobra.Command { return err } - if !nonInteractive { + if !flags.NonInteractive { pwd = readPassphrase(pwd) } pk, err := kb.GetPrivKey(fromAddrHex, pwd) @@ -284,7 +286,7 @@ func newUnpauseCmd(cmdDef actorCmdDef) *cobra.Command { return err } - if !nonInteractive { + if !flags.NonInteractive { pwd = readPassphrase(pwd) } diff --git a/app/client/cli/cmd.go b/app/client/cli/cmd.go index faabb9e85..9e2c29f92 100644 --- a/app/client/cli/cmd.go +++ b/app/client/cli/cmd.go @@ -3,10 +3,12 @@ package cli import ( "context" - "github.com/pokt-network/pocket/runtime/configs" - "github.com/pokt-network/pocket/runtime/defaults" "github.com/spf13/cobra" "github.com/spf13/viper" + + "github.com/pokt-network/pocket/app/client/cli/flags" + "github.com/pokt-network/pocket/runtime/configs" + "github.com/pokt-network/pocket/runtime/defaults" ) const ( @@ -14,31 +16,24 @@ const ( ) var ( - remoteCLIURL string - dataDir string - configPath string - nonInteractive bool - verbose bool - cfg *configs.Config + cfg *configs.Config ) func init() { - rootCmd.PersistentFlags().StringVar(&remoteCLIURL, "remote_cli_url", defaults.DefaultRemoteCLIURL, "takes a remote endpoint in the form of :// (uses RPC Port)") - rootCmd.PersistentFlags().BoolVar(&nonInteractive, "non_interactive", false, "if true skips the interactive prompts wherever possible (useful for scripting & automation)") + rootCmd.PersistentFlags().StringVar(&flags.RemoteCLIURL, "remote_cli_url", defaults.DefaultRemoteCLIURL, "takes a remote endpoint in the form of :// (uses RPC Port)") + rootCmd.PersistentFlags().BoolVar(&flags.NonInteractive, "non_interactive", false, "if true skips the interactive prompts wherever possible (useful for scripting & automation)") // TECHDEBT: Why do we have a data dir when we have a config path if the data dir is only storing keys? - rootCmd.PersistentFlags().StringVar(&dataDir, "data_dir", defaults.DefaultRootDirectory, "Path to store pocket related data (keybase etc.)") - rootCmd.PersistentFlags().StringVar(&configPath, "config", "", "Path to config") + rootCmd.PersistentFlags().StringVar(&flags.DataDir, "data_dir", defaults.DefaultRootDirectory, "Path to store pocket related data (keybase etc.)") + rootCmd.PersistentFlags().StringVar(&flags.ConfigPath, "config", "", "Path to config") if err := viper.BindPFlag("root_directory", rootCmd.PersistentFlags().Lookup("data_dir")); err != nil { panic(err) } - rootCmd.PersistentFlags().BoolVar(&verbose, "verbose", false, "Show verbose output") + rootCmd.PersistentFlags().BoolVar(&flags.Verbose, "verbose", false, "Show verbose output") if err := viper.BindPFlag("verbose", rootCmd.PersistentFlags().Lookup("verbose")); err != nil { panic(err) } - - rootCmd.AddCommand(PeerCmd) } var rootCmd = &cobra.Command{ @@ -47,7 +42,7 @@ var rootCmd = &cobra.Command{ Long: "The CLI is meant to be an user but also a machine friendly way for interacting with Pocket Network.", PersistentPreRunE: func(cmd *cobra.Command, args []string) error { // by this time, the config path should be set - cfg = configs.ParseConfig(configPath) + cfg = configs.ParseConfig(flags.ConfigPath) return nil }, } diff --git a/app/client/cli/consensus.go b/app/client/cli/consensus.go index e909fcd2d..a74876949 100644 --- a/app/client/cli/consensus.go +++ b/app/client/cli/consensus.go @@ -2,9 +2,10 @@ package cli import ( "fmt" + "github.com/spf13/cobra" + "github.com/pokt-network/pocket/app/client/cli/flags" "github.com/pokt-network/pocket/rpc" - "github.com/spf13/cobra" ) func init() { @@ -96,7 +97,7 @@ func consensusCommands() []*cobra.Command { } func getConsensusState(cmd *cobra.Command) (*rpc.GetV1ConsensusStateResponse, error) { - client, err := rpc.NewClientWithResponses(remoteCLIURL) + client, err := rpc.NewClientWithResponses(flags.RemoteCLIURL) if err != nil { return nil, nil } diff --git a/app/client/cli/flags/flags.go b/app/client/cli/flags/flags.go new file mode 100644 index 000000000..8203bc9bb --- /dev/null +++ b/app/client/cli/flags/flags.go @@ -0,0 +1,13 @@ +package flags + +var ( + RemoteCLIURL string + + DataDir string + + ConfigPath string + + NonInteractive bool + + Verbose bool +) diff --git a/app/client/cli/gov.go b/app/client/cli/gov.go index c94737c32..a0fc30b88 100644 --- a/app/client/cli/gov.go +++ b/app/client/cli/gov.go @@ -3,10 +3,12 @@ package cli import ( "fmt" - "github.com/pokt-network/pocket/utility/types" "github.com/spf13/cobra" "google.golang.org/protobuf/types/known/anypb" "google.golang.org/protobuf/types/known/wrapperspb" + + "github.com/pokt-network/pocket/app/client/cli/flags" + "github.com/pokt-network/pocket/utility/types" ) func init() { @@ -52,7 +54,7 @@ func govCommands() []*cobra.Command { return err } - if !nonInteractive { + if !flags.NonInteractive { pwd = readPassphrase(pwd) } diff --git a/app/client/cli/keys.go b/app/client/cli/keys.go index c1500ac49..15409b675 100644 --- a/app/client/cli/keys.go +++ b/app/client/cli/keys.go @@ -7,11 +7,13 @@ import ( "strconv" "strings" + "github.com/spf13/cobra" + + "github.com/pokt-network/pocket/app/client/cli/flags" "github.com/pokt-network/pocket/shared/codec" coreTypes "github.com/pokt-network/pocket/shared/core/types" "github.com/pokt-network/pocket/shared/crypto" "github.com/pokt-network/pocket/shared/utils" - "github.com/spf13/cobra" ) var ( @@ -65,7 +67,7 @@ func keysCreateCommands() []*cobra.Command { return err } - if !nonInteractive { + if !flags.NonInteractive { pwd = readPassphrase(pwd) confirmPassphrase(pwd) } @@ -112,7 +114,7 @@ func keysUpdateCommands() []*cobra.Command { return err } - if !nonInteractive { + if !flags.NonInteractive { pwd = readPassphrase(pwd) newPwd = readPassphraseMessage(newPwd, "New passphrase: ") confirmPassphrase(newPwd) @@ -161,7 +163,7 @@ func keysDeleteCommands() []*cobra.Command { return err } - if !nonInteractive { + if !flags.NonInteractive { pwd = readPassphrase(pwd) } @@ -276,7 +278,7 @@ func keysExportCommands() []*cobra.Command { return err } - if !nonInteractive { + if !flags.NonInteractive { pwd = readPassphrase(pwd) } @@ -353,7 +355,7 @@ func keysImportCommands() []*cobra.Command { return err } - if !nonInteractive { + if !flags.NonInteractive { pwd = readPassphrase(pwd) } @@ -367,7 +369,7 @@ func keysImportCommands() []*cobra.Command { } case "raw": // it is unarmoured so we need to confirm the passphrase - if !nonInteractive { + if !flags.NonInteractive { confirmPassphrase(pwd) } kp, err = kb.ImportFromString(privateKeyString, pwd, hint) @@ -423,7 +425,7 @@ func keysSignMsgCommands() []*cobra.Command { return err } - if !nonInteractive { + if !flags.NonInteractive { pwd = readPassphrase(pwd) } @@ -520,7 +522,7 @@ func keysSignTxCommands() []*cobra.Command { return err } - if !nonInteractive { + if !flags.NonInteractive { pwd = readPassphrase(pwd) } @@ -678,7 +680,7 @@ func keysSlipCommands() []*cobra.Command { return err } - if !nonInteractive { + if !flags.NonInteractive { pwd = readPassphrase(pwd) } diff --git a/app/client/cli/query.go b/app/client/cli/query.go index fd2cf32d0..e93d91f88 100644 --- a/app/client/cli/query.go +++ b/app/client/cli/query.go @@ -6,8 +6,10 @@ import ( "net/http" "os" - "github.com/pokt-network/pocket/rpc" "github.com/spf13/cobra" + + "github.com/pokt-network/pocket/app/client/cli/flags" + "github.com/pokt-network/pocket/rpc" ) var ( @@ -68,7 +70,7 @@ func queryHeightCommands() []*cobra.Command { Args: cobra.ExactArgs(1), Aliases: []string{"account"}, RunE: func(cmd *cobra.Command, args []string) error { - client, err := rpc.NewClientWithResponses(remoteCLIURL) + client, err := rpc.NewClientWithResponses(flags.RemoteCLIURL) if err != nil { return err } @@ -103,7 +105,7 @@ func queryHeightCommands() []*cobra.Command { Args: cobra.ExactArgs(1), Aliases: []string{"app"}, RunE: func(cmd *cobra.Command, args []string) error { - client, err := rpc.NewClientWithResponses(remoteCLIURL) + client, err := rpc.NewClientWithResponses(flags.RemoteCLIURL) if err != nil { return err } @@ -138,7 +140,7 @@ func queryHeightCommands() []*cobra.Command { Args: cobra.ExactArgs(1), Aliases: []string{"balance"}, RunE: func(cmd *cobra.Command, args []string) error { - client, err := rpc.NewClientWithResponses(remoteCLIURL) + client, err := rpc.NewClientWithResponses(flags.RemoteCLIURL) if err != nil { return err } @@ -173,7 +175,7 @@ func queryHeightCommands() []*cobra.Command { Args: cobra.ExactArgs(0), Aliases: []string{"block"}, RunE: func(cmd *cobra.Command, args []string) error { - client, err := rpc.NewClientWithResponses(remoteCLIURL) + client, err := rpc.NewClientWithResponses(flags.RemoteCLIURL) if err != nil { return err } @@ -207,7 +209,7 @@ func queryHeightCommands() []*cobra.Command { Args: cobra.ExactArgs(1), Aliases: []string{"fisherman"}, RunE: func(cmd *cobra.Command, args []string) error { - client, err := rpc.NewClientWithResponses(remoteCLIURL) + client, err := rpc.NewClientWithResponses(flags.RemoteCLIURL) if err != nil { return err } @@ -242,7 +244,7 @@ func queryHeightCommands() []*cobra.Command { Aliases: []string{"param"}, Args: cobra.ExactArgs(1), RunE: func(cmd *cobra.Command, args []string) error { - client, err := rpc.NewClientWithResponses(remoteCLIURL) + client, err := rpc.NewClientWithResponses(flags.RemoteCLIURL) if err != nil { return err } @@ -277,7 +279,7 @@ func queryHeightCommands() []*cobra.Command { Args: cobra.ExactArgs(1), Aliases: []string{"servicer"}, RunE: func(cmd *cobra.Command, args []string) error { - client, err := rpc.NewClientWithResponses(remoteCLIURL) + client, err := rpc.NewClientWithResponses(flags.RemoteCLIURL) if err != nil { return err } @@ -312,7 +314,7 @@ func queryHeightCommands() []*cobra.Command { Args: cobra.ExactArgs(0), Aliases: []string{"supply"}, RunE: func(cmd *cobra.Command, args []string) error { - client, err := rpc.NewClientWithResponses(remoteCLIURL) + client, err := rpc.NewClientWithResponses(flags.RemoteCLIURL) if err != nil { return err } @@ -346,7 +348,7 @@ func queryHeightCommands() []*cobra.Command { Args: cobra.ExactArgs(0), Aliases: []string{"supportedchains"}, RunE: func(cmd *cobra.Command, args []string) error { - client, err := rpc.NewClientWithResponses(remoteCLIURL) + client, err := rpc.NewClientWithResponses(flags.RemoteCLIURL) if err != nil { return err } @@ -380,7 +382,7 @@ func queryHeightCommands() []*cobra.Command { Aliases: []string{"param"}, Args: cobra.ExactArgs(0), RunE: func(cmd *cobra.Command, args []string) error { - client, err := rpc.NewClientWithResponses(remoteCLIURL) + client, err := rpc.NewClientWithResponses(flags.RemoteCLIURL) if err != nil { return err } @@ -414,7 +416,7 @@ func queryHeightCommands() []*cobra.Command { Args: cobra.ExactArgs(1), Aliases: []string{"validator"}, RunE: func(cmd *cobra.Command, args []string) error { - client, err := rpc.NewClientWithResponses(remoteCLIURL) + client, err := rpc.NewClientWithResponses(flags.RemoteCLIURL) if err != nil { return err } @@ -456,7 +458,7 @@ func queryHeightPaginatedCommands() []*cobra.Command { Args: cobra.ExactArgs(0), Aliases: []string{"accounts"}, RunE: func(cmd *cobra.Command, args []string) error { - client, err := rpc.NewClientWithResponses(remoteCLIURL) + client, err := rpc.NewClientWithResponses(flags.RemoteCLIURL) if err != nil { return err } @@ -492,7 +494,7 @@ func queryHeightPaginatedCommands() []*cobra.Command { Args: cobra.ExactArgs(0), Aliases: []string{"apps"}, RunE: func(cmd *cobra.Command, args []string) error { - client, err := rpc.NewClientWithResponses(remoteCLIURL) + client, err := rpc.NewClientWithResponses(flags.RemoteCLIURL) if err != nil { return err } @@ -528,7 +530,7 @@ func queryHeightPaginatedCommands() []*cobra.Command { Args: cobra.ExactArgs(0), Aliases: []string{"fishermen"}, RunE: func(cmd *cobra.Command, args []string) error { - client, err := rpc.NewClientWithResponses(remoteCLIURL) + client, err := rpc.NewClientWithResponses(flags.RemoteCLIURL) if err != nil { return err } @@ -564,7 +566,7 @@ func queryHeightPaginatedCommands() []*cobra.Command { Args: cobra.ExactArgs(0), Aliases: []string{"servicers"}, RunE: func(cmd *cobra.Command, args []string) error { - client, err := rpc.NewClientWithResponses(remoteCLIURL) + client, err := rpc.NewClientWithResponses(flags.RemoteCLIURL) if err != nil { return err } @@ -600,7 +602,7 @@ func queryHeightPaginatedCommands() []*cobra.Command { Args: cobra.ExactArgs(0), Aliases: []string{"validators"}, RunE: func(cmd *cobra.Command, args []string) error { - client, err := rpc.NewClientWithResponses(remoteCLIURL) + client, err := rpc.NewClientWithResponses(flags.RemoteCLIURL) if err != nil { return err } @@ -643,7 +645,7 @@ func queryHeightPaginatedSortedCommands() []*cobra.Command { Args: cobra.ExactArgs(0), Aliases: []string{"blocktxs"}, RunE: func(cmd *cobra.Command, args []string) error { - client, err := rpc.NewClientWithResponses(remoteCLIURL) + client, err := rpc.NewClientWithResponses(flags.RemoteCLIURL) if err != nil { return err } @@ -687,7 +689,7 @@ func queryPaginatedSortedCommands() []*cobra.Command { Args: cobra.ExactArgs(1), Aliases: []string{"accounttxs"}, RunE: func(cmd *cobra.Command, args []string) error { - client, err := rpc.NewClientWithResponses(remoteCLIURL) + client, err := rpc.NewClientWithResponses(flags.RemoteCLIURL) if err != nil { return err } @@ -724,7 +726,7 @@ func queryPaginatedSortedCommands() []*cobra.Command { Args: cobra.ExactArgs(0), Aliases: []string{"unconfirmedtxs"}, RunE: func(cmd *cobra.Command, args []string) error { - client, err := rpc.NewClientWithResponses(remoteCLIURL) + client, err := rpc.NewClientWithResponses(flags.RemoteCLIURL) if err != nil { return err } @@ -767,7 +769,7 @@ func queryCommands() []*cobra.Command { Aliases: []string{"allparams"}, Args: cobra.ExactArgs(0), RunE: func(cmd *cobra.Command, args []string) error { - client, err := rpc.NewClientWithResponses(remoteCLIURL) + client, err := rpc.NewClientWithResponses(flags.RemoteCLIURL) if err != nil { return err } @@ -795,7 +797,7 @@ func queryCommands() []*cobra.Command { Aliases: []string{"height"}, Args: cobra.ExactArgs(0), RunE: func(cmd *cobra.Command, args []string) error { - client, err := rpc.NewClientWithResponses(remoteCLIURL) + client, err := rpc.NewClientWithResponses(flags.RemoteCLIURL) if err != nil { return err } @@ -823,7 +825,7 @@ func queryCommands() []*cobra.Command { Aliases: []string{"tx"}, Args: cobra.ExactArgs(1), RunE: func(cmd *cobra.Command, args []string) error { - client, err := rpc.NewClientWithResponses(remoteCLIURL) + client, err := rpc.NewClientWithResponses(flags.RemoteCLIURL) if err != nil { return err } @@ -857,7 +859,7 @@ func queryCommands() []*cobra.Command { Aliases: []string{"unconfirmedtx"}, Args: cobra.ExactArgs(1), RunE: func(cmd *cobra.Command, args []string) error { - client, err := rpc.NewClientWithResponses(remoteCLIURL) + client, err := rpc.NewClientWithResponses(flags.RemoteCLIURL) if err != nil { return err } diff --git a/app/client/cli/system.go b/app/client/cli/system.go index 2bcce8e24..63391db73 100644 --- a/app/client/cli/system.go +++ b/app/client/cli/system.go @@ -4,8 +4,10 @@ import ( "fmt" "net/http" - "github.com/pokt-network/pocket/rpc" "github.com/spf13/cobra" + + "github.com/pokt-network/pocket/app/client/cli/flags" + "github.com/pokt-network/pocket/rpc" ) func init() { @@ -34,7 +36,7 @@ func systemCommands() []*cobra.Command { Long: "Performs a simple liveness check on the node RPC endpoint", Aliases: []string{"health"}, RunE: func(cmd *cobra.Command, args []string) error { - client, err := rpc.NewClientWithResponses(remoteCLIURL) + client, err := rpc.NewClientWithResponses(flags.RemoteCLIURL) if err != nil { return nil } @@ -44,7 +46,7 @@ func systemCommands() []*cobra.Command { } statusCode := response.StatusCode() if statusCode == http.StatusOK { - fmt.Printf("✅ RPC reporting healthy status for node @ %s\n\n%s", boldText(remoteCLIURL), response.Body) + fmt.Printf("✅ RPC reporting healthy status for node @ %s\n\n%s", boldText(flags.RemoteCLIURL), response.Body) return nil } @@ -57,7 +59,7 @@ func systemCommands() []*cobra.Command { Long: "Queries the node RPC to obtain the version of the software currently running", Aliases: []string{"version"}, RunE: func(cmd *cobra.Command, args []string) error { - client, err := rpc.NewClientWithResponses(remoteCLIURL) + client, err := rpc.NewClientWithResponses(flags.RemoteCLIURL) if err != nil { return err } @@ -67,7 +69,7 @@ func systemCommands() []*cobra.Command { } statusCode := response.StatusCode() if statusCode == http.StatusOK { - fmt.Printf("Node @ %s reports that it's running version: \n%s\n", boldText(remoteCLIURL), boldText(response.Body)) + fmt.Printf("Node @ %s reports that it's running version: \n%s\n", boldText(flags.RemoteCLIURL), boldText(response.Body)) return nil } diff --git a/app/client/cli/utils.go b/app/client/cli/utils.go index ad841eeb6..2e3e0263e 100644 --- a/app/client/cli/utils.go +++ b/app/client/cli/utils.go @@ -11,6 +11,11 @@ import ( "os" "strings" + "github.com/spf13/cobra" + "github.com/spf13/viper" + "golang.org/x/term" + + "github.com/pokt-network/pocket/app/client/cli/flags" "github.com/pokt-network/pocket/app/client/keybase" "github.com/pokt-network/pocket/logger" "github.com/pokt-network/pocket/rpc" @@ -20,9 +25,6 @@ import ( "github.com/pokt-network/pocket/shared/crypto" "github.com/pokt-network/pocket/shared/utils" typesUtil "github.com/pokt-network/pocket/utility/types" - "github.com/spf13/cobra" - "github.com/spf13/viper" - "golang.org/x/term" ) var ( @@ -129,7 +131,7 @@ func prepareTxBytes(msg typesUtil.Message, pk crypto.PrivateKey) ([]byte, error) // postRawTx posts a signed transaction func postRawTx(ctx context.Context, pk crypto.PrivateKey, j []byte) (*rpc.PostV1ClientBroadcastTxSyncResponse, error) { - client, err := rpc.NewClientWithResponses(remoteCLIURL) + client, err := rpc.NewClientWithResponses(flags.RemoteCLIURL) if err != nil { return nil, err } @@ -313,12 +315,12 @@ func keybaseForCLI() (keybase.Keybase, error) { } func unableToConnectToRpc(err error) error { - fmt.Printf("❌ Unable to connect to the RPC @ %s\n\nError: %s", boldText(remoteCLIURL), err) + fmt.Printf("❌ Unable to connect to the RPC @ %s\n\nError: %s", boldText(flags.RemoteCLIURL), err) return nil } func rpcResponseCodeUnhealthy(statusCode int, response []byte) error { - fmt.Printf("❌ RPC reporting unhealthy status HTTP %d @ %s\n\n%s", statusCode, boldText(remoteCLIURL), response) + fmt.Printf("❌ RPC reporting unhealthy status HTTP %d @ %s\n\n%s", statusCode, boldText(flags.RemoteCLIURL), response) return nil }