Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
Antoine Gelloz committed Apr 19, 2024
1 parent d1d4cca commit 32e5396
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 11 deletions.
5 changes: 3 additions & 2 deletions cmd/graph.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,8 @@ func doGraph(opts GraphOpts) error {
}
logger.Debugf("Generate DAG -- Done")

graph.Print()

logger.Debugf("Print DAG")
graph.Print(opts.BuildPath)
logger.Debugf("Print DAG -- Done")
return nil
}
12 changes: 7 additions & 5 deletions pkg/dag/dag.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,13 @@ type DAG struct {
nodes []*Node // Root nodes of the graph.
}

func (d *DAG) Print() {
for _, t := range d.nodes {
if err := DefaultTree.WithRoot(t).Render(); err != nil {
logger.Fatalf(err.Error())
}
func (d *DAG) Print(name string) {
rootNode := &Node{
Image: &Image{Name: name},
children: d.nodes,
}
if err := DefaultTree.WithRoot(rootNode).Render(); err != nil {
logger.Fatalf(err.Error())
}
}

Expand Down
8 changes: 4 additions & 4 deletions pkg/dag/printer.go
Original file line number Diff line number Diff line change
Expand Up @@ -114,25 +114,25 @@ func walkOverTree(nodes []*Node, printer TreePrinter, prefix string) string {
if len(node.Children()) == 0 { // if there are no children
ret += prefix + printer.TreeStyle.Sprint(printer.TopRightDownString) +
strings.Repeat(printer.TreeStyle.Sprint(printer.HorizontalString), printer.Indent) +
printer.TextStyle.Sprint(node.Image.Name) + "\n"
printer.TextStyle.Sprint(node.Image.ShortName) + "\n"
} else { // if there are children
ret += prefix + printer.TreeStyle.Sprint(printer.TopRightDownString) +
strings.Repeat(printer.TreeStyle.Sprint(printer.HorizontalString), printer.Indent-1) +
printer.TreeStyle.Sprint(printer.RightDownLeftString) +
printer.TextStyle.Sprint(node.Image.Name) + "\n"
printer.TextStyle.Sprint(node.Image.ShortName) + "\n"
ret += walkOverTree(node.Children(), printer,
prefix+printer.TreeStyle.Sprint(printer.VerticalString)+strings.Repeat(" ", printer.Indent-1))
}
} else if len(nodes) == nodeIndex+1 { // if last in nodes
if len(node.Children()) == 0 { // if there are no children
ret += prefix + printer.TreeStyle.Sprint(printer.TopRightCornerString) +
strings.Repeat(printer.TreeStyle.Sprint(printer.HorizontalString), printer.Indent) +
printer.TextStyle.Sprint(node.Image.Name) + "\n"
printer.TextStyle.Sprint(node.Image.ShortName) + "\n"
} else { // if there are children
ret += prefix + printer.TreeStyle.Sprint(printer.TopRightCornerString) +
strings.Repeat(printer.TreeStyle.Sprint(printer.HorizontalString), printer.Indent-1) +
printer.TreeStyle.Sprint(printer.RightDownLeftString) +
printer.TextStyle.Sprint(node.Image.Name) + "\n"
printer.TextStyle.Sprint(node.Image.ShortName) + "\n"
ret += walkOverTree(node.Children(), printer,
prefix+strings.Repeat(" ", printer.Indent))
}
Expand Down

0 comments on commit 32e5396

Please sign in to comment.