func runDotDumper(cmd *cobra.Command, args []string) { g := represent.NewGraph() raw, err := schema.Master() if err != nil { panic(fmt.Sprint("Failed to open master schema file, test must abort. message:", err.Error())) } schemaMaster, err := gjs.NewSchema(gjs.NewStringLoader(string(raw))) if err != nil { panic("bad schema...?") } if len(args) < 1 { log.Fatalf("Must provide at least one directory argument to dotdumper.") } var k uint64 = 0 for _, dir := range args { fl, err := ioutil.ReadDir(dir) if err != nil { erro.Printf("Failed to read directory '%v' with error %v\n", dir, err) } for _, f := range fl { if match, _ := regexp.MatchString("\\.json$", f.Name()); match && !f.IsDir() { src, err := ioutil.ReadFile(dir + "/" + f.Name()) if err != nil { erro.Printf("Failed to read fixture file %v/%v\n", dir, f.Name()) continue } result, err := schemaMaster.Validate(gjs.NewStringLoader(string(src))) if err != nil { erro.Printf("Validation process terminated with errors for %v/%v. Error: \n%v\n", dir, f.Name(), err.Error()) continue } if !result.Valid() { for _, desc := range result.Errors() { erro.Printf("\t%s\n", desc) } } else { k++ m := ingest.Message{} json.Unmarshal(src, &m) g = g.Merge(k, m.UnificationForm()) fmt.Printf("Merged message %v/%v into graph\n", dir, f.Name()) } } } } pathflag := cmd.Flags().Lookup("output") if pathflag.Changed { ioutil.WriteFile(pathflag.Value.String(), GenerateDot(g), 0644) } else { fmt.Println(string(GenerateDot(g))) } }