提交 371bf931 作者: Kejie Zhang

uodate json option name

License: MIT
Signed-off-by: 's avatarKejie Zhang <601172892@qq.com>
上级 dee54b36
...@@ -27,7 +27,7 @@ type ConfigField struct { ...@@ -27,7 +27,7 @@ type ConfigField struct {
const ( const (
configBoolOptionName = "bool" configBoolOptionName = "bool"
configJsonOptionName = "json" configJSONOptionName = "json"
) )
var ConfigCmd = &cmds.Command{ var ConfigCmd = &cmds.Command{
...@@ -60,7 +60,7 @@ Set the value of the 'Datastore.Path' key: ...@@ -60,7 +60,7 @@ Set the value of the 'Datastore.Path' key:
}, },
Options: []cmdkit.Option{ Options: []cmdkit.Option{
cmdkit.BoolOption(configBoolOptionName, "Set a boolean value."), cmdkit.BoolOption(configBoolOptionName, "Set a boolean value."),
cmdkit.BoolOption(configJsonOptionName, "Parse stringified JSON."), cmdkit.BoolOption(configJSONOptionName, "Parse stringified JSON."),
}, },
Run: func(req cmds.Request, res cmds.Response) { Run: func(req cmds.Request, res cmds.Response) {
args := req.Arguments() args := req.Arguments()
...@@ -92,7 +92,7 @@ Set the value of the 'Datastore.Path' key: ...@@ -92,7 +92,7 @@ Set the value of the 'Datastore.Path' key:
if len(args) == 2 { if len(args) == 2 {
value := args[1] value := args[1]
if parseJson, _, _ := req.Option(configJsonOptionName).Bool(); parseJson { if parseJSON, _, _ := req.Option(configJSONOptionName).Bool(); parseJSON {
var jsonVal interface{} var jsonVal interface{}
if err := json.Unmarshal([]byte(value), &jsonVal); err != nil { if err := json.Unmarshal([]byte(value), &jsonVal); err != nil {
err = fmt.Errorf("failed to unmarshal json. %s", err) err = fmt.Errorf("failed to unmarshal json. %s", err)
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论