Skip to content

Commit

Permalink
Migrate to Go YAML v3
Browse files Browse the repository at this point in the history
Introduce consistent usage of Go YAML v3 type `Node` in all functions.

Remove all old Go YAML v2 map item and slice references.

Rewrite the restructure code based on the previous style and ideas.

Rework test case setup to introduce YAML Node type.

Drop version directory in main library package path.
  • Loading branch information
HeavyWombat committed Dec 31, 2019
1 parent bb758c6 commit 357a0e0
Show file tree
Hide file tree
Showing 26 changed files with 649 additions and 711 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
binaries
**/*.coverprofile
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
.PHONY: all clean test verify build

version := $(shell git describe --tags --abbrev=0 2>/dev/null || (git rev-parse HEAD | cut -c-8))
sources := $(wildcard cmd/ytbx/*.go internal/cmd/*.go pkg/v1/ytbx/*.go)
sources := $(wildcard cmd/ytbx/*.go internal/cmd/*.go pkg/ytbx/*.go)

all: clean verify test build

Expand Down
4 changes: 2 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,12 @@ go 1.12
require (
github.com/BurntSushi/toml v0.3.1
github.com/gonvenience/bunt v1.1.1
github.com/gonvenience/neat v1.1.0
github.com/gonvenience/neat v1.1.1
github.com/gonvenience/wrap v1.1.0
github.com/gorilla/mux v1.7.3
github.com/onsi/ginkgo v1.11.0
github.com/onsi/gomega v1.8.1
github.com/spf13/cobra v0.0.5
github.com/virtuald/go-ordered-json v0.0.0-20170621173500-b18e6e673d74
gopkg.in/yaml.v2 v2.2.7
gopkg.in/yaml.v3 v3.0.0-20191120175047-4206685974f2
)
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ github.com/fsnotify/fsnotify v1.4.7/go.mod h1:jwhsz4b93w/PPRr/qN1Yymfu8t87LnFCMo
github.com/golang/protobuf v1.2.0/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U=
github.com/gonvenience/bunt v1.1.1 h1:isYxOpDqbRMOSRhZtoux1tYvhhQ/AIbVDFrs24l6t0M=
github.com/gonvenience/bunt v1.1.1/go.mod h1:lsyhkmNpSAzhVx059BD0fQy5F29rWcS6AHb7UWNlT/s=
github.com/gonvenience/neat v1.1.0 h1:xuEH2rYPedbIwuaYBJAtGwCJHwRlo8jF5PScLizuI5Y=
github.com/gonvenience/neat v1.1.0/go.mod h1:Yb+9Jlr04pbtcRU8EGosVheOEBs//Lw/OXvgDyQfLTQ=
github.com/gonvenience/neat v1.1.1 h1:uX5uxp3/KVMNgvfFceA5gkFeSofaqREIhOWepZafYlE=
github.com/gonvenience/neat v1.1.1/go.mod h1:Yb+9Jlr04pbtcRU8EGosVheOEBs//Lw/OXvgDyQfLTQ=
github.com/gonvenience/term v1.0.0 h1:joCB/j0Ngmdakd3muuLgAGPMf7DNKdoe708c1I6RiBs=
github.com/gonvenience/term v1.0.0/go.mod h1:wohD4Iqso9Eol7qc2VnNhSFFhZxok5PvO7pZhdrAn4E=
github.com/gonvenience/wrap v1.1.0 h1:d8gEZrXS/zg4BC1q0U4nHpPIh5k6muKpQ1+rQFBwpYc=
Expand Down
2 changes: 1 addition & 1 deletion internal/cmd/compare.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ import (
"fmt"

"github.com/gonvenience/wrap"
"github.com/homeport/ytbx/pkg/v1/ytbx"
"github.com/homeport/ytbx/pkg/ytbx"
"github.com/spf13/cobra"
)

Expand Down
2 changes: 1 addition & 1 deletion internal/cmd/get.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ import (

"github.com/gonvenience/neat"
"github.com/gonvenience/wrap"
"github.com/homeport/ytbx/pkg/v1/ytbx"
"github.com/homeport/ytbx/pkg/ytbx"
"github.com/spf13/cobra"
)

Expand Down
2 changes: 1 addition & 1 deletion internal/cmd/paths.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ import (
"fmt"

"github.com/gonvenience/wrap"
"github.com/homeport/ytbx/pkg/v1/ytbx"
"github.com/homeport/ytbx/pkg/ytbx"
"github.com/spf13/cobra"
)

Expand Down
19 changes: 10 additions & 9 deletions internal/cmd/restructure.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,9 @@ import (

"github.com/gonvenience/bunt"
"github.com/gonvenience/neat"
"github.com/homeport/ytbx/pkg/v1/ytbx"
"github.com/homeport/ytbx/pkg/ytbx"
"github.com/spf13/cobra"
"gopkg.in/yaml.v2"
yamlv3 "gopkg.in/yaml.v3"
)

var inplace bool
Expand All @@ -53,7 +53,7 @@ var restructureCmd = &cobra.Command{
}

for i := range input.Documents {
input.Documents[i] = ytbx.RestructureObject(input.Documents[i])
ytbx.RestructureObject(input.Documents[i])
}

if inplace {
Expand All @@ -65,12 +65,12 @@ var restructureCmd = &cobra.Command{
var buf bytes.Buffer
writer := bufio.NewWriter(&buf)
for _, document := range input.Documents {
out, err := yaml.Marshal(document)
out, err := yamlv3.Marshal(document)
if err != nil {
return err
}

fmt.Fprint(writer, "---\n", string(out))
fmt.Fprint(writer, string(out))
}

writer.Flush()
Expand All @@ -83,7 +83,6 @@ var restructureCmd = &cobra.Command{
return err
}

bunt.Println("DimGray{*---*}")
fmt.Print(out)
fmt.Println()
}
Expand All @@ -104,8 +103,8 @@ func init() {
}

func renderLongDescription() string {
var data yaml.MapSlice
yaml.Unmarshal([]byte(`---
var data yamlv3.Node
yamlv3.Unmarshal([]byte(`---
releases:
- sha1: 5ab3b7e685ca18a47d0b4a16d0e3b60832b0a393
name: binary-buildpack
Expand All @@ -114,7 +113,9 @@ releases:
`), &data)

before, _ := neat.ToYAMLString(data)
after, _ := neat.ToYAMLString(ytbx.RestructureObject(data))

ytbx.RestructureObject(&data)
after, _ := neat.ToYAMLString(data)

return bunt.Sprintf(`Restructure the order of keys in YAML maps
Expand Down
2 changes: 1 addition & 1 deletion internal/cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ import (
"github.com/gonvenience/bunt"
"github.com/gonvenience/neat"
"github.com/gonvenience/wrap"
"github.com/homeport/ytbx/pkg/v1/ytbx"
"github.com/homeport/ytbx/pkg/ytbx"
"github.com/spf13/cobra"
)

Expand Down
114 changes: 0 additions & 114 deletions pkg/v1/ytbx/convert.go

This file was deleted.

93 changes: 0 additions & 93 deletions pkg/v1/ytbx/getting.go

This file was deleted.

Loading

0 comments on commit 357a0e0

Please sign in to comment.