github.com/iotexproject/iotex-core@v1.14.1-rc1/ioctl/newcmd/config/config_get.go (about) 1 // Copyright (c) 2022 IoTeX Foundation 2 // This source code is provided 'as is' and no warranties are given as to title or non-infringement, merchantability 3 // or fitness for purpose and, to the extent permitted by law, all liability for your use of the code is disclaimed. 4 // This source code is governed by Apache License 2.0 that can be found in the LICENSE file. 5 6 package config 7 8 import ( 9 "fmt" 10 "strings" 11 12 "github.com/pkg/errors" 13 "github.com/spf13/cobra" 14 15 "github.com/iotexproject/iotex-core/ioctl" 16 "github.com/iotexproject/iotex-core/ioctl/config" 17 ) 18 19 var ( 20 _configGetUse = map[config.Language]string{ 21 config.English: "get VARIABLE", 22 config.Chinese: "get 变量", 23 } 24 _configGetUseCmdShorts = map[config.Language]string{ 25 config.English: "Get config fields from ioctl", 26 config.Chinese: "从 ioctl 获取配置字段", 27 } 28 _configGetUseCmdLong = map[config.Language]string{ 29 config.English: "Get config fields from ioctl\nValid Variables: [" + strings.Join(_validGetArgs, ", ") + "]", 30 config.Chinese: "从 ioctl 获取配置字段\n有效变量: [" + strings.Join(_validGetArgs, ", ") + "]", 31 } 32 ) 33 34 // NewConfigGetCmd is a command to get config fields from iotcl. 35 func NewConfigGetCmd(client ioctl.Client) *cobra.Command { 36 use, _ := client.SelectTranslation(_configGetUse) 37 short, _ := client.SelectTranslation(_configGetUseCmdShorts) 38 long, _ := client.SelectTranslation(_configGetUseCmdLong) 39 40 return &cobra.Command{ 41 Use: use, 42 Short: short, 43 Long: long, 44 ValidArgs: _validGetArgs, 45 Args: cobra.ExactValidArgs(1), 46 RunE: func(cmd *cobra.Command, args []string) error { 47 cmd.SilenceUsage = true 48 result, err := newInfo(client.Config(), client.ConfigFilePath()).get(args[0]) 49 if err != nil { 50 return errors.Wrap(err, fmt.Sprintf("issue fetching config value %s", args[0])) 51 } 52 cmd.Println(result) 53 return nil 54 }, 55 } 56 }