From 8fd4073e82ead27f9ada68e6c3cd250a06132288 Mon Sep 17 00:00:00 2001 From: Robert Lin Date: Thu, 2 Apr 2020 22:13:58 -0700 Subject: [PATCH] cmd(project): fix set command (#669) --- cfg/util.go | 14 +++++++++----- cmd/project/project.go | 5 +++-- 2 files changed, 12 insertions(+), 7 deletions(-) diff --git a/cfg/util.go b/cfg/util.go index dd23ea71..229c2fb2 100644 --- a/cfg/util.go +++ b/cfg/util.go @@ -33,18 +33,22 @@ func SetProperty(name string, value string, obj interface{}) error { return SetProperty(strings.Join(parts[1:], "."), value, fieldPtr.Interface()) } if fieldVal.IsValid() && fieldVal.CanSet() { - if fieldVal.Kind() == reflect.String { - // attempt to set string + switch fieldVal.Kind() { + // set string + case reflect.String: fieldVal.SetString(value) return nil - } - if fieldVal.Kind() == reflect.Bool { - // attempt to set boolean + // attempt to set boolean + case reflect.Bool: if _, err := strconv.ParseBool(value); err == nil { fieldVal.SetBool(true) return nil } + break + + default: + break } } } diff --git a/cmd/project/project.go b/cmd/project/project.go index dd3a1e4b..a1171841 100644 --- a/cmd/project/project.go +++ b/cmd/project/project.go @@ -4,6 +4,7 @@ import ( "os" "github.com/spf13/cobra" + "github.com/ubclaunchpad/inertia/cfg" "github.com/ubclaunchpad/inertia/cmd/core" "github.com/ubclaunchpad/inertia/cmd/core/utils/input" @@ -55,13 +56,13 @@ func (root *ProjectCmd) attachSetCmd() { Long: `Updates a property of your Inertia project configuration and save it to inertia.toml.`, Args: cobra.ExactArgs(2), Run: func(cmd *cobra.Command, args []string) { - if err := cfg.SetProperty(args[0], args[1], root.config); err != nil { + if err := cfg.SetProperty(args[0], args[1], root.config); err == nil { if err := local.Write(root.projectConfigPath, root.config); err != nil { out.Fatal(err) } out.Println("configuration setting '" + args[0] + "' has been updated") } else { - out.Println("configuration setting '" + args[0] + "' not found") + out.Println("configuration setting '" + args[0] + "' could not be updated: " + err.Error()) } }, }