// Main is the main function for inspect tool. Helps visualize stitches. func Main(opts []string) int { if arglen := len(opts); arglen < 2 { fmt.Println("not enough arguments: ", arglen) Usage() return 1 } configPath := opts[0] spec, err := stitch.FromFile(configPath, stitch.DefaultImportGetter) if err != nil { fmt.Fprintln(os.Stderr, err) return 1 } graph, err := stitch.InitializeGraph(spec) if err != nil { fmt.Fprintln(os.Stderr, err) return 1 } switch opts[1] { case "pdf", "ascii", "graphviz": viz(configPath, spec, graph, opts[1]) default: Usage() return 1 } return 0 }
func TestViz(t *testing.T) { expect := `strict digraph { subgraph cluster_0 { 1; 2; 3; public; } 1 -> 2 2 -> 3 }` stc := `(label "a" (docker "ubuntu")) (label "b" (docker "ubuntu")) (label "c" (docker "ubuntu")) (connect 22 "a" "b") (connect 22 "b" "c")` spec, err := initSpec(stc) if err != nil { panic(err) } graph, err := stitch.InitializeGraph(spec) if err != nil { panic(err) } gv := makeGraphviz(graph) gv = strings.Replace(gv, "\n", "", -1) gv = strings.Replace(gv, " ", "", -1) expect = strings.Replace(expect, "\n", "", -1) expect = strings.Replace(expect, " ", "", -1) if gv != expect { t.Error(gv + "\n" + expect) } }
func TestViz(t *testing.T) { t.Parallel() spec, err := initSpec(testStitch) if err != nil { panic(err) } graph, err := stitch.InitializeGraph(spec) if err != nil { panic(err) } gv := makeGraphviz(graph) if !isGraphEqual(gv, expGraph) { t.Error(gv + "\n" + expGraph) } }
// Main is the main function for inspect tool. Helps visualize stitches. func Main(opts []string) { if arglen := len(opts); arglen < 3 { fmt.Println("not enough arguments: ", arglen-1) usage() } configPath := opts[1] f, err := os.Open(configPath) if err != nil { fmt.Println(err) os.Exit(1) } defer f.Close() sc := scanner.Scanner{ Position: scanner.Position{ Filename: configPath, }, } pathStr, _ := os.LookupEnv(quiltPath) spec, err := stitch.New(*sc.Init(bufio.NewReader(f)), pathStr, false) if err != nil { fmt.Fprintln(os.Stderr, err) os.Exit(1) } graph, err := stitch.InitializeGraph(spec) if err != nil { fmt.Fprintln(os.Stderr, err) os.Exit(1) } switch opts[2] { case "pdf": fallthrough case "ascii": viz(configPath, spec, graph, opts[2]) default: usage() } }