Skip to content

Commit

Permalink
fix: pass generated filename as arg
Browse files Browse the repository at this point in the history
Signed-off-by: ismael FALL <ismael.fall@epitech.eu>
  • Loading branch information
Doozers committed Apr 13, 2023
1 parent 2b2d9b6 commit a6bc25b
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 11 deletions.
15 changes: 9 additions & 6 deletions cmd/depviz/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,6 @@ import (
"os/signal"
"time"

"github.com/cayleygraph/cayley"
"github.com/cayleygraph/cayley/graph"
_ "github.com/cayleygraph/cayley/graph/kv/bolt"
"github.com/cayleygraph/cayley/schema"
"github.com/oklog/run"
"github.com/peterbourgon/ff/v3/ffcli"
"go.uber.org/zap"
"moul.io/banner"
"moul.io/depviz/v3/pkg/dvcore"
Expand All @@ -26,6 +20,13 @@ import (
"moul.io/srand"
"moul.io/u"
"moul.io/zapconfig"

"github.com/cayleygraph/cayley"
"github.com/cayleygraph/cayley/graph"
_ "github.com/cayleygraph/cayley/graph/kv/bolt"
"github.com/cayleygraph/cayley/schema"
"github.com/oklog/run"
"github.com/peterbourgon/ff/v3/ffcli"
)

var (
Expand Down Expand Up @@ -78,6 +79,7 @@ var (
graphvizFlags = flag.NewFlagSet("graphviz", flag.ExitOnError)
graphvizLabel = graphvizFlags.String("label", "", "label to use for the graph")
graphvizType = graphvizFlags.String("type", "svg", "output type (svg, png, dot)")
graphvizFile = graphvizFlags.String("file", "", "output file (default: stdout)")
)

func main() {
Expand Down Expand Up @@ -376,6 +378,7 @@ func execGenGraphviz(ctx context.Context, args []string) error {
GenOpts: genOpts,
Label: *graphvizLabel,
Type: *graphvizType,
File: *graphvizFile,
}

return dvcore.GenGraphviz(store, args, opts)
Expand Down
16 changes: 11 additions & 5 deletions pkg/dvcore/graphviz.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,18 @@ package dvcore

import (
"fmt"
"os"
"strings"

"github.com/cayleygraph/cayley"
"github.com/cayleygraph/quad"
"github.com/goccy/go-graphviz"
"github.com/goccy/go-graphviz/cgraph"
"go.uber.org/zap"
"moul.io/depviz/v3/pkg/dvmodel"
"moul.io/depviz/v3/pkg/dvparser"
"moul.io/depviz/v3/pkg/dvstore"

"github.com/cayleygraph/cayley"
"github.com/cayleygraph/quad"
"github.com/goccy/go-graphviz"
"github.com/goccy/go-graphviz/cgraph"
)

type GraphvizOpts struct {
Expand All @@ -20,6 +22,7 @@ type GraphvizOpts struct {
// graphviz
Label string
Type string
File string
}

func GenGraphviz(h *cayley.Handle, args []string, opts GraphvizOpts) error {
Expand Down Expand Up @@ -106,7 +109,10 @@ func GenGraphviz(h *cayley.Handle, args []string, opts GraphvizOpts) error {
_ = edge
}
}
return g.RenderFilename(graph, graphviz.Format(opts.Type), "graph."+opts.Type)
if opts.File == "" {
return g.Render(graph, graphviz.Format(opts.Type), os.Stdout)
}
return g.RenderFilename(graph, graphviz.Format(opts.Type), opts.File)
}

func fmtIRI(s quad.IRI) string {
Expand Down

0 comments on commit a6bc25b

Please sign in to comment.