github.com/aca02djr/gb@v0.4.1/cmd/gb/dot.go (about)

     1  package main
     2  
     3  import (
     4  	"fmt"
     5  	"io"
     6  	"strings"
     7  
     8  	"github.com/constabulary/gb"
     9  )
    10  
    11  func printActions(w io.Writer, a *gb.Action) {
    12  	fmt.Fprintf(w, "digraph %q {\n", a.Name)
    13  	seen := make(map[*gb.Action]bool)
    14  	print0(w, seen, a)
    15  	fmt.Fprintf(w, "}\n")
    16  }
    17  
    18  func print0(w io.Writer, seen map[*gb.Action]bool, a *gb.Action) {
    19  	if seen[a] {
    20  		return
    21  	}
    22  
    23  	split := func(s string) string {
    24  		return strings.Replace(strings.Replace(s, ": ", "\n", -1), ",", "\n", -1)
    25  	}
    26  
    27  	for _, d := range a.Deps {
    28  		print0(w, seen, d)
    29  		fmt.Fprintf(w, "%q -> %q;\n", split(a.Name), split(d.Name))
    30  	}
    31  
    32  	seen[a] = true
    33  }