예제 #1
0
// this helps whenever a 'task' gets refactored to become an 'alias' (e.g. 'pkg-build' task renamed to 'deb', and 'pkg-build' became a task alias)
// note that the task settings take precedence over the alias' settings.
func (s *Settings) MergeAliasedTaskSettings(aliases map[string][]string) {
	//for each per-task setting name/value pair:
	for taskSettingTaskName, taskSettingValue := range s.TaskSettings {
		//loop through aliases, getting alias,tasks:
		for staticSettingAlias, aliasedTasks := range aliases {
			// if the specified TaskSetting == this alias:
			if staticSettingAlias == taskSettingTaskName {
				//merge into results ...
				for _, aliasedTask := range aliasedTasks {
					aliasedTaskValue, exists := s.TaskSettings[aliasedTask]
					//if settings already exists for the actual task - merge
					if exists {
						if s.IsVerbose() {
							log.Printf("Task settings specified for %s. Merging %v with %v", aliasedTask, aliasedTaskValue, taskSettingValue)
						}
						// merge
						s.TaskSettings[aliasedTask] = typeutils.MergeMaps(aliasedTaskValue, taskSettingValue)
					} else {
						if s.IsVerbose() {
							log.Printf("alias didnt exist. Setting %s to %v", aliasedTask, taskSettingValue)
						}
						//add ...
						s.TaskSettings[aliasedTask] = taskSettingValue
					}
				}
			}
		}
	}
}
예제 #2
0
파일: json.go 프로젝트: anlaneg/socketplane
func LoadJsonConfigs(dir string, configs []string, verbose bool) (Settings, error) {
	//most-important first
	mergedSettingsMap := map[string]interface{}{}
	for _, jsonFile := range configs {
		settingsMap, err := loadJsonFileAsMap(jsonFile, verbose)
		if err != nil {
			if os.IsNotExist(err) {
				//continue onto next file
			} else {
				//parse error. Stop right there.
				return Settings{}, err
			}
		} else {
			mergedSettingsMap = typeutils.MergeMaps(mergedSettingsMap, settingsMap)
		}
	}
	return loadSettingsSection(mergedSettingsMap)
}