Skip to content

Commit

Permalink
Upgrade to the latest version of Kroki Go (#3)
Browse files Browse the repository at this point in the history
  • Loading branch information
ggrossetie committed Feb 20, 2019
1 parent 5195743 commit bf32e50
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 36 deletions.
62 changes: 32 additions & 30 deletions cmd/convert.go
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ func ResolveOutputFilePath(outFile string, filePath string, imageFormat kroki.Im
func ResolveImageFormat(imageFormatRaw string, outFile string) (kroki.ImageFormat, error) {
if imageFormatRaw == "" {
if outFile == "" || outFile == "-" {
return kroki.Svg, nil
return kroki.SVG, nil
}
return ImageFormatFromFile(outFile)
}
Expand All @@ -119,13 +119,15 @@ func ImageFormatFromValue(imageFormatRaw string) (kroki.ImageFormat, error) {
value := strings.ToLower(imageFormatRaw)
switch value {
case "svg":
return kroki.Svg, nil
return kroki.SVG, nil
case "png":
return kroki.ImageFormat("png"), nil
return kroki.PNG, nil
case "jpeg":
return kroki.ImageFormat("jpeg"), nil
return kroki.JPEG, nil
case "pdf":
return kroki.ImageFormat("pdf"), nil
return kroki.PDF, nil
case "base64":
return kroki.Base64, nil
default:
return kroki.ImageFormat(""), errors.Errorf(
"invalid image format %s.",
Expand All @@ -138,35 +140,35 @@ func ImageFormatFromFile(filePath string) (kroki.ImageFormat, error) {
value := strings.ToLower(fileExtension)
switch value {
case ".svg":
return kroki.Svg, nil
return kroki.SVG, nil
case ".png":
return kroki.ImageFormat("png"), nil
return kroki.PNG, nil
case ".jpeg", ".jpg":
return kroki.ImageFormat("jpeg"), nil
return kroki.JPEG, nil
case ".pdf":
return kroki.ImageFormat("pdf"), nil
return kroki.PDF, nil
default:
return kroki.ImageFormat(""), errors.Errorf(
"invalid image format %s.",
value)
}
}

func ResolveGraphFormat(graphFormatRaw string, filePath string) (kroki.GraphFormat, error) {
func ResolveGraphFormat(graphFormatRaw string, filePath string) (kroki.DiagramType, error) {
if graphFormatRaw == "" {
return GraphFormatFromFile(filePath)
} else {
return GraphFormatFromValue(graphFormatRaw)
}
}

func GraphFormatFromValue(value string) (kroki.GraphFormat, error) {
func GraphFormatFromValue(value string) (kroki.DiagramType, error) {
value = strings.ToLower(value)
switch value {
case "dot", "graphviz":
return kroki.Graphviz, nil
return kroki.GraphViz, nil
case "plantuml":
return kroki.Plantuml, nil
return kroki.PlantUML, nil
case "nomnoml":
return kroki.Nomnoml, nil
case "blockdiag":
Expand All @@ -176,34 +178,34 @@ func GraphFormatFromValue(value string) (kroki.GraphFormat, error) {
case "svgbob":
return kroki.Svgbob, nil
case "umlet":
return kroki.Umlet, nil
return kroki.UMlet, nil
case "c4plantuml":
return kroki.C4plantuml, nil
return kroki.C4PlantUML, nil
case "seqdiag":
return kroki.SeqDiag, nil
case "erd", "er":
return kroki.GraphFormat("erd"), nil
return kroki.Erd, nil
case "nwdiag":
return kroki.GraphFormat("nwdiag"), nil
return kroki.NwDiag, nil
case "actdiag":
return kroki.GraphFormat("actdiag"), nil
return kroki.ActDiag, nil
case "ditaa":
return kroki.GraphFormat("ditaa"), nil
return kroki.Ditaa, nil
default:
return kroki.GraphFormat(""), errors.Errorf(
return kroki.DiagramType(""), errors.Errorf(
"invalid graph format %s.",
value)
}
}

func GraphFormatFromFile(filePath string) (kroki.GraphFormat, error) {
func GraphFormatFromFile(filePath string) (kroki.DiagramType, error) {
fileExtension := filepath.Ext(filePath)
value := strings.ToLower(fileExtension)
switch value {
case ".dot", ".gv", ".graphviz":
return kroki.Graphviz, nil
return kroki.GraphViz, nil
case ".puml", ".plantuml":
return kroki.Plantuml, nil
return kroki.PlantUML, nil
case ".nomnoml":
return kroki.Nomnoml, nil
case ".blockdiag":
Expand All @@ -213,21 +215,21 @@ func GraphFormatFromFile(filePath string) (kroki.GraphFormat, error) {
case ".svgbob":
return kroki.Svgbob, nil
case ".umlet":
return kroki.Umlet, nil
return kroki.UMlet, nil
case ".c4puml", ".c4", ".c4plantuml":
return kroki.C4plantuml, nil
return kroki.C4PlantUML, nil
case ".seqdiag":
return kroki.SeqDiag, nil
case ".erd", ".er":
return kroki.GraphFormat("erd"), nil
return kroki.Erd, nil
case ".nwdiag":
return kroki.GraphFormat("nwdiag"), nil
return kroki.NwDiag, nil
case ".actdiag":
return kroki.GraphFormat("actdiag"), nil
return kroki.ActDiag, nil
case ".ditaa":
return kroki.GraphFormat("ditaa"), nil
return kroki.Ditaa, nil
default:
return kroki.GraphFormat(""), errors.Errorf(
return kroki.DiagramType(""), errors.Errorf(
"unable to infer the graph format from the file extension %s, please specify the diagram type using --type flag.",
value)
}
Expand Down
10 changes: 5 additions & 5 deletions cmd/convert_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,13 +28,13 @@ func TestResolveOutputFilePath(t *testing.T) {
{
filePath: "/path/to/hello.dot",
outFile: "",
imageFormat: kroki.Svg,
imageFormat: kroki.SVG,
expected: "/path/to/hello.svg",
},
{
filePath: "/path/dot/hello.dot",
outFile: "",
imageFormat: kroki.Svg,
imageFormat: kroki.SVG,
expected: "/path/dot/hello.svg",
},
{
Expand Down Expand Up @@ -68,17 +68,17 @@ func TestResolveImageFormat(t *testing.T) {
{
imageFormatRaw: "",
outFile: "",
expected: kroki.Svg, // default value
expected: kroki.SVG, // default value
},
{
imageFormatRaw: "SVG",
outFile: "",
expected: kroki.Svg,
expected: kroki.SVG,
},
{
imageFormatRaw: "SVG",
outFile: "out.png",
expected: kroki.Svg, // --format flag has priority over output file extension
expected: kroki.SVG, // --format flag has priority over output file extension
},
{
imageFormatRaw: "PNG",
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,5 @@ require (
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.1.0
github.com/yuzutech/kroki-go v0.1.1-0.20190219183547-bfe91c3e23c2
)
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@ 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=
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 bf32e50

Please sign in to comment.