func diff(aFilePath, bFilePath string) { aFile, err := ioutil.ReadFile(aFilePath) if err != nil { log.Fatalln("error reading a:", err) } aYAML, err := yaml.Parse(aFile) if err != nil { log.Fatalln("error parsing a:", err) } bFile, err := ioutil.ReadFile(bFilePath) if err != nil { log.Fatalln("error reading b:", err) } bYAML, err := yaml.Parse(bFile) if err != nil { log.Fatalln("error parsing b:", err) } diffs := compare.Compare(aYAML, bYAML) if len(diffs) == 0 { fmt.Println("no differences!") return } for _, diff := range diffs { fmt.Println("Difference in", strings.Join(diff.Path, ".")) if diff.A != nil { ayaml, err := goyaml.Marshal(diff.A) if err != nil { panic(err) } fmt.Printf(" %s has:\n \x1b[31m%s\x1b[0m\n", aFilePath, strings.Replace(string(ayaml), "\n", "\n ", -1)) } if diff.B != nil { byaml, err := goyaml.Marshal(diff.B) if err != nil { panic(err) } fmt.Printf(" %s has:\n \x1b[32m%s\x1b[0m\n", bFilePath, strings.Replace(string(byaml), "\n", "\n ", -1)) } } }
func parseYAML(source string) yaml.Node { parsed, err := yaml.Parse([]byte(source)) if err != nil { panic(err) } return parsed }
func merge(templateFilePath string, stubFilePaths []string) { templateFile, err := ioutil.ReadFile(templateFilePath) if err != nil { log.Fatalln("error reading template:", err) } templateYAML, err := yaml.Parse(templateFile) if err != nil { log.Fatalln("error parsing template:", err) } stubs := []yaml.Node{} for _, stubFilePath := range stubFilePaths { stubFile, err := ioutil.ReadFile(stubFilePath) if err != nil { log.Fatalln("error reading stub:", err) } stubYAML, err := yaml.Parse(stubFile) if err != nil { log.Fatalln("error parsing stub:", err) } stubs = append(stubs, stubYAML) } flowed, err := flow.Cascade(templateYAML, stubs...) if err != nil { log.Fatalln("error generating manifest:", err) } yaml, err := goyaml.Marshal(flowed) if err != nil { log.Fatalln("error marshalling manifest:", err) } fmt.Println(string(yaml)) }