Skip to content

Commit

Permalink
fix(win): escape JSON values
Browse files Browse the repository at this point in the history
  • Loading branch information
develar committed Jan 11, 2018
1 parent 858229a commit 9c01bb5
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 18 deletions.
1 change: 1 addition & 0 deletions icons/error.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package icons
import "fmt"

type ImageError interface {
Error() string
ErrorCode() string
}

Expand Down
9 changes: 9 additions & 0 deletions icons/icons-api.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,15 @@ type IconListResult struct {
Icons []IconInfo `json:"icons"`
}

type IconConvertResult struct {
File string `json:"file"`
}

type MisConfigurationError struct {
Message string `json:"error"`
Code string `json:"errorCode"`
}

func LoadImage(file string) (image.Image, error) {
reader, err := os.Open(file)
if err != nil {
Expand Down
28 changes: 11 additions & 17 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import (
)

var (
app = kingpin.New("app-builder", "app-builder").Version("0.3.0")
app = kingpin.New("app-builder", "app-builder").Version("0.3.1")

icnsToPng = app.Command("icns-to-png", "convert ICNS to PNG")
icnsToPngInFile = icnsToPng.Flag("input", "input ICNS file").Short('i').Required().String()
Expand Down Expand Up @@ -51,7 +51,7 @@ func main() {
if err != nil {
log.Fatalf("%+v\n", err)
}
err = writeIconListResult(result)
err = writeJsonToStdOut(result)
if err != nil {
log.Fatalf("%+v\n", err)
}
Expand All @@ -61,7 +61,7 @@ func main() {
if err != nil {
log.Fatalf("%+v\n", err)
}
err = writeIconListResult(result)
err = writeJsonToStdOut(result)
if err != nil {
log.Fatalf("%+v\n", err)
}
Expand Down Expand Up @@ -101,14 +101,14 @@ func doConvertIcon() {
}
}

_, err = fmt.Printf("{\"file\":\"%s\"}", resultFile)
err = writeJsonToStdOut(icons.IconConvertResult{File: resultFile})
if err != nil {
log.Fatalf("%+v\n", err)
}
}

func printAppError(error icons.ImageError) {
_, err := fmt.Printf("{\"error\":\"%s\", \"errorCode\": \"%s\"}", error, error.ErrorCode())
err := writeJsonToStdOut(icons.MisConfigurationError{Message: error.Error(), Code: error.ErrorCode()})
if err != nil {
log.Fatalf("%+v\n", err)
}
Expand All @@ -130,7 +130,11 @@ func doBuildBlockMap() error {
return err
}

serializedInputInfo, err := json.Marshal(inputInfo)
return writeJsonToStdOut(inputInfo)
}

func writeJsonToStdOut(v interface{}) error {
serializedInputInfo, err := json.Marshal(v)
if err != nil {
return err
}
Expand All @@ -140,14 +144,4 @@ func doBuildBlockMap() error {
}

return nil
}

func writeIconListResult(result *icons.IconListResult) error {
serializedResult, err := json.Marshal(result)
if err != nil {
return err
}

_, err = os.Stdout.Write(serializedResult)
return err
}
}
2 changes: 1 addition & 1 deletion publish.sh
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ if [ -z "$GITHUB_TOKEN" ] ; then
fi

NAME=app-builder
VERSION=0.3.0
VERSION=0.3.1

OUT_DIR="$BASEDIR/dist/out"
rm -rf "$OUT_DIR"
Expand Down

0 comments on commit 9c01bb5

Please sign in to comment.