"github.com/gophersiesta/gophersiesta/Godeps/_workspace/src/github.com/spf13/cobra" "github.com/gophersiesta/gophersiesta/common" ) // setCmd represents the set command var setCmd = &cobra.Command{ Use: "set", Short: "Set all the values to configuration manager. Needed {appname + label}", Long: "Set all the values to be setup. From appname + label", Run: func(cmd *cobra.Command, args []string) { api := common.NewAPI(source) data := map[string]interface{}{} json.Unmarshal([]byte(properties), &data) var values common.Values if len(data) > 0 { //it's a JSON for k, v := range data { values.Values = append(values.Values, &common.Value{k, fmt.Sprint(v)}) } } else if strings.Contains(properties, "=") { pairs := strings.Split(properties, ",") for _, v := range pairs { vv := strings.Split(v, "=") values.Values = append(values.Values, &common.Value{vv[0], strings.Join(vv[1:], "=")}) } } else { fmt.Println("ERROR") os.Exit(0) }
fmt.Println(values.String()) fmt.Println(pls.String()) fmt.Printf("\nThere are %v common. Listing: \n", len(pls.Placeholders)) for _, p := range pls.Placeholders { fmt.Printf("%s [$%s] (current value: \"%s\")\n", p.PropertyName, p.PlaceHolder, p.PropertyValue) } fmt.Printf("\n\n") fmt.Printf("Type value for each placeholder and press ENTER, or ENTER to skip or left as before: \n") fmt.Printf(" explanation: property.path [$PLACE_HOLDER] --> curentvalue \n") mValues, err := values.ToMapString() sValues := common.Values{} for _, p := range pls.Placeholders { pv := p.PropertyValue if _, ok := mValues[p.PropertyName]; ok { pv = mValues[p.PropertyName] } value := setPropertyHolderValue(p, pv) sValue := common.Value{p.PropertyName, value} sValues.Values = append(sValues.Values, &sValue) } api.SetValues(appName, strings.Split(label, ","), sValues) },