// parseSteps creates the struct representation of the steps section in the yaml file.
// It determines which kind of step is defined and create the correct implementation for it.
parseSteps creates the struct representation of the steps section in the yaml file.
It determines which kind of step is defined and create the correct implementation for it.
// parseSteps creates the struct representation of the steps section in the yaml file . // It determines which kind of step is defined and create the correct implementation for it .
func parseSteps(stepsYaml []interface{}, variables map[string]string) (steps []model.Step, err error) {
	for _, stepYaml := range stepsYaml {
		stepYaml := stepYaml.(map[string]interface{})
		if kind, ok := stepYaml["Kind"].(string); ok {
			if _, ok := stepYaml["Preferences"]; ok {
				stepYaml["Preferences"], err = expandPreferences(stepYaml["Preferences"].(map[string]interface{}), variables)
				if err != nil {
					return steps, err
				}
			}
			switch kind {
			case step.KindDownload:
				step := stepDefinition.Download{}
				err = step.FromConfig(stepYaml)
				if err != nil {
					return steps, err
				}
				steps = append(steps, &step)
			case step.KindUnzip:
				step := stepDefinition.Unzip{}
				err = step.FromConfig(stepYaml)
				if err != nil {
					return steps, err
				}
				steps = append(steps, &step)
			case step.KindDelete:
				step := stepDefinition.Delete{}
				err = step.FromConfig(stepYaml)
				if err != nil {
					return steps, err
				}
				steps = append(steps, &step)
			case step.KindCreateFolder:
				step := stepDefinition.CreateFolder{}
				err = step.FromConfig(stepYaml)
				if err != nil {
					return steps, err
				}
				steps = append(steps, &step)
			case step.KindCommand:
				step := stepDefinition.Command{}
				err = step.FromConfig(stepYaml)
				if err != nil {
					return steps, err
				}
				steps = append(steps, &step)
			case step.KindService:
				step := stepDefinition.Service{}
				err = step.FromConfig(stepYaml)
				if err != nil {
					return steps, err
				}
				steps = append(steps, &step)
			case step.KindChecklist:
				step := stepDefinition.Checklist{}
				err = step.FromConfig(stepYaml)
				if err != nil {
					return steps, err
				}
				steps = append(steps, &step)
			case step.KindWatch:
				step := stepDefinition.Watch{}
				err = step.FromConfig(stepYaml)
				if err != nil {
					return steps, err
				}
				steps = append(steps, &step)
			case step.KindCopy:
				step := stepDefinition.Copy{}
				err = step.FromConfig(stepYaml)
				if err != nil {
					return steps, err
				}
				steps = append(steps, &step)
			default:
				return steps, fmt.Errorf("Unknown step type \"%s\" used", kind)
			}
		}
	}
	return steps, nil
}
func parseSteps ( stepsYaml [ ] interface { } , variables map [ string ] string ) ( steps [ ] model . Step , err error ) { for _ , stepYaml := range stepsYaml { stepYaml := stepYaml . ( map [ string ] interface { } ) if kind , ok := stepYaml [ " " ] . ( string ) ; ok { if _ , ok := stepYaml [ " " ] ; ok { stepYaml [ " " ] , err = expandPreferences ( stepYaml [ " " ] . ( map [ string ] interface { } ) , variables ) if err != nil { return steps , err } } switch kind { case step . KindDownload : step := stepDefinition . Download { } err = step . FromConfig ( stepYaml ) if err != nil { return steps , err } steps = append ( steps , & step ) case step . KindUnzip : step := stepDefinition . Unzip { } err = step . FromConfig ( stepYaml ) if err != nil { return steps , err } steps = append ( steps , & step ) case step . KindDelete : step := stepDefinition . Delete { } err = step . FromConfig ( stepYaml ) if err != nil { return steps , err } steps = append ( steps , & step ) case step . KindCreateFolder : step := stepDefinition . CreateFolder { } err = step . FromConfig ( stepYaml ) if err != nil { return steps , err } steps = append ( steps , & step ) case step . KindCommand : step := stepDefinition . Command { } err = step . FromConfig ( stepYaml ) if err != nil { return steps , err } steps = append ( steps , & step ) case step . KindService : step := stepDefinition . Service { } err = step . FromConfig ( stepYaml ) if err != nil { return steps , err } steps = append ( steps , & step ) case step . KindChecklist : step := stepDefinition . Checklist { } err = step . FromConfig ( stepYaml ) if err != nil { return steps , err } steps = append ( steps , & step ) case step . KindWatch : step := stepDefinition . Watch { } err = step . FromConfig ( stepYaml ) if err != nil { return steps , err } steps = append ( steps , & step ) case step . KindCopy : step := stepDefinition . Copy { } err = step . FromConfig ( stepYaml ) if err != nil { return steps , err } steps = append ( steps , & step ) default : return steps , fmt . Errorf ( " \" \" " , kind ) } } } return steps , nil }
parseSteps creates the struct representation of the steps section in the yaml file.
parseSteps creates the struct representation of the steps section in the yaml file .
//Iterate tasks // Create the correct instance based on the type of step // Check the preferences if any variables where used that need to be expanded // Create the correct type of step