Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
Antoine Gelloz committed Apr 22, 2024
1 parent d1d4cca commit b84abcf
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 16 deletions.
9 changes: 5 additions & 4 deletions cmd/graph.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@ type GraphOpts struct {
// buildCmd represents the build command.
var graphCmd = &cobra.Command{
Use: "graph",
Short: "",
Long: `dib build will compute the graph of images, and print it.`,
Short: "Compute the graph of images, and print it.",
Long: "Compute the graph of images, and print it.",
Run: func(cmd *cobra.Command, _ []string) {
bindPFlagsSnakeCase(cmd.Flags())

Expand Down 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
5 changes: 2 additions & 3 deletions pkg/dib/generate_dag.go
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,7 @@ func generateHashes(graph *dag.DAG, allFiles []string, customHashListPath string

for {
needRepass := false
err := graph.WalkErr(func(node *dag.Node) error {
if err := graph.WalkErr(func(node *dag.Node) error {
var parentHashes []string
for _, parent := range node.Parents() {
if parent.Image.Hash == "" {
Expand Down Expand Up @@ -218,8 +218,7 @@ func generateHashes(graph *dag.DAG, allFiles []string, customHashListPath string
}
node.Image.Hash = hash
return nil
})
if err != nil {
}); err != nil {
return err
}
if !needRepass {
Expand Down

0 comments on commit b84abcf

Please sign in to comment.