1
0
mirror of https://github.com/taigrr/yq synced 2025-01-18 04:53:17 -08:00

Compare commits

...

6 Commits
2.1.1 ... 2.1.2

Author SHA1 Message Date
Mike Farah
90fe9c6512 Version bump 2018-10-25 16:05:43 +11:00
Thad Craft
a9ade5a832 fixing test lint 2018-10-25 15:46:57 +11:00
Thad Craft
8d6e3a6a75 copying file permissions from original file when inline merging - Closes #180 2018-10-25 15:46:57 +11:00
Mike Farah
7a6689eb40 Fixed latest linting issues 2018-08-06 16:24:06 +10:00
Mike Farah
e6660e2460 Update README.md 2018-07-31 19:04:34 +10:00
Mike Farah
28169b04f7 Added build support for all linux architectures supported by gox 2018-07-23 09:16:52 +10:00
8 changed files with 40 additions and 22 deletions

View File

@@ -1,4 +1,6 @@
# yq [![Build Status](https://travis-ci.org/mikefarah/yq.svg?branch=master)](https://travis-ci.org/mikefarah/yq) ![Docker Pulls](https://img.shields.io/docker/pulls/mikefarah/yq.svg) ![Github Releases (by Release)](https://img.shields.io/github/downloads/mikefarah/yq/total.svg)
# yq
[![Build Status](https://travis-ci.org/mikefarah/yq.svg?branch=master)](https://travis-ci.org/mikefarah/yq) ![Docker Pulls](https://img.shields.io/docker/pulls/mikefarah/yq.svg) ![Github Releases (by Release)](https://img.shields.io/github/downloads/mikefarah/yq/total.svg)
a lightweight and portable command-line YAML processor
@@ -82,12 +84,13 @@ Use "yq [command] --help" for more information about a command.
```
## Contribute
1. `make [local] vendor`
2. add unit tests
3. apply changes (use govendor with a preference to [gopkg](https://gopkg.in/) for package dependencies)
4. `make [local] build`
5. If required, update the user documentation
1. `scripts/devtools.sh`
2. `make [local] vendor`
3. add unit tests
4. apply changes (use govendor with a preference to [gopkg](https://gopkg.in/) for package dependencies)
5. `make [local] build`
6. If required, update the user documentation
- Update README.md and/or documentation under the mkdocs folder
- `make [local] build-docs`
- browse to docs/index.html and check your changes
6. profit
7. profit

View File

@@ -2,6 +2,7 @@ package main
import (
"fmt"
"os"
"strings"
"testing"
@@ -600,7 +601,7 @@ b:
func TestDeleteYamlArray(t *testing.T) {
content := `- 1
- 2
- 3
- 3
`
filename := writeTempYamlFile(content)
defer removeTempYamlFile(filename)
@@ -846,6 +847,10 @@ c:
func TestMergeCmd_Inplace(t *testing.T) {
filename := writeTempYamlFile(readTempYamlFile("examples/data1.yaml"))
err := os.Chmod(filename, os.FileMode(int(0666)))
if err != nil {
t.Error(err)
}
defer removeTempYamlFile(filename)
cmd := getRootCommand()
@@ -853,6 +858,7 @@ func TestMergeCmd_Inplace(t *testing.T) {
if result.Error != nil {
t.Error(result.Error)
}
info, _ := os.Stat(filename)
gotOutput := readTempYamlFile(filename)
expectedOutput := `a: simple
b:
@@ -861,4 +867,5 @@ b:
c:
test: 1`
assertResult(t, expectedOutput, strings.Trim(gotOutput, "\n "))
assertResult(t, os.FileMode(int(0666)), info.Mode())
}

View File

@@ -96,13 +96,11 @@ func writeArray(context interface{}, paths []string, value interface{}) []interf
if rawIndex == "+" {
index = int64(len(array))
} else {
index, _ = strconv.ParseInt(rawIndex, 10, 64)
index, _ = strconv.ParseInt(rawIndex, 10, 64) // nolint
// writeArray is only called by updatedChildValue which handles parsing the
// index, as such this renders this dead code.
}
// writeArray is only called by updatedChildValue which handles parsing the
// index, as such this renders this dead code.
// if err != nil {
// return array, fmt.Errorf("Error accessing array: %v", err)
// }
for index >= int64(len(array)) {
array = append(array, nil)
}

View File

@@ -4,6 +4,6 @@
# at https://github.com/inconshreveable/gonative
gox -ldflags "${LDFLAGS}" -output="build/{{.Dir}}_{{.OS}}_{{.Arch}}"
gox -os=linux -arch=ppc64 -output="build/{{.Dir}}_{{.OS}}_{{.Arch}}"
gox -os=linux -arch=ppc64le -output="build/{{.Dir}}_{{.OS}}_{{.Arch}}"
# include non-default linux builds too
gox -ldflags "${LDFLAGS}" -os=linux -output="build/{{.Dir}}_{{.OS}}_{{.Arch}}"

View File

@@ -1,5 +1,5 @@
name: yq
version: 2.1.0
version: 2.1.2
summary: A lightweight and portable command-line YAML processor
description: |
The aim of the project is to be the jq or sed of yaml files.

2
test.yml Normal file
View File

@@ -0,0 +1,2 @@
a: apple
c: cat

View File

@@ -11,7 +11,7 @@ var (
GitDescribe string
// Version is main version number that is being run at the moment.
Version = "2.1.1"
Version = "2.1.2"
// VersionPrerelease is a pre-release marker for the version. If this is "" (empty string)
// then it means that it is a final release. Otherwise, this is a pre-release

16
yq.go
View File

@@ -11,10 +11,10 @@ import (
"strings"
errors "github.com/pkg/errors"
"gopkg.in/spf13/cobra.v0"
yaml "gopkg.in/mikefarah/yaml.v2"
logging "gopkg.in/op/go-logging.v1"
cobra "gopkg.in/spf13/cobra.v0"
)
var trimOutput = true
@@ -398,7 +398,15 @@ func readAndUpdate(stdOut io.Writer, inputFile string, updateData updateDataFn)
var destination io.Writer
var destinationName string
if writeInplace {
var tempFile, err = ioutil.TempFile("", "temp")
info, err := os.Stat(inputFile)
if err != nil {
return err
}
tempFile, err := ioutil.TempFile("", "temp")
if err != nil {
return err
}
err = tempFile.Chmod(info.Mode())
if err != nil {
return err
}
@@ -564,7 +572,7 @@ func safelyRenameFile(from string, to string) {
// thanks https://stackoverflow.com/questions/21060945/simple-way-to-copy-a-file-in-golang
func copyFileContents(src, dst string) (err error) {
in, err := os.Open(src)
in, err := os.Open(src) // nolint gosec
if err != nil {
return err
}
@@ -606,7 +614,7 @@ func readStream(filename string, yamlDecoder yamlDecoderFn) error {
if filename == "-" {
stream = bufio.NewReader(os.Stdin)
} else {
file, err := os.Open(filename)
file, err := os.Open(filename) // nolint gosec
if err != nil {
return err
}