Skip to content

Commit

Permalink
updates
Browse files Browse the repository at this point in the history
  • Loading branch information
wcharczuk committed Feb 4, 2024
1 parent 9ec5362 commit 9bbab83
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 42 deletions.
42 changes: 0 additions & 42 deletions dot.go
Original file line number Diff line number Diff line change
@@ -1,12 +1,8 @@
package incr

import (
"bytes"
"fmt"
"io"
"os"
"os/exec"
"path/filepath"
"slices"
"strings"
)
Expand Down Expand Up @@ -73,41 +69,3 @@ func Dot(wr io.Writer, g *Graph) (err error) {
writef(0, "}")
return
}

func homedir(filename string) string {
var rootDir string
if rootDir = os.Getenv("INCR_DEBUG_DOT_ROOT"); rootDir == "" {
rootDir = os.ExpandEnv("$HOME/Desktop")
}
return filepath.Join(rootDir, filename)
}

func dumpDot(g *Graph, path string) error {
if os.Getenv("INCR_DEBUG_DOT") != "true" {
return nil
}

dotContents := new(bytes.Buffer)
if err := Dot(dotContents, g); err != nil {
return err
}
dotOutput, err := os.Create(os.ExpandEnv(path))
if err != nil {
return err
}
defer func() { _ = dotOutput.Close() }()
dotFullPath, err := exec.LookPath("dot")
if err != nil {
return fmt.Errorf("there was an issue finding `dot` in your path; you may need to install the `graphviz` package or similar on your platform: %w", err)
}

errOut := new(bytes.Buffer)
cmd := exec.Command(dotFullPath, "-Tpng")
cmd.Stdin = dotContents
cmd.Stdout = dotOutput
cmd.Stderr = errOut
if err := cmd.Run(); err != nil {
return fmt.Errorf("%v; %w", errOut.String(), err)
}
return nil
}
41 changes: 41 additions & 0 deletions main_test.go
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
package incr

import (
"bytes"
"context"
"fmt"
"math"
"os"
"os/exec"
"path/filepath"
"testing"

"github.com/wcharczuk/go-incr/testutil"
Expand Down Expand Up @@ -180,3 +183,41 @@ func createDynamicBind(ctx context.Context, label string, a, b Incr[string]) (Va
bind.Node().SetLabel(fmt.Sprintf("bind - %s", label))
return bindVar, bind
}

func homedir(filename string) string {
var rootDir string
if rootDir = os.Getenv("INCR_DEBUG_DOT_ROOT"); rootDir == "" {
rootDir = os.ExpandEnv("$HOME/Desktop")
}
return filepath.Join(rootDir, filename)
}

func dumpDot(g *Graph, path string) error {
if os.Getenv("INCR_DEBUG_DOT") != "true" {
return nil
}

dotContents := new(bytes.Buffer)
if err := Dot(dotContents, g); err != nil {
return err
}
dotOutput, err := os.Create(os.ExpandEnv(path))
if err != nil {
return err
}
defer func() { _ = dotOutput.Close() }()
dotFullPath, err := exec.LookPath("dot")
if err != nil {
return fmt.Errorf("there was an issue finding `dot` in your path; you may need to install the `graphviz` package or similar on your platform: %w", err)
}

errOut := new(bytes.Buffer)
cmd := exec.Command(dotFullPath, "-Tpng")
cmd.Stdin = dotContents
cmd.Stdout = dotOutput
cmd.Stderr = errOut
if err := cmd.Run(); err != nil {
return fmt.Errorf("%v; %w", errOut.String(), err)
}
return nil
}

0 comments on commit 9bbab83

Please sign in to comment.