From cb1ca511cb6d26e10bbd7a4d3150c0846885eb1a Mon Sep 17 00:00:00 2001 From: Alex Vanin Date: Mon, 12 Oct 2020 16:59:33 +0300 Subject: [PATCH] [#77] Add endpoint global argument in CLI Signed-off-by: Alex Vanin --- cmd/neofs-cli/modules/root.go | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/cmd/neofs-cli/modules/root.go b/cmd/neofs-cli/modules/root.go index e75202ae..0dab0ab6 100644 --- a/cmd/neofs-cli/modules/root.go +++ b/cmd/neofs-cli/modules/root.go @@ -8,6 +8,7 @@ import ( "github.com/mitchellh/go-homedir" crypto "github.com/nspcc-dev/neofs-crypto" + "github.com/nspcc-dev/neofs-node/pkg/network" "github.com/spf13/cobra" "github.com/spf13/viper" ) @@ -16,6 +17,7 @@ import ( var ( cfgFile string privateKey string + endpoint string ) // rootCmd represents the base command when called without any subcommands @@ -31,7 +33,8 @@ and much more!`, } var ( - errInvalidKey = errors.New("provided key is incorrect") + errInvalidKey = errors.New("provided key is incorrect") + errInvalidEndpoint = errors.New("provided RPC endpoint is incorrect") ) // Execute adds all child commands to the root command and sets flags appropriately. @@ -52,6 +55,7 @@ func init() { rootCmd.PersistentFlags().StringVarP(&cfgFile, "config", "c", "", "config file (default is $HOME/.config/neofs-cli/config.yaml)") rootCmd.PersistentFlags().StringVarP(&privateKey, "key", "k", "", "private key in hex, WIF or filepath") + rootCmd.PersistentFlags().StringVarP(&endpoint, "rpc-endpoint", "r", "", "remote node address (as 'multiaddr' or ':')") // Cobra also supports local flags, which will only run // when this action is called directly. @@ -93,3 +97,14 @@ func getKey() (*ecdsa.PrivateKey, error) { return key, nil } + +// getEndpointAddress returns network address structure that stores multiaddr +// inside, parsed from global arguments. +func getEndpointAddress() (*network.Address, error) { + addr, err := network.AddressFromString(endpoint) + if err != nil { + return nil, errInvalidEndpoint + } + + return addr, nil +}