From 6b825965462bc63ec0d73091bfa87167853c9337 Mon Sep 17 00:00:00 2001 From: Guillaume Grossetie Date: Wed, 20 Feb 2019 19:00:04 +0100 Subject: [PATCH] Upgrade to the latest version of Kroki Go --- cmd/convert.go | 62 +++++++++++++++++++++++---------------------- cmd/convert_test.go | 10 ++++---- go.mod | 2 +- go.sum | 2 ++ 4 files changed, 40 insertions(+), 36 deletions(-) diff --git a/cmd/convert.go b/cmd/convert.go index 5d11c2b..0fb4449 100644 --- a/cmd/convert.go +++ b/cmd/convert.go @@ -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) } @@ -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.", @@ -138,13 +140,13 @@ 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.", @@ -152,7 +154,7 @@ func ImageFormatFromFile(filePath string) (kroki.ImageFormat, error) { } } -func ResolveGraphFormat(graphFormatRaw string, filePath string) (kroki.GraphFormat, error) { +func ResolveGraphFormat(graphFormatRaw string, filePath string) (kroki.DiagramType, error) { if graphFormatRaw == "" { return GraphFormatFromFile(filePath) } else { @@ -160,13 +162,13 @@ func ResolveGraphFormat(graphFormatRaw string, filePath string) (kroki.GraphForm } } -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": @@ -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": @@ -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) } diff --git a/cmd/convert_test.go b/cmd/convert_test.go index 04f2b66..5774d6e 100644 --- a/cmd/convert_test.go +++ b/cmd/convert_test.go @@ -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", }, { @@ -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", diff --git a/go.mod b/go.mod index 7c01b52..65f18bd 100644 --- a/go.mod +++ b/go.mod @@ -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 ) diff --git a/go.sum b/go.sum index 331af3b..53b791a 100644 --- a/go.sum +++ b/go.sum @@ -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=