in internal/cmd/set.go [76:139]
func Set(environment string, subcomponent string, pathValuePairStrings []string, noNewConfigKeys bool, inputFile string) (err error) {
subcomponentPath := []string{}
if len(subcomponent) > 0 {
subcomponentPath = strings.Split(subcomponent, ".")
}
componentConfig := core.NewComponentConfig(".")
// Load input file if provided
inputFileValuePairList := []string{}
if inputFile != "" {
bytes, err := ioutil.ReadFile(inputFile)
if err != nil {
return err
}
yamlContent := map[string]interface{}{}
err = yaml.Unmarshal(bytes, &yamlContent)
if err != nil {
return err
}
// Flatten the map
flattenedInputFileContentMap := util.FlattenMap(yamlContent, ".", []string{})
// Append all key/value in map to the flattened list
for k, v := range flattenedInputFileContentMap {
// Join to PathValue strings with "="
valueAsString := fmt.Sprintf("%v", v)
joined := strings.Join([]string{k, valueAsString}, "=")
inputFileValuePairList = append(inputFileValuePairList, joined)
}
}
pathValuePairs, err := SplitPathValuePairs(append(inputFileValuePairList, pathValuePairStrings...))
if err != nil {
return err
}
if err := componentConfig.Load(environment); err != nil {
return err
}
newConfigError := errors.New("new configuration was specified and the --no-new-config-keys switch is on")
for _, pathValue := range pathValuePairs {
if noNewConfigKeys {
if !componentConfig.HasSubcomponentConfig(subcomponentPath) {
return newConfigError
}
sc := componentConfig.GetSubcomponentConfig(subcomponentPath)
if !sc.HasComponentConfig(pathValue.Path) {
return newConfigError
}
}
componentConfig.SetConfig(subcomponentPath, pathValue.Path, pathValue.Value)
}
return componentConfig.Write(environment)
}