Skip to content

Commit

Permalink
Add RackDiag, PacketDiag, Vega, Vega-Lite and WaveDrom support (#12)
Browse files Browse the repository at this point in the history
* Add RackDiag, PacketDiag, Vega, Vega-Lite and WaveDrom support

Upgrade to kroki-go v0.4.0

* Update goreleaser config
  • Loading branch information
ggrossetie committed Mar 22, 2020
1 parent 359bcf9 commit b802f44
Show file tree
Hide file tree
Showing 5 changed files with 73 additions and 7 deletions.
9 changes: 5 additions & 4 deletions .goreleaser.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,11 @@ builds:
goarch:
- amd64

archive:
format_overrides:
- goos: windows
format: zip
archives:
-
format_overrides:
- goos: windows
format: zip

release:
github:
Expand Down
20 changes: 20 additions & 0 deletions cmd/convert.go
Original file line number Diff line number Diff line change
Expand Up @@ -191,6 +191,16 @@ func GraphFormatFromValue(value string) (kroki.DiagramType, error) {
return kroki.ActDiag, nil
case "ditaa":
return kroki.Ditaa, nil
case "rackdiag":
return kroki.RackDiag, nil
case "packetdiag":
return kroki.PacketDiag, nil
case "vega":
return kroki.Vega, nil
case "vegalite":
return kroki.VegaLite, nil
case "wavedrom":
return kroki.WaveDrom, nil
default:
return kroki.DiagramType(""), errors.Errorf(
"invalid graph format %s.",
Expand Down Expand Up @@ -228,6 +238,16 @@ func GraphFormatFromFile(filePath string) (kroki.DiagramType, error) {
return kroki.ActDiag, nil
case ".ditaa":
return kroki.Ditaa, nil
case ".rackdiag":
return kroki.RackDiag, nil
case ".packetdiag":
return kroki.PacketDiag, nil
case ".vega", ".vg":
return kroki.Vega, nil
case ".vegalite", ".vgl", ".vl":
return kroki.VegaLite, nil
case "wavedrom":
return kroki.WaveDrom, nil
default:
return kroki.DiagramType(""), errors.Errorf(
"unable to infer the graph format from the file extension %s, please specify the diagram type using --type flag.",
Expand Down
43 changes: 43 additions & 0 deletions cmd/convert_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,49 @@ func TestResolveOutputFilePath(t *testing.T) {
}
}

func TestGraphFormatFromFile(t *testing.T) {
cases := []struct {
filePath string
expected kroki.DiagramType
}{
{
filePath: "/path/to/hello.dot",
expected: kroki.GraphViz,
},
{
filePath: "/path/to/hello.puml",
expected: kroki.PlantUML,
},
{
filePath: "/path/to/hello.plantuml",
expected: kroki.PlantUML,
},
{
filePath: "/path/to/hello.vega",
expected: kroki.Vega,
},
{
filePath: "/path/to/hello.vg",
expected: kroki.Vega,
},
{
filePath: "hello.vl",
expected: kroki.VegaLite,
},
{
filePath: "hello.c4",
expected: kroki.C4PlantUML,
},
}
for _, c := range cases {

result, _ := GraphFormatFromFile(c.filePath)
if result != c.expected {
t.Errorf("GraphFormatFromFile error\nexpected: %s\nactual: %s", c.expected, result)
}
}
}

func TestResolveImageFormat(t *testing.T) {
cases := []struct {
imageFormatRaw string
Expand Down
4 changes: 3 additions & 1 deletion go.mod
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
module kroki

go 1.14

require (
github.com/inconshreveable/mousetrap v1.0.0 // indirect
github.com/pkg/errors v0.8.1
github.com/spf13/cobra v0.0.3
github.com/spf13/viper v1.3.1
github.com/yuzutech/kroki-go v0.3.0
github.com/yuzutech/kroki-go v0.4.0
)
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -35,12 +35,12 @@ github.com/ugorji/go/codec v0.0.0-20181204163529-d75b2dcb6bc8/go.mod h1:VFNgLljT
github.com/xordataexchange/crypt v0.0.3-0.20170626215501-b2862e3d0a77/go.mod h1:aYKd//L2LvnjZzWKhF00oedf4jCCReLcmhLdhm1A27Q=
github.com/yuzutech/kroki-go v0.1.0 h1:fuQTmYDpZM1LMIxp9NVuL69a823aef9lAuCQ17IUkpU=
github.com/yuzutech/kroki-go v0.1.0/go.mod h1:75GoPIdAFlGbVkHdyNhF5qHlf3uT0jWpBIFuCVz8omY=
github.com/yuzutech/kroki-go v0.1.1-0.20190219183547-bfe91c3e23c2 h1:1Vzhq5g76xAazH/2CSoE7GfVxSl28/+9rnkqMA8VqsQ=
github.com/yuzutech/kroki-go v0.1.1-0.20190219183547-bfe91c3e23c2/go.mod h1:Cys0gjXdlViePdrZ4AKMUyX4yVIAoIhMBhvpYPJahrk=
github.com/yuzutech/kroki-go v0.2.0 h1:BZ7CMkepyJ4JGUrO43GRRKTCMnAOc0eFceZBrPm6zuQ=
github.com/yuzutech/kroki-go v0.2.0/go.mod h1:Cys0gjXdlViePdrZ4AKMUyX4yVIAoIhMBhvpYPJahrk=
github.com/yuzutech/kroki-go v0.3.0 h1:GIQv3jVQF8GNl6k+el55pksFeV7mJ9dQr9wPjyNj6nI=
github.com/yuzutech/kroki-go v0.3.0/go.mod h1:Cys0gjXdlViePdrZ4AKMUyX4yVIAoIhMBhvpYPJahrk=
github.com/yuzutech/kroki-go v0.4.0 h1:2w2Vxd7yleXB29vZUL7UVZ2RFL3UfTgYwd4I6poNMIM=
github.com/yuzutech/kroki-go v0.4.0/go.mod h1:Cys0gjXdlViePdrZ4AKMUyX4yVIAoIhMBhvpYPJahrk=
golang.org/x/crypto v0.0.0-20181203042331-505ab145d0a9/go.mod h1:6SG95UA2DQfeDnfUPMdvaQW0Q7yPrPDi9nlGo2tz2b4=
golang.org/x/sys v0.0.0-20181205085412-a5c9d58dba9a h1:1n5lsVfiQW3yfsRGu98756EH1YthsFqr/5mxHduZW2A=
golang.org/x/sys v0.0.0-20181205085412-a5c9d58dba9a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
Expand Down

0 comments on commit b802f44

Please sign in to comment.