mirror of
https://github.com/mikefarah/yq.git
synced 2024-12-19 20:19:04 +00:00
Bump golang version to 1.11
This commit is contained in:
parent
386a0ca3c3
commit
77c8f22a79
@ -1,6 +1,6 @@
|
|||||||
language: go
|
language: go
|
||||||
go:
|
go:
|
||||||
- 1.9.x
|
- 1.11.x
|
||||||
script:
|
script:
|
||||||
- scripts/devtools.sh
|
- scripts/devtools.sh
|
||||||
- make local build
|
- make local build
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
FROM golang:1.9 as builder
|
FROM golang:1.11 as builder
|
||||||
|
|
||||||
WORKDIR /go/src/mikefarah/yq
|
WORKDIR /go/src/mikefarah/yq
|
||||||
|
|
||||||
|
5
Makefile
5
Makefile
@ -14,7 +14,6 @@ help:
|
|||||||
@echo ' make build Build yq binary.'
|
@echo ' make build Build yq binary.'
|
||||||
@echo ' make install Install yq.'
|
@echo ' make install Install yq.'
|
||||||
@echo ' make xcompile Build cross-compiled binaries of yq.'
|
@echo ' make xcompile Build cross-compiled binaries of yq.'
|
||||||
@echo ' make snap Build a snap package of yq.'
|
|
||||||
@echo ' make vendor Install dependencies using govendor.'
|
@echo ' make vendor Install dependencies using govendor.'
|
||||||
@echo ' make format Run code formatter.'
|
@echo ' make format Run code formatter.'
|
||||||
@echo ' make check Run static code analysis (lint).'
|
@echo ' make check Run static code analysis (lint).'
|
||||||
@ -65,10 +64,6 @@ xcompile: check
|
|||||||
@find build -type d -exec chmod 755 {} \; || :
|
@find build -type d -exec chmod 755 {} \; || :
|
||||||
@find build -type f -exec chmod 755 {} \; || :
|
@find build -type f -exec chmod 755 {} \; || :
|
||||||
|
|
||||||
.PHONY: snap
|
|
||||||
snap:
|
|
||||||
snapcraft
|
|
||||||
|
|
||||||
.PHONY: install
|
.PHONY: install
|
||||||
install: build
|
install: build
|
||||||
${DOCKRUN} go install
|
${DOCKRUN} go install
|
||||||
|
@ -7,7 +7,7 @@ import (
|
|||||||
"strings"
|
"strings"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
"gopkg.in/spf13/cobra.v0"
|
cobra "gopkg.in/spf13/cobra.v0"
|
||||||
)
|
)
|
||||||
|
|
||||||
func getRootCommand() *cobra.Command {
|
func getRootCommand() *cobra.Command {
|
||||||
@ -122,7 +122,7 @@ func TestReadBadDocumentIndexCmd(t *testing.T) {
|
|||||||
if result.Error == nil {
|
if result.Error == nil {
|
||||||
t.Error("Expected command to fail due to invalid path")
|
t.Error("Expected command to fail due to invalid path")
|
||||||
}
|
}
|
||||||
expectedOutput := `Asked to process document index 1 but there are only 1 document(s)`
|
expectedOutput := `asked to process document index 1 but there are only 1 document(s)`
|
||||||
assertResult(t, expectedOutput, result.Error.Error())
|
assertResult(t, expectedOutput, result.Error.Error())
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -240,7 +240,7 @@ func TestReadCmd_ArrayYaml_ErrorBadPath(t *testing.T) {
|
|||||||
if result.Error == nil {
|
if result.Error == nil {
|
||||||
t.Error("Expected command to fail due to invalid path")
|
t.Error("Expected command to fail due to invalid path")
|
||||||
}
|
}
|
||||||
expectedOutput := `Error reading path in document index 0: Error accessing array: strconv.ParseInt: parsing "x": invalid syntax`
|
expectedOutput := `Error reading path in document index 0: error accessing array: strconv.ParseInt: parsing "x": invalid syntax`
|
||||||
assertResult(t, expectedOutput, result.Error.Error())
|
assertResult(t, expectedOutput, result.Error.Error())
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -250,7 +250,7 @@ func TestReadCmd_ArrayYaml_Splat_ErrorBadPath(t *testing.T) {
|
|||||||
if result.Error == nil {
|
if result.Error == nil {
|
||||||
t.Error("Expected command to fail due to invalid path")
|
t.Error("Expected command to fail due to invalid path")
|
||||||
}
|
}
|
||||||
expectedOutput := `Error reading path in document index 0: Error accessing array: strconv.ParseInt: parsing "x": invalid syntax`
|
expectedOutput := `Error reading path in document index 0: error accessing array: strconv.ParseInt: parsing "x": invalid syntax`
|
||||||
assertResult(t, expectedOutput, result.Error.Error())
|
assertResult(t, expectedOutput, result.Error.Error())
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -307,7 +307,7 @@ func TestReadCmd_ErrorBadPath(t *testing.T) {
|
|||||||
if result.Error == nil {
|
if result.Error == nil {
|
||||||
t.Fatal("Expected command to fail due to invalid path")
|
t.Fatal("Expected command to fail due to invalid path")
|
||||||
}
|
}
|
||||||
expectedOutput := `Error reading path in document index 0: Error accessing array: strconv.ParseInt: parsing "x": invalid syntax`
|
expectedOutput := `Error reading path in document index 0: error accessing array: strconv.ParseInt: parsing "x": invalid syntax`
|
||||||
assertResult(t, expectedOutput, result.Error.Error())
|
assertResult(t, expectedOutput, result.Error.Error())
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -457,7 +457,7 @@ func TestPrefixBadDocumentIndexCmd(t *testing.T) {
|
|||||||
if result.Error == nil {
|
if result.Error == nil {
|
||||||
t.Error("Expected command to fail due to invalid path")
|
t.Error("Expected command to fail due to invalid path")
|
||||||
}
|
}
|
||||||
expectedOutput := `Asked to process document index 1 but there are only 1 document(s)`
|
expectedOutput := `asked to process document index 1 but there are only 1 document(s)`
|
||||||
assertResult(t, expectedOutput, result.Error.Error())
|
assertResult(t, expectedOutput, result.Error.Error())
|
||||||
}
|
}
|
||||||
func TestPrefixMultiAllCmd(t *testing.T) {
|
func TestPrefixMultiAllCmd(t *testing.T) {
|
||||||
@ -647,7 +647,7 @@ func TestWriteBadDocumentIndexCmd(t *testing.T) {
|
|||||||
if result.Error == nil {
|
if result.Error == nil {
|
||||||
t.Error("Expected command to fail due to invalid path")
|
t.Error("Expected command to fail due to invalid path")
|
||||||
}
|
}
|
||||||
expectedOutput := `Asked to process document index 1 but there are only 1 document(s)`
|
expectedOutput := `asked to process document index 1 but there are only 1 document(s)`
|
||||||
assertResult(t, expectedOutput, result.Error.Error())
|
assertResult(t, expectedOutput, result.Error.Error())
|
||||||
}
|
}
|
||||||
func TestWriteMultiAllCmd(t *testing.T) {
|
func TestWriteMultiAllCmd(t *testing.T) {
|
||||||
|
@ -19,9 +19,9 @@ func entryInSlice(context yaml.MapSlice, key interface{}) *yaml.MapItem {
|
|||||||
|
|
||||||
func getMapSlice(context interface{}) yaml.MapSlice {
|
func getMapSlice(context interface{}) yaml.MapSlice {
|
||||||
var mapSlice yaml.MapSlice
|
var mapSlice yaml.MapSlice
|
||||||
switch context.(type) {
|
switch context := context.(type) {
|
||||||
case yaml.MapSlice:
|
case yaml.MapSlice:
|
||||||
mapSlice = context.(yaml.MapSlice)
|
mapSlice = context
|
||||||
default:
|
default:
|
||||||
mapSlice = make(yaml.MapSlice, 0)
|
mapSlice = make(yaml.MapSlice, 0)
|
||||||
}
|
}
|
||||||
@ -29,9 +29,9 @@ func getMapSlice(context interface{}) yaml.MapSlice {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func getArray(context interface{}) (array []interface{}, ok bool) {
|
func getArray(context interface{}) (array []interface{}, ok bool) {
|
||||||
switch context.(type) {
|
switch context := context.(type) {
|
||||||
case []interface{}:
|
case []interface{}:
|
||||||
array = context.([]interface{})
|
array = context
|
||||||
ok = true
|
ok = true
|
||||||
default:
|
default:
|
||||||
array = make([]interface{}, 0)
|
array = make([]interface{}, 0)
|
||||||
@ -146,18 +146,18 @@ func readMapSplat(context yaml.MapSlice, tail []string) (interface{}, error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func recurse(value interface{}, head string, tail []string) (interface{}, error) {
|
func recurse(value interface{}, head string, tail []string) (interface{}, error) {
|
||||||
switch value.(type) {
|
switch value := value.(type) {
|
||||||
case []interface{}:
|
case []interface{}:
|
||||||
if head == "*" {
|
if head == "*" {
|
||||||
return readArraySplat(value.([]interface{}), tail)
|
return readArraySplat(value, tail)
|
||||||
}
|
}
|
||||||
index, err := strconv.ParseInt(head, 10, 64)
|
index, err := strconv.ParseInt(head, 10, 64)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, fmt.Errorf("Error accessing array: %v", err)
|
return nil, fmt.Errorf("error accessing array: %v", err)
|
||||||
}
|
}
|
||||||
return readArray(value.([]interface{}), index, tail)
|
return readArray(value, index, tail)
|
||||||
case yaml.MapSlice:
|
case yaml.MapSlice:
|
||||||
return readMap(value.(yaml.MapSlice), head, tail)
|
return readMap(value, head, tail)
|
||||||
default:
|
default:
|
||||||
return nil, nil
|
return nil, nil
|
||||||
}
|
}
|
||||||
|
@ -92,7 +92,7 @@ b:
|
|||||||
if err == nil {
|
if err == nil {
|
||||||
t.Fatal("Expected error due to invalid path")
|
t.Fatal("Expected error due to invalid path")
|
||||||
}
|
}
|
||||||
expectedOutput := `Error accessing array: strconv.ParseInt: parsing "x": invalid syntax`
|
expectedOutput := `error accessing array: strconv.ParseInt: parsing "x": invalid syntax`
|
||||||
assertResult(t, expectedOutput, err.Error())
|
assertResult(t, expectedOutput, err.Error())
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -112,7 +112,7 @@ b:
|
|||||||
if err == nil {
|
if err == nil {
|
||||||
t.Fatal("Expected error due to invalid path")
|
t.Fatal("Expected error due to invalid path")
|
||||||
}
|
}
|
||||||
expectedOutput := `Error accessing array: strconv.ParseInt: parsing "x": invalid syntax`
|
expectedOutput := `error accessing array: strconv.ParseInt: parsing "x": invalid syntax`
|
||||||
assertResult(t, expectedOutput, err.Error())
|
assertResult(t, expectedOutput, err.Error())
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -132,7 +132,7 @@ b:
|
|||||||
if err == nil {
|
if err == nil {
|
||||||
t.Fatal("Expected error due to invalid path")
|
t.Fatal("Expected error due to invalid path")
|
||||||
}
|
}
|
||||||
expectedOutput := `Error accessing array: strconv.ParseInt: parsing "x": invalid syntax`
|
expectedOutput := `error accessing array: strconv.ParseInt: parsing "x": invalid syntax`
|
||||||
assertResult(t, expectedOutput, err.Error())
|
assertResult(t, expectedOutput, err.Error())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -17,16 +17,16 @@ func jsonToString(context interface{}) (string, error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func toJSON(context interface{}) interface{} {
|
func toJSON(context interface{}) interface{} {
|
||||||
switch context.(type) {
|
switch context := context.(type) {
|
||||||
case []interface{}:
|
case []interface{}:
|
||||||
oldArray := context.([]interface{})
|
oldArray := context
|
||||||
newArray := make([]interface{}, len(oldArray))
|
newArray := make([]interface{}, len(oldArray))
|
||||||
for index, value := range oldArray {
|
for index, value := range oldArray {
|
||||||
newArray[index] = toJSON(value)
|
newArray[index] = toJSON(value)
|
||||||
}
|
}
|
||||||
return newArray
|
return newArray
|
||||||
case yaml.MapSlice:
|
case yaml.MapSlice:
|
||||||
oldMap := context.(yaml.MapSlice)
|
oldMap := context
|
||||||
newMap := make(map[string]interface{})
|
newMap := make(map[string]interface{})
|
||||||
for _, entry := range oldMap {
|
for _, entry := range oldMap {
|
||||||
if str, ok := entry.Key.(string); ok {
|
if str, ok := entry.Key.(string); ok {
|
||||||
|
2
merge.go
2
merge.go
@ -1,6 +1,6 @@
|
|||||||
package main
|
package main
|
||||||
|
|
||||||
import "gopkg.in/imdario/mergo.v0"
|
import mergo "gopkg.in/imdario/mergo.v0"
|
||||||
|
|
||||||
func merge(dst interface{}, src interface{}, overwrite bool, append bool) error {
|
func merge(dst interface{}, src interface{}, overwrite bool, append bool) error {
|
||||||
if overwrite {
|
if overwrite {
|
||||||
|
@ -10,7 +10,7 @@ import (
|
|||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
yaml "gopkg.in/mikefarah/yaml.v2"
|
yaml "gopkg.in/mikefarah/yaml.v2"
|
||||||
"gopkg.in/spf13/cobra.v0"
|
cobra "gopkg.in/spf13/cobra.v0"
|
||||||
)
|
)
|
||||||
|
|
||||||
type resulter struct {
|
type resulter struct {
|
||||||
|
8
yq.go
8
yq.go
@ -255,7 +255,7 @@ func readProperty(cmd *cobra.Command, args []string) error {
|
|||||||
if errorReading == io.EOF {
|
if errorReading == io.EOF {
|
||||||
log.Debugf("done %v / %v", currentIndex, docIndexInt)
|
log.Debugf("done %v / %v", currentIndex, docIndexInt)
|
||||||
if !updateAll && currentIndex <= docIndexInt {
|
if !updateAll && currentIndex <= docIndexInt {
|
||||||
return fmt.Errorf("Asked to process document index %v but there are only %v document(s)", docIndex, currentIndex)
|
return fmt.Errorf("asked to process document index %v but there are only %v document(s)", docIndex, currentIndex)
|
||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
@ -370,7 +370,7 @@ func mapYamlDecoder(updateData updateDataFn, encoder *yaml.Encoder) yamlDecoderF
|
|||||||
|
|
||||||
if errorReading == io.EOF {
|
if errorReading == io.EOF {
|
||||||
if !updateAll && currentIndex <= docIndexInt {
|
if !updateAll && currentIndex <= docIndexInt {
|
||||||
return fmt.Errorf("Asked to process document index %v but there are only %v document(s)", docIndex, currentIndex)
|
return fmt.Errorf("asked to process document index %v but there are only %v document(s)", docIndex, currentIndex)
|
||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
} else if errorReading != nil {
|
} else if errorReading != nil {
|
||||||
@ -589,9 +589,9 @@ func toString(context interface{}) (string, error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func yamlToString(context interface{}) (string, error) {
|
func yamlToString(context interface{}) (string, error) {
|
||||||
switch context.(type) {
|
switch context := context.(type) {
|
||||||
case string:
|
case string:
|
||||||
return context.(string), nil
|
return context, nil
|
||||||
default:
|
default:
|
||||||
return marshalContext(context)
|
return marshalContext(context)
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user