[#169] Add --ttl argument in CLI

Signed-off-by: Alex Vanin <alexey@nspcc.ru>
This commit is contained in:
Alex Vanin 2020-11-16 11:25:42 +03:00 committed by Alex Vanin
parent ea41dec23f
commit e47c866d6a
5 changed files with 39 additions and 15 deletions

View file

@ -21,6 +21,8 @@ const (
envPrefix = "NEOFS_CLI"
generateKeyConst = "new"
ttlDefaultValue = 2
)
// Global scope flags.
@ -73,6 +75,9 @@ func init() {
rootCmd.PersistentFlags().StringP("rpc-endpoint", "r", "", "remote node address (as 'multiaddr' or '<host>:<port>')")
_ = viper.BindPFlag("rpc", rootCmd.PersistentFlags().Lookup("rpc-endpoint"))
rootCmd.PersistentFlags().Uint32("ttl", ttlDefaultValue, "TTL value in request meta header")
_ = viper.BindPFlag("ttl", rootCmd.PersistentFlags().Lookup("ttl"))
rootCmd.PersistentFlags().BoolVarP(&verbose, "verbose", "v", false, "verbose output")
// Cobra also supports local flags, which will only run
@ -165,6 +170,13 @@ func getSDKClient() (*client.Client, error) {
return client.New(key, client.WithAddress(ipAddr))
}
func getTTL() uint32 {
ttl := viper.GetUint32("ttl")
printVerbose("TTL: %d", ttl)
return ttl
}
// ownerFromString converts string with NEO3 wallet address to neofs owner ID.
func ownerFromString(s string) (*owner.ID, error) {
result := owner.NewID()