mirror of
https://github.com/taigrr/yq
synced 2025-01-18 04:53:17 -08:00
Compare commits
6 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
90fe9c6512 | ||
|
|
a9ade5a832 | ||
|
|
8d6e3a6a75 | ||
|
|
7a6689eb40 | ||
|
|
e6660e2460 | ||
|
|
28169b04f7 |
17
README.md
17
README.md
@@ -1,4 +1,6 @@
|
|||||||
# yq [](https://travis-ci.org/mikefarah/yq)  
|
# yq
|
||||||
|
|
||||||
|
[](https://travis-ci.org/mikefarah/yq)  
|
||||||
|
|
||||||
|
|
||||||
a lightweight and portable command-line YAML processor
|
a lightweight and portable command-line YAML processor
|
||||||
@@ -82,12 +84,13 @@ Use "yq [command] --help" for more information about a command.
|
|||||||
```
|
```
|
||||||
|
|
||||||
## Contribute
|
## Contribute
|
||||||
1. `make [local] vendor`
|
1. `scripts/devtools.sh`
|
||||||
2. add unit tests
|
2. `make [local] vendor`
|
||||||
3. apply changes (use govendor with a preference to [gopkg](https://gopkg.in/) for package dependencies)
|
3. add unit tests
|
||||||
4. `make [local] build`
|
4. apply changes (use govendor with a preference to [gopkg](https://gopkg.in/) for package dependencies)
|
||||||
5. If required, update the user documentation
|
5. `make [local] build`
|
||||||
|
6. If required, update the user documentation
|
||||||
- Update README.md and/or documentation under the mkdocs folder
|
- Update README.md and/or documentation under the mkdocs folder
|
||||||
- `make [local] build-docs`
|
- `make [local] build-docs`
|
||||||
- browse to docs/index.html and check your changes
|
- browse to docs/index.html and check your changes
|
||||||
6. profit
|
7. profit
|
||||||
|
|||||||
@@ -2,6 +2,7 @@ package main
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"os"
|
||||||
"strings"
|
"strings"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
@@ -846,6 +847,10 @@ c:
|
|||||||
|
|
||||||
func TestMergeCmd_Inplace(t *testing.T) {
|
func TestMergeCmd_Inplace(t *testing.T) {
|
||||||
filename := writeTempYamlFile(readTempYamlFile("examples/data1.yaml"))
|
filename := writeTempYamlFile(readTempYamlFile("examples/data1.yaml"))
|
||||||
|
err := os.Chmod(filename, os.FileMode(int(0666)))
|
||||||
|
if err != nil {
|
||||||
|
t.Error(err)
|
||||||
|
}
|
||||||
defer removeTempYamlFile(filename)
|
defer removeTempYamlFile(filename)
|
||||||
|
|
||||||
cmd := getRootCommand()
|
cmd := getRootCommand()
|
||||||
@@ -853,6 +858,7 @@ func TestMergeCmd_Inplace(t *testing.T) {
|
|||||||
if result.Error != nil {
|
if result.Error != nil {
|
||||||
t.Error(result.Error)
|
t.Error(result.Error)
|
||||||
}
|
}
|
||||||
|
info, _ := os.Stat(filename)
|
||||||
gotOutput := readTempYamlFile(filename)
|
gotOutput := readTempYamlFile(filename)
|
||||||
expectedOutput := `a: simple
|
expectedOutput := `a: simple
|
||||||
b:
|
b:
|
||||||
@@ -861,4 +867,5 @@ b:
|
|||||||
c:
|
c:
|
||||||
test: 1`
|
test: 1`
|
||||||
assertResult(t, expectedOutput, strings.Trim(gotOutput, "\n "))
|
assertResult(t, expectedOutput, strings.Trim(gotOutput, "\n "))
|
||||||
|
assertResult(t, os.FileMode(int(0666)), info.Mode())
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -96,13 +96,11 @@ func writeArray(context interface{}, paths []string, value interface{}) []interf
|
|||||||
if rawIndex == "+" {
|
if rawIndex == "+" {
|
||||||
index = int64(len(array))
|
index = int64(len(array))
|
||||||
} else {
|
} 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)) {
|
for index >= int64(len(array)) {
|
||||||
array = append(array, nil)
|
array = append(array, nil)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -4,6 +4,6 @@
|
|||||||
# at https://github.com/inconshreveable/gonative
|
# at https://github.com/inconshreveable/gonative
|
||||||
|
|
||||||
gox -ldflags "${LDFLAGS}" -output="build/{{.Dir}}_{{.OS}}_{{.Arch}}"
|
gox -ldflags "${LDFLAGS}" -output="build/{{.Dir}}_{{.OS}}_{{.Arch}}"
|
||||||
gox -os=linux -arch=ppc64 -output="build/{{.Dir}}_{{.OS}}_{{.Arch}}"
|
# include non-default linux builds too
|
||||||
gox -os=linux -arch=ppc64le -output="build/{{.Dir}}_{{.OS}}_{{.Arch}}"
|
gox -ldflags "${LDFLAGS}" -os=linux -output="build/{{.Dir}}_{{.OS}}_{{.Arch}}"
|
||||||
|
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
name: yq
|
name: yq
|
||||||
version: 2.1.0
|
version: 2.1.2
|
||||||
summary: A lightweight and portable command-line YAML processor
|
summary: A lightweight and portable command-line YAML processor
|
||||||
description: |
|
description: |
|
||||||
The aim of the project is to be the jq or sed of yaml files.
|
The aim of the project is to be the jq or sed of yaml files.
|
||||||
|
|||||||
@@ -11,7 +11,7 @@ var (
|
|||||||
GitDescribe string
|
GitDescribe string
|
||||||
|
|
||||||
// Version is main version number that is being run at the moment.
|
// 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)
|
// 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
|
// then it means that it is a final release. Otherwise, this is a pre-release
|
||||||
|
|||||||
16
yq.go
16
yq.go
@@ -11,10 +11,10 @@ import (
|
|||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
errors "github.com/pkg/errors"
|
errors "github.com/pkg/errors"
|
||||||
"gopkg.in/spf13/cobra.v0"
|
|
||||||
|
|
||||||
yaml "gopkg.in/mikefarah/yaml.v2"
|
yaml "gopkg.in/mikefarah/yaml.v2"
|
||||||
logging "gopkg.in/op/go-logging.v1"
|
logging "gopkg.in/op/go-logging.v1"
|
||||||
|
cobra "gopkg.in/spf13/cobra.v0"
|
||||||
)
|
)
|
||||||
|
|
||||||
var trimOutput = true
|
var trimOutput = true
|
||||||
@@ -398,7 +398,15 @@ func readAndUpdate(stdOut io.Writer, inputFile string, updateData updateDataFn)
|
|||||||
var destination io.Writer
|
var destination io.Writer
|
||||||
var destinationName string
|
var destinationName string
|
||||||
if writeInplace {
|
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 {
|
if err != nil {
|
||||||
return err
|
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
|
// thanks https://stackoverflow.com/questions/21060945/simple-way-to-copy-a-file-in-golang
|
||||||
func copyFileContents(src, dst string) (err error) {
|
func copyFileContents(src, dst string) (err error) {
|
||||||
in, err := os.Open(src)
|
in, err := os.Open(src) // nolint gosec
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
@@ -606,7 +614,7 @@ func readStream(filename string, yamlDecoder yamlDecoderFn) error {
|
|||||||
if filename == "-" {
|
if filename == "-" {
|
||||||
stream = bufio.NewReader(os.Stdin)
|
stream = bufio.NewReader(os.Stdin)
|
||||||
} else {
|
} else {
|
||||||
file, err := os.Open(filename)
|
file, err := os.Open(filename) // nolint gosec
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user