Skip to content

Commit

Permalink
cmd(project): fix set command (#669)
Browse files Browse the repository at this point in the history
  • Loading branch information
bobheadxi authored Apr 3, 2020
1 parent 67b2f5a commit 8fd4073
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 7 deletions.
14 changes: 9 additions & 5 deletions cfg/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
}
}
Expand Down
5 changes: 3 additions & 2 deletions cmd/project/project.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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())
}
},
}
Expand Down

0 comments on commit 8fd4073

Please sign in to comment.