forked from TrueCloudLab/frostfs-node
[#77] Add endpoint global argument in CLI
Signed-off-by: Alex Vanin <alexey@nspcc.ru>
This commit is contained in:
parent
fc700cbbdc
commit
cb1ca511cb
1 changed files with 16 additions and 1 deletions
|
@ -8,6 +8,7 @@ import (
|
||||||
|
|
||||||
"github.com/mitchellh/go-homedir"
|
"github.com/mitchellh/go-homedir"
|
||||||
crypto "github.com/nspcc-dev/neofs-crypto"
|
crypto "github.com/nspcc-dev/neofs-crypto"
|
||||||
|
"github.com/nspcc-dev/neofs-node/pkg/network"
|
||||||
"github.com/spf13/cobra"
|
"github.com/spf13/cobra"
|
||||||
"github.com/spf13/viper"
|
"github.com/spf13/viper"
|
||||||
)
|
)
|
||||||
|
@ -16,6 +17,7 @@ import (
|
||||||
var (
|
var (
|
||||||
cfgFile string
|
cfgFile string
|
||||||
privateKey string
|
privateKey string
|
||||||
|
endpoint string
|
||||||
)
|
)
|
||||||
|
|
||||||
// rootCmd represents the base command when called without any subcommands
|
// rootCmd represents the base command when called without any subcommands
|
||||||
|
@ -31,7 +33,8 @@ and much more!`,
|
||||||
}
|
}
|
||||||
|
|
||||||
var (
|
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.
|
// 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(&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(&privateKey, "key", "k", "", "private key in hex, WIF or filepath")
|
||||||
|
rootCmd.PersistentFlags().StringVarP(&endpoint, "rpc-endpoint", "r", "", "remote node address (as 'multiaddr' or '<host>:<port>')")
|
||||||
|
|
||||||
// Cobra also supports local flags, which will only run
|
// Cobra also supports local flags, which will only run
|
||||||
// when this action is called directly.
|
// when this action is called directly.
|
||||||
|
@ -93,3 +97,14 @@ func getKey() (*ecdsa.PrivateKey, error) {
|
||||||
|
|
||||||
return key, nil
|
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
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in a new issue