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

Compare commits

..

46 Commits

Author SHA1 Message Date
Mike Farah
b8b2c9de61 attempt to fix go get 2019-12-02 10:37:06 +11:00
Mike Farah
f5fdf98c38 Updating release instructions 2019-11-13 12:26:33 +11:00
Mike Farah
29986db8f8 Update doc for go get 2019-11-13 12:25:24 +11:00
Mike Farah
1f4e3a9cde Ignore vendor folder 2019-11-06 11:45:31 +11:00
Mike Farah
b6da773dde Bumbed snapcraft version 2019-11-01 12:40:35 +11:00
Mike Farah
8020d4253b Updated README 2019-11-01 12:40:21 +11:00
Mike Farah
3c701fe98e Incremented version 2019-11-01 10:47:38 +11:00
Mike Farah
97d1aa2b26 Added formatter, fixed docker build 2019-10-31 08:21:19 +11:00
Elliot
d05391e244 update ci to use go 1.13, switch to golangci-lint 2019-10-31 08:21:19 +11:00
Elliot
d1cec1ad18 fix to make it work with modules 2019-10-31 08:21:19 +11:00
Mike Farah
fe5842e5f9 Fix: Only remove original file if copying was successful 2019-08-27 09:21:39 +10:00
Aleksandr Sergin
e0d8cd6bf6 yq small fix 2019-08-27 09:18:38 +10:00
Aleksandr Sergin
8f5ffe47ff return to old behavior, small fix. 2019-08-27 09:18:38 +10:00
Aleksandr Sergin
5acc1e661e fix linter error 2019-08-27 09:18:38 +10:00
Aleksandr Sergin
a9c0ef571c fix linter error 2019-08-27 09:18:38 +10:00
Aleksandr Sergin
7a28531f2f fix linter error 2019-08-27 09:18:38 +10:00
Aleksandr Sergin
5de2bea1b4 fix linter error 2019-08-27 09:18:38 +10:00
Aleksandr Sergin
7320b8d3c9 fix linter error 2019-08-27 09:18:38 +10:00
Aleksandr Sergin
2f70e6f27a fix linter error 2019-08-27 09:18:38 +10:00
Aleksandr Sergin
a9e871ee00 add Move func to avoid 'invalid cross-device link' 2019-08-27 09:18:38 +10:00
Azimjon Ilkhomov
bc4bab9380 Fix typo 2019-08-05 11:30:20 +10:00
Mike Farah
665d9079fa Added goreport to readme 2019-07-23 10:07:59 +10:00
Mike Farah
7b54a44fcf Fixed readme for bash docker alias to bash function, thanks @dead10ck 2019-07-23 09:57:58 +10:00
Kenny Jones
94148e4398 Merge pull request #256 from arnaud-deprez/patch-1
doc: use '--rm' instead of '-rm' for docker command
2019-07-02 09:32:51 -04:00
Arnaud Deprez
f8553162ca doc: use '--rm' instead of '-rm' for docker command 2019-07-02 12:17:35 +00:00
Eduardo Minguez Perez
be532bf2fe Added '-rm' docker flag to remove the containers
Also, added a handy alias just in case.
2019-06-10 21:59:40 +10:00
Mike Farah
e9b8265ca3 Updated docs re creating a new array 2019-05-16 14:57:34 +10:00
Mike Farah
0f8b864321 Updated instructions 2019-05-16 14:56:00 +10:00
Mike Farah
e5bcfedbe9 updating docs 2019-05-16 14:55:32 +10:00
Mike Farah
a5f5fb2562 Publish moves files after uploading for speedy retries 2019-05-16 14:54:58 +10:00
Mike Farah
84de9c078d Improved handling of numeric keys
When there is no match at a given path, numeric keys are assumed to be strings.
To create an array '+' must be used.

e.g: yq n thing[+].cat fred
will create an array under thing, whereas
yq n thing[0].cat fred
will create a map under thing, with a key '0'
2019-05-16 10:03:54 +10:00
Mike Farah
c7f5261036 Bump version 2019-05-16 10:03:54 +10:00
Georgi Knox
6e35356a84 add help description 2019-05-16 09:35:16 +10:00
Mike Farah
b2fe3e6738 fixing delete splat 2019-05-14 11:20:41 +10:00
Mike Farah
774badfef4 Can delete splat!
Fixes https://github.com/mikefarah/yq/issues/175
2019-05-13 09:48:05 +10:00
Mike Farah
c4e9516aa6 Prefix matching splat
Fixes https://github.com/mikefarah/yq/issues/218
2019-05-13 09:32:08 +10:00
Mike Farah
323089eb64 fixed tests for write array splat 2019-05-13 09:13:45 +10:00
Mike Farah
53289366a5 Write array splat 2019-05-01 08:55:44 +10:00
Mike Farah
cda9a82906 Refactoring write command to allow splat 2019-05-01 08:40:35 +10:00
Mike Farah
2dbde6b9fb Can process numeric keys
Fixes: https://github.com/mikefarah/yq/issues/215
2019-04-30 09:43:09 +10:00
Mike Farah
f8c1c3c1b4 Updated instructions w.r.t keys and values starting with dashes 2019-04-29 16:14:33 +10:00
Mike Farah
238a1241d2 Added snap specific notes
https://forum.snapcraft.io/t/requesting-classic-confinement-for-yq/10559
2019-03-27 09:27:07 +11:00
Mike Farah
8a61ef072a Revert "Snapcraft classic confinment to allow access to system resources"
Snap doesn't let me use classic

This reverts commit 4f178d2317.
2019-03-25 09:28:06 +11:00
Mike Farah
4f178d2317 Snapcraft classic confinment to allow access to system resources
https://docs.snapcraft.io/snap-confinement/6233
2019-03-25 09:19:29 +11:00
Mike Farah
133e55105c Bump snapcraft go version 2019-03-22 16:32:30 +11:00
Mike Farah
5e5468af3b Release instructions update 2019-03-22 16:03:11 +11:00
62 changed files with 1587 additions and 4527 deletions

1
.dockerignore Normal file
View File

@@ -0,0 +1 @@
bin

3
.gitignore vendored
View File

@@ -8,6 +8,7 @@ _obj
_test
bin
build
build-done
.DS_Store
# Architecture specific extensions/prefixes
@@ -26,7 +27,7 @@ coverage.out
*.test
*.prof
yaml
vendor/*/
vendor/
tmp/
cover/
yq

View File

@@ -1,6 +1,6 @@
language: go
go:
- 1.11.x
- 1.13.x
script:
- scripts/devtools.sh
- make local build

View File

@@ -1,4 +1,4 @@
FROM golang:1.11 as builder
FROM golang:1.13 as builder
WORKDIR /go/src/mikefarah/yq
@@ -6,10 +6,6 @@ WORKDIR /go/src/mikefarah/yq
COPY ./scripts/devtools.sh /go/src/mikefarah/yq/scripts/devtools.sh
RUN ./scripts/devtools.sh
# cache vendor
COPY ./vendor/vendor.json /go/src/mikefarah/yq/vendor/vendor.json
RUN govendor sync
COPY . /go/src/mikefarah/yq
RUN CGO_ENABLED=0 make local build

View File

@@ -1,4 +1,4 @@
FROM golang:1.9
FROM golang:1.13
COPY scripts/devtools.sh /opt/devtools.sh

View File

@@ -14,7 +14,7 @@ help:
@echo ' make build Build yq binary.'
@echo ' make install Install yq.'
@echo ' make xcompile Build cross-compiled binaries of yq.'
@echo ' make vendor Install dependencies using govendor.'
@echo ' make vendor Install dependencies to vendor directory.'
@echo ' make format Run code formatter.'
@echo ' make check Run static code analysis (lint).'
@echo ' make test Run tests on project.'
@@ -71,8 +71,7 @@ install: build
# Each of the fetch should be an entry within vendor.json; not currently included within project
.PHONY: vendor
vendor: tmp/dev_image_id
${DOCKRUN} govendor sync
@chmod 664 vendor/vendor.json
${DOCKRUN} go mod vendor
# ----------------------------------------------
# develop and test

View File

@@ -1,6 +1,6 @@
# yq
# 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)
[![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) ![Go Report](https://goreportcard.com/badge/github.com/mikefarah/yq)
a lightweight and portable command-line YAML processor
@@ -8,23 +8,42 @@ a lightweight and portable command-line YAML processor
The aim of the project is to be the [jq](https://github.com/stedolan/jq) or sed of yaml files.
## Install
On MacOS:
### On MacOS:
```
brew install yq
```
On Ubuntu and other Linux distros supporting `snap` packages:
### On Ubuntu and other Linux distros supporting `snap` packages:
```
snap install yq
```
On Ubuntu 16.04 or higher from Debian package:
#### Snap notes
`yq` installs with with [_strict confinement_](https://docs.snapcraft.io/snap-confinement/6233) in snap, this means it doesn't have direct access to root files. To read root files you can:
```
sudo cat /etc/myfile | yq -r - somecommand
```
And to write to a root file you can either use [sponge](https://linux.die.net/man/1/sponge):
```
sudo cat /etc/myfile | yq -r - somecommand | sudo sponge /etc/myfile
```
or write to a temporary file:
```
sudo cat /etc/myfile | yq -r - somecommand | sudo tee /etc/myfile.tmp
sudo mv /etc/myfile.tmp /etc/myfile
rm /etc/myfile.tmp
```
### On Ubuntu 16.04 or higher from Debian package:
```
sudo add-apt-repository ppa:rmescandon/yq
sudo apt update
sudo apt install yq -y
```
or, [Download latest binary](https://github.com/mikefarah/yq/releases/latest) or alternatively:
### or, [Download latest binary](https://github.com/mikefarah/yq/releases/latest) or alternatively:
```
go get gopkg.in/mikefarah/yq.v2
GO111MODULE=on go get github.com/mikefarah/yq@2.4.1
```
## Run with Docker
@@ -32,13 +51,21 @@ go get gopkg.in/mikefarah/yq.v2
Oneshot use:
```bash
docker run -v ${PWD}:/workdir mikefarah/yq yq [flags] <command> FILE...
docker run --rm -v ${PWD}:/workdir mikefarah/yq yq [flags] <command> FILE...
```
Run commands interactively:
```bash
docker run -it -v ${PWD}:/workdir mikefarah/yq sh
docker run --rm -it -v ${PWD}:/workdir mikefarah/yq sh
```
It can be useful to have a bash function to avoid typing the whole docker command:
```bash
yq() {
docker run --rm -i -v ${PWD}:/workdir mikefarah/yq yq $@
}
```
## Features
@@ -63,6 +90,8 @@ docker run -it -v ${PWD}:/workdir mikefarah/yq sh
Check out the [documentation](http://mikefarah.github.io/yq/) for more detailed and advanced usage.
```
yq is a lightweight and portable command-line YAML processor. It aims to be the jq or sed of yaml files.
Usage:
yq [flags]
yq [command]
@@ -72,9 +101,9 @@ Available Commands:
help Help about any command
merge yq m [--inplace/-i] [--doc/-d index] [--overwrite/-x] [--append/-a] sample.yaml sample2.yaml
new yq n [--script/-s script_file] a.b.c newValue
prefix yq p [--inplace/-i] [--doc/-d index] sample.yaml a.b.c
read yq r [--doc/-d index] sample.yaml a.b.c
write yq w [--inplace/-i] [--script/-s script_file] [--doc/-d index] sample.yaml a.b.c newValue
prefix yq p [--inplace/-i] [--doc/-d index] sample.yaml a.b.c
Flags:
-h, --help help for yq
@@ -89,10 +118,10 @@ Use "yq [command] --help" for more information about a command.
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)
4. apply changes to go.mod
5. `make [local] build`
6. If required, update the user documentation
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
- browse to docs/index.html and check your changes
7. profit

View File

@@ -7,7 +7,7 @@ import (
"strings"
"testing"
cobra "gopkg.in/spf13/cobra.v0"
"github.com/spf13/cobra"
)
func getRootCommand() *cobra.Command {
@@ -24,7 +24,18 @@ func TestRootCmd(t *testing.T) {
if !strings.Contains(result.Output, "Usage:") {
t.Error("Expected usage message to be printed out, but the usage message was not found.")
}
}
func TestRootCmd_Help(t *testing.T) {
cmd := getRootCommand()
result := runCmd(cmd, "--help")
if result.Error != nil {
t.Error(result.Error)
}
if !strings.Contains(result.Output, "yq is a lightweight and portable command-line YAML processor. It aims to be the jq or sed of yaml files.") {
t.Error("Expected usage message to be printed out, but the usage message was not found.")
}
}
func TestRootCmd_VerboseLong(t *testing.T) {
@@ -374,12 +385,11 @@ func TestPrefixCmdArray(t *testing.T) {
defer removeTempYamlFile(filename)
cmd := getRootCommand()
result := runCmd(cmd, fmt.Sprintf("prefix %s [0].d.[1]", filename))
result := runCmd(cmd, fmt.Sprintf("prefix %s [+].d.[+]", filename))
if result.Error != nil {
t.Error(result.Error)
}
expectedOutput := `- d:
- null
- b:
c: 3
`
@@ -775,7 +785,7 @@ func TestWriteCmd_AppendEmptyArray(t *testing.T) {
defer removeTempYamlFile(filename)
cmd := getRootCommand()
result := runCmd(cmd, fmt.Sprintf("write %s b[+] v", filename))
result := runCmd(cmd, fmt.Sprintf("write -v %s b[+] v", filename))
if result.Error != nil {
t.Error(result.Error)
}
@@ -786,6 +796,66 @@ b:
assertResult(t, expectedOutput, result.Output)
}
func TestWriteCmd_SplatArray(t *testing.T) {
content := `b:
- c: thing
- c: another thing
`
filename := writeTempYamlFile(content)
defer removeTempYamlFile(filename)
cmd := getRootCommand()
result := runCmd(cmd, fmt.Sprintf("write -v %s b[*].c new", filename))
if result.Error != nil {
t.Error(result.Error)
}
expectedOutput := `b:
- c: new
- c: new
`
assertResult(t, expectedOutput, result.Output)
}
func TestWriteCmd_SplatMap(t *testing.T) {
content := `b:
c: thing
d: another thing
`
filename := writeTempYamlFile(content)
defer removeTempYamlFile(filename)
cmd := getRootCommand()
result := runCmd(cmd, fmt.Sprintf("write -v %s b.* new", filename))
if result.Error != nil {
t.Error(result.Error)
}
expectedOutput := `b:
c: new
d: new
`
assertResult(t, expectedOutput, result.Output)
}
func TestWriteCmd_SplatMapEmpty(t *testing.T) {
content := `b:
c: thing
d: another thing
`
filename := writeTempYamlFile(content)
defer removeTempYamlFile(filename)
cmd := getRootCommand()
result := runCmd(cmd, fmt.Sprintf("write -v %s b.c.* new", filename))
if result.Error != nil {
t.Error(result.Error)
}
expectedOutput := `b:
c: thing
d: another thing
`
assertResult(t, expectedOutput, result.Output)
}
func TestDeleteYaml(t *testing.T) {
content := `a: 2
b:
@@ -808,6 +878,102 @@ b:
assertResult(t, expectedOutput, result.Output)
}
func TestDeleteSplatYaml(t *testing.T) {
content := `a: 2
b:
hi:
c: things
d: something else
hello:
c: things2
d: something else2
there:
c: more things
d: more something else
`
filename := writeTempYamlFile(content)
defer removeTempYamlFile(filename)
cmd := getRootCommand()
result := runCmd(cmd, fmt.Sprintf("delete -v %s b.*.c", filename))
if result.Error != nil {
t.Error(result.Error)
}
expectedOutput := `a: 2
b:
hi:
d: something else
hello:
d: something else2
there:
d: more something else
`
assertResult(t, expectedOutput, result.Output)
}
func TestDeleteSplatArrayYaml(t *testing.T) {
content := `a: 2
b:
hi:
- thing: item1
name: fred
- thing: item2
name: sam
`
filename := writeTempYamlFile(content)
defer removeTempYamlFile(filename)
cmd := getRootCommand()
result := runCmd(cmd, fmt.Sprintf("delete -v %s b.hi[*].thing", filename))
if result.Error != nil {
t.Error(result.Error)
}
expectedOutput := `a: 2
b:
hi:
- name: fred
- name: sam
`
assertResult(t, expectedOutput, result.Output)
}
func TestDeleteSplatPrefixYaml(t *testing.T) {
content := `a: 2
b:
hi:
c: things
d: something else
there:
c: more things
d: more something else
there2:
c: more things also
d: more something else also
`
filename := writeTempYamlFile(content)
defer removeTempYamlFile(filename)
cmd := getRootCommand()
result := runCmd(cmd, fmt.Sprintf("delete -v %s b.there*.c", filename))
if result.Error != nil {
t.Error(result.Error)
}
expectedOutput := `a: 2
b:
hi:
c: things
d: something else
there:
d: more something else
there2:
d: more something else also
`
assertResult(t, expectedOutput, result.Output)
}
func TestDeleteYamlArray(t *testing.T) {
content := `- 1
- 2

View File

@@ -2,19 +2,31 @@ package main
import (
"fmt"
"reflect"
"strconv"
"strings"
yaml "gopkg.in/mikefarah/yaml.v2"
yaml "github.com/mikefarah/yaml/v2"
)
func entryInSlice(context yaml.MapSlice, key interface{}) *yaml.MapItem {
func matchesKey(key string, actual interface{}) bool {
var actualString = fmt.Sprintf("%v", actual)
var prefixMatch = strings.TrimSuffix(key, "*")
if prefixMatch != key {
return strings.HasPrefix(actualString, prefixMatch)
}
return actualString == key
}
func entriesInSlice(context yaml.MapSlice, key string) []*yaml.MapItem {
var matches = make([]*yaml.MapItem, 0)
for idx := range context {
var entry = &context[idx]
if entry.Key == key {
return entry
if matchesKey(key, entry.Key) {
matches = append(matches, entry)
}
}
return nil
return matches
}
func getMapSlice(context interface{}) yaml.MapSlice {
@@ -40,27 +52,33 @@ func getArray(context interface{}) (array []interface{}, ok bool) {
return
}
func writeMap(context interface{}, paths []string, value interface{}) yaml.MapSlice {
log.Debugf("writeMap for %v for %v with value %v\n", paths, context, value)
func writeMap(context interface{}, paths []string, value interface{}) interface{} {
log.Debugf("writeMap with path %v for %v to set value %v\n", paths, context, value)
mapSlice := getMapSlice(context)
if len(paths) == 0 {
return mapSlice
return context
}
child := entryInSlice(mapSlice, paths[0])
if child == nil {
children := entriesInSlice(mapSlice, paths[0])
if len(children) == 0 && paths[0] == "*" {
log.Debugf("\tNo matches, return map as is")
return context
}
if len(children) == 0 {
newChild := yaml.MapItem{Key: paths[0]}
mapSlice = append(mapSlice, newChild)
child = entryInSlice(mapSlice, paths[0])
children = entriesInSlice(mapSlice, paths[0])
log.Debugf("\tAppended child at %v for mapSlice %v\n", paths[0], mapSlice)
}
log.Debugf("\tchild.Value %v\n", child.Value)
remainingPaths := paths[1:]
child.Value = updatedChildValue(child.Value, remainingPaths, value)
for _, child := range children {
child.Value = updatedChildValue(child.Value, remainingPaths, value)
}
log.Debugf("\tReturning mapSlice %v\n", mapSlice)
return mapSlice
}
@@ -69,19 +87,26 @@ func updatedChildValue(child interface{}, remainingPaths []string, value interfa
if len(remainingPaths) == 0 {
return value
}
log.Debugf("updatedChildValue for child %v with path %v to set value %v", child, remainingPaths, value)
log.Debugf("type of child is %v", reflect.TypeOf(child))
_, nextIndexErr := strconv.ParseInt(remainingPaths[0], 10, 64)
if nextIndexErr != nil && remainingPaths[0] != "+" {
// must be a map
return writeMap(child, remainingPaths, value)
switch child := child.(type) {
case nil:
if remainingPaths[0] == "+" || remainingPaths[0] == "*" {
return writeArray(child, remainingPaths, value)
}
case []interface{}:
_, nextIndexErr := strconv.ParseInt(remainingPaths[0], 10, 64)
arrayCommand := nextIndexErr == nil || remainingPaths[0] == "+" || remainingPaths[0] == "*"
if arrayCommand {
return writeArray(child, remainingPaths, value)
}
}
// must be an array
return writeArray(child, remainingPaths, value)
return writeMap(child, remainingPaths, value)
}
func writeArray(context interface{}, paths []string, value interface{}) []interface{} {
log.Debugf("writeArray for %v for %v with value %v\n", paths, context, value)
log.Debugf("writeArray with path %v for %v to set value %v\n", paths, context, value)
array, _ := getArray(context)
if len(paths) == 0 {
@@ -91,10 +116,16 @@ func writeArray(context interface{}, paths []string, value interface{}) []interf
log.Debugf("\tarray %v\n", array)
rawIndex := paths[0]
remainingPaths := paths[1:]
var index int64
// the append array indicator
if rawIndex == "+" {
index = int64(len(array))
} else if rawIndex == "*" {
for index, oldChild := range array {
array[index] = updatedChildValue(oldChild, remainingPaths, value)
}
return array
} else {
index, _ = strconv.ParseInt(rawIndex, 10, 64) // nolint
// writeArray is only called by updatedChildValue which handles parsing the
@@ -108,23 +139,34 @@ func writeArray(context interface{}, paths []string, value interface{}) []interf
log.Debugf("\tcurrentChild %v\n", currentChild)
remainingPaths := paths[1:]
array[index] = updatedChildValue(currentChild, remainingPaths, value)
log.Debugf("\tReturning array %v\n", array)
return array
}
func readMap(context yaml.MapSlice, head string, tail []string) (interface{}, error) {
log.Debugf("readingMap %v with key %v\n", context, head)
if head == "*" {
return readMapSplat(context, tail)
}
var value interface{}
entry := entryInSlice(context, head)
if entry != nil {
value = entry.Value
entries := entriesInSlice(context, head)
if len(entries) == 1 {
return calculateValue(entries[0].Value, tail)
} else if len(entries) == 0 {
return nil, nil
}
return calculateValue(value, tail)
var errInIdx error
values := make([]interface{}, len(entries))
for idx, entry := range entries {
values[idx], errInIdx = calculateValue(entry.Value, tail)
if errInIdx != nil {
log.Errorf("Error updating index %v in %v", idx, context)
return nil, errInIdx
}
}
return values, nil
}
func readMapSplat(context yaml.MapSlice, tail []string) (interface{}, error) {
@@ -191,39 +233,47 @@ func calculateValue(value interface{}, tail []string) (interface{}, error) {
return value, nil
}
func deleteMap(context interface{}, paths []string) yaml.MapSlice {
func deleteMap(context interface{}, paths []string) (yaml.MapSlice, error) {
log.Debugf("deleteMap for %v for %v\n", paths, context)
mapSlice := getMapSlice(context)
if len(paths) == 0 {
return mapSlice
return mapSlice, nil
}
var found bool
var index int
var child yaml.MapItem
for index, child = range mapSlice {
if child.Key == paths[0] {
found = true
break
if matchesKey(paths[0], child.Key) {
log.Debugf("\tMatched [%v] with [%v] at index %v", paths[0], child.Key, index)
var badDelete error
mapSlice, badDelete = deleteEntryInMap(mapSlice, child, index, paths)
if badDelete != nil {
return nil, badDelete
}
}
}
if !found {
return mapSlice
}
return mapSlice, nil
}
func deleteEntryInMap(original yaml.MapSlice, child yaml.MapItem, index int, paths []string) (yaml.MapSlice, error) {
remainingPaths := paths[1:]
var newSlice yaml.MapSlice
if len(remainingPaths) > 0 {
newChild := yaml.MapItem{Key: child.Key}
newChild.Value = deleteChildValue(child.Value, remainingPaths)
var errorDeleting error
newChild.Value, errorDeleting = deleteChildValue(child.Value, remainingPaths)
if errorDeleting != nil {
return nil, errorDeleting
}
newSlice = make(yaml.MapSlice, len(mapSlice))
for i := range mapSlice {
item := mapSlice[i]
newSlice = make(yaml.MapSlice, len(original))
for i := range original {
item := original[i]
if i == index {
item = newChild
}
@@ -231,32 +281,43 @@ func deleteMap(context interface{}, paths []string) yaml.MapSlice {
}
} else {
// Delete item from slice at index
newSlice = append(mapSlice[:index], mapSlice[index+1:]...)
log.Debugf("\tDeleted item index %d from mapSlice", index)
newSlice = append(original[:index], original[index+1:]...)
log.Debugf("\tDeleted item index %d from original", index)
}
log.Debugf("\t\tlen: %d\tcap: %d\tslice: %v", len(mapSlice), cap(mapSlice), mapSlice)
log.Debugf("\tReturning mapSlice %v\n", mapSlice)
return newSlice
log.Debugf("\tReturning original %v\n", original)
return newSlice, nil
}
func deleteArray(context interface{}, paths []string, index int64) interface{} {
log.Debugf("deleteArray for %v for %v\n", paths, context)
array, ok := getArray(context)
if !ok {
// did not get an array
return context
func deleteArraySplat(array []interface{}, tail []string) (interface{}, error) {
log.Debugf("deleteArraySplat for %v for %v\n", tail, array)
var newArray = make([]interface{}, len(array))
for index, value := range array {
val, err := deleteChildValue(value, tail)
if err != nil {
return nil, err
}
newArray[index] = val
}
return newArray, nil
}
func deleteArray(array []interface{}, paths []string, index int64) (interface{}, error) {
log.Debugf("deleteArray for %v for %v\n", paths, array)
if index >= int64(len(array)) {
return array
return array, nil
}
remainingPaths := paths[1:]
if len(remainingPaths) > 0 {
// Recurse into the array element at index
array[index] = deleteMap(array[index], remainingPaths)
var errorDeleting error
array[index], errorDeleting = deleteMap(array[index], remainingPaths)
if errorDeleting != nil {
return nil, errorDeleting
}
} else {
// Delete the array element at index
array = append(array[:index], array[index+1:]...)
@@ -264,19 +325,25 @@ func deleteArray(context interface{}, paths []string, index int64) interface{} {
}
log.Debugf("\tReturning array: %v\n", array)
return array
return array, nil
}
func deleteChildValue(child interface{}, remainingPaths []string) interface{} {
func deleteChildValue(child interface{}, remainingPaths []string) (interface{}, error) {
log.Debugf("deleteChildValue for %v for %v\n", remainingPaths, child)
idx, nextIndexErr := strconv.ParseInt(remainingPaths[0], 10, 64)
if nextIndexErr != nil {
// must be a map
log.Debugf("\tdetected a map, invoking deleteMap\n")
var head = remainingPaths[0]
var tail = remainingPaths[1:]
switch child := child.(type) {
case yaml.MapSlice:
return deleteMap(child, remainingPaths)
case []interface{}:
if head == "*" {
return deleteArraySplat(child, tail)
}
index, err := strconv.ParseInt(head, 10, 64)
if err != nil {
return nil, fmt.Errorf("error accessing array: %v", err)
}
return deleteArray(child, remainingPaths, index)
}
log.Debugf("\tdetected an array, so traversing element with index %d\n", idx)
return deleteArray(child, remainingPaths, idx)
return child, nil
}

View File

@@ -4,8 +4,6 @@ import (
"fmt"
"sort"
"testing"
yaml "gopkg.in/mikefarah/yaml.v2"
)
func TestReadMap_simple(t *testing.T) {
@@ -18,18 +16,37 @@ b:
assertResult(t, 2, got)
}
func TestReadMap_numberKey(t *testing.T) {
var data = parseData(`
---
200: things
`)
got, _ := readMap(data, "200", []string{})
assertResult(t, "things", got)
}
func TestReadMap_splat(t *testing.T) {
var data = parseData(`
---
mapSplat:
item1: things
item2: whatever
otherThing: cat
`)
res, _ := readMap(data, "mapSplat", []string{"*"})
result := res.([]interface{})
var actual = []string{result[0].(string), result[1].(string)}
sort.Strings(actual)
assertResult(t, "[things whatever]", fmt.Sprintf("%v", actual))
assertResult(t, "[things whatever cat]", fmt.Sprintf("%v", res))
}
func TestReadMap_prefixSplat(t *testing.T) {
var data = parseData(`
---
mapSplat:
item1: things
item2: whatever
otherThing: cat
`)
res, _ := readMap(data, "mapSplat", []string{"item*"})
assertResult(t, "[things whatever]", fmt.Sprintf("%v", res))
}
func TestReadMap_deep_splat(t *testing.T) {
@@ -180,8 +197,7 @@ func TestWrite_really_simple(t *testing.T) {
`)
updated := writeMap(data, []string{"b"}, "4")
b := entryInSlice(updated, "b").Value
assertResult(t, "4", b)
assertResult(t, "[{b 4}]", fmt.Sprintf("%v", updated))
}
func TestWrite_simple(t *testing.T) {
@@ -191,9 +207,7 @@ b:
`)
updated := writeMap(data, []string{"b", "c"}, "4")
b := entryInSlice(updated, "b").Value.(yaml.MapSlice)
c := entryInSlice(b, "c").Value
assertResult(t, "4", c)
assertResult(t, "[{b [{c 4}]}]", fmt.Sprintf("%v", updated))
}
func TestWrite_new(t *testing.T) {
@@ -203,9 +217,7 @@ b:
`)
updated := writeMap(data, []string{"b", "d"}, "4")
b := entryInSlice(updated, "b").Value.(yaml.MapSlice)
d := entryInSlice(b, "d").Value
assertResult(t, "4", d)
assertResult(t, "[{b [{c 2} {d 4}]}]", fmt.Sprintf("%v", updated))
}
func TestWrite_new_deep(t *testing.T) {
@@ -215,8 +227,7 @@ b:
`)
updated := writeMap(data, []string{"b", "d", "f"}, "4")
got, _ := readMap(updated, "b", []string{"d", "f"})
assertResult(t, "4", got)
assertResult(t, "[{b [{c 2} {d [{f 4}]}]}]", fmt.Sprintf("%v", updated))
}
func TestWrite_array(t *testing.T) {
@@ -227,8 +238,7 @@ b:
updated := writeMap(data, []string{"b", "0"}, "bb")
b := entryInSlice(updated, "b").Value.([]interface{})
assertResult(t, "bb", b[0].(string))
assertResult(t, "[{b [bb]}]", fmt.Sprintf("%v", updated))
}
func TestWrite_new_array(t *testing.T) {
@@ -238,20 +248,19 @@ b:
`)
updated := writeMap(data, []string{"b", "0"}, "4")
got, _ := readMap(updated, "b", []string{"0"})
assertResult(t, "4", got)
assertResult(t, "[{b [{c 2} {0 4}]}]", fmt.Sprintf("%v", updated))
}
func TestWrite_new_array_deep(t *testing.T) {
var data = parseData(`
b:
c: 2
a: apple
`)
var expected = `b:
var expected = `a: apple
b:
- c: "4"`
updated := writeMap(data, []string{"b", "0", "c"}, "4")
updated := writeMap(data, []string{"b", "+", "c"}, "4")
got, _ := yamlToString(updated)
assertResult(t, expected, got)
}
@@ -261,10 +270,14 @@ func TestWrite_new_map_array_deep(t *testing.T) {
b:
c: 2
`)
var expected = `b:
c: 2
d:
- "4"`
updated := writeMap(data, []string{"b", "d", "0"}, "4")
got, _ := readMap(updated, "b", []string{"d", "0"})
assertResult(t, "4", got)
updated := writeMap(data, []string{"b", "d", "+"}, "4")
got, _ := yamlToString(updated)
assertResult(t, expected, got)
}
func TestWrite_add_to_array(t *testing.T) {
@@ -289,8 +302,7 @@ b:
`)
updated := writeMap(data, []string{"b"}, "4")
b := entryInSlice(updated, "b").Value
assertResult(t, "4", fmt.Sprintf("%v", b))
assertResult(t, "[{b 4}]", fmt.Sprintf("%v", updated))
}
func TestWriteMap_no_paths(t *testing.T) {
@@ -318,7 +330,7 @@ b: 456
b: 456
`)
result := deleteMap(data, []string{"a"})
result, _ := deleteMap(data, []string{"a"})
assertResult(t, fmt.Sprintf("%v", expected), fmt.Sprintf("%v", result))
}
@@ -327,7 +339,7 @@ func TestDelete_index_to_string(t *testing.T) {
var data = parseData(`
a: mystring
`)
result := deleteMap(data, []string{"a", "0"})
result, _ := deleteMap(data, []string{"a", "0"})
assertResult(t, fmt.Sprintf("%v", data), fmt.Sprintf("%v", result))
}
@@ -338,7 +350,7 @@ a: [3, 4]
var expected = parseData(`
a: [3]
`)
result := deleteMap(data, []string{"a", "1"})
result, _ := deleteMap(data, []string{"a", "1"})
assertResult(t, fmt.Sprintf("%v", expected), fmt.Sprintf("%v", result))
}
@@ -346,7 +358,7 @@ func TestDelete_list_index_beyond_bounds(t *testing.T) {
var data = parseData(`
a: [3, 4]
`)
result := deleteMap(data, []string{"a", "5"})
result, _ := deleteMap(data, []string{"a", "5"})
assertResult(t, fmt.Sprintf("%v", data), fmt.Sprintf("%v", result))
}
@@ -354,7 +366,7 @@ func TestDelete_list_index_out_of_bounds_by_1(t *testing.T) {
var data = parseData(`
a: [3, 4]
`)
result := deleteMap(data, []string{"a", "2"})
result, _ := deleteMap(data, []string{"a", "2"})
assertResult(t, fmt.Sprintf("%v", data), fmt.Sprintf("%v", result))
}
@@ -364,7 +376,7 @@ a: [3, 4]
b:
- name: test
`)
result := deleteMap(data, []string{})
result, _ := deleteMap(data, []string{})
assertResult(t, fmt.Sprintf("%v", data), fmt.Sprintf("%v", result))
}
@@ -382,6 +394,6 @@ b:
- name: john
value: test
`)
result := deleteMap(data, []string{"b", "0", "name"})
result, _ := deleteMap(data, []string{"b", "0", "name"})
assertResult(t, fmt.Sprintf("%v", expected), fmt.Sprintf("%v", result))
}

View File

@@ -2,7 +2,7 @@
<!DOCTYPE html>
<!doctype html>
<html lang="en" class="no-js">
<head>
@@ -32,7 +32,7 @@
<meta name="lang:search.tokenizer" content="[\s\-]+">
<link rel="shortcut icon" href="/assets/images/favicon.png">
<meta name="generator" content="mkdocs-1.0.4, mkdocs-material-3.1.0">
<meta name="generator" content="mkdocs-1.0.4, mkdocs-material-4.2.0">
@@ -40,12 +40,12 @@
<link rel="stylesheet" href="/assets/stylesheets/application.11e41852.css">
<link rel="stylesheet" href="/assets/stylesheets/application.750b69bd.css">
<script src="/assets/javascripts/modernizr.20ef595d.js"></script>
<script src="/assets/javascripts/modernizr.74668098.js"></script>
@@ -58,6 +58,9 @@
</head>
<body dir="ltr">
@@ -108,22 +111,19 @@
<div class="md-flex__cell md-flex__cell--stretch">
<div class="md-flex__ellipsis md-header-nav__title" data-md-component="title">
<span class="md-header-nav__topic">
Yq
</span>
<span class="md-header-nav__topic">
</span>
<span class="md-header-nav__topic">
Yq
</span>
<span class="md-header-nav__topic">
</span>
</div>
</div>
<div class="md-flex__cell md-flex__cell--shrink">
<label class="md-icon md-icon--search md-header-nav__button" for="__search"></label>
<label class="md-icon md-icon--search md-header-nav__button" for="__search"></label>
<div class="md-search" data-md-component="search" role="dialog">
<label class="md-search__overlay" for="__search"></label>
<div class="md-search__inner" role="search">
@@ -146,7 +146,6 @@
</div>
</div>
</div>
</div>
@@ -157,20 +156,18 @@
<a href="https://github.com/mikefarah/yq/" title="Go to repository" class="md-source" data-md-source="github">
<div class="md-source__icon">
<svg viewBox="0 0 24 24" width="24" height="24">
<use xlink:href="#__github" width="24" height="24"></use>
</svg>
</div>
<div class="md-source__repository">
mikefarah/yq
<a href="https://github.com/mikefarah/yq/" title="Go to repository" class="md-source" data-md-source="github">
<div class="md-source__icon">
<svg viewBox="0 0 24 24" width="24" height="24">
<use xlink:href="#__github" width="24" height="24"></use>
</svg>
</div>
</a>
<div class="md-source__repository">
mikefarah/yq
</div>
</a>
</div>
</div>
@@ -206,20 +203,18 @@
<a href="https://github.com/mikefarah/yq/" title="Go to repository" class="md-source" data-md-source="github">
<div class="md-source__icon">
<svg viewBox="0 0 24 24" width="24" height="24">
<use xlink:href="#__github" width="24" height="24"></use>
</svg>
</div>
<div class="md-source__repository">
mikefarah/yq
<a href="https://github.com/mikefarah/yq/" title="Go to repository" class="md-source" data-md-source="github">
<div class="md-source__icon">
<svg viewBox="0 0 24 24" width="24" height="24">
<use xlink:href="#__github" width="24" height="24"></use>
</svg>
</div>
</a>
<div class="md-source__repository">
mikefarah/yq
</div>
</a>
</div>
<ul class="md-nav__list" data-md-scrollfix>
@@ -357,7 +352,6 @@
Material for MkDocs</a>
</div>
<div class="md-footer-social">
<link rel="stylesheet" href="/assets/fonts/font-awesome.css">
@@ -367,20 +361,16 @@
</div>
</div>
</div>
</footer>
</div>
<script src="/assets/javascripts/application.9e1f3b71.js"></script>
<script src="/assets/javascripts/application.39abc4af.js"></script>
<script>app.initialize({version:"1.0.4",url:{base:"/"}})</script>
</body>
</html>

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

View File

@@ -0,0 +1 @@
!function(e,r){"function"==typeof define&&define.amd?define(r):"object"==typeof exports?module.exports=r():r()(e.lunr)}(this,function(){return function(m){if(void 0===m)throw new Error("Lunr is not present. Please include / require Lunr before this script.");if(void 0===m.stemmerSupport)throw new Error("Lunr stemmer support is not present. Please include / require Lunr stemmer support before this script.");var l="2"==m.version[0];m.ja=function(){this.pipeline.reset(),this.pipeline.add(m.ja.trimmer,m.ja.stopWordFilter,m.ja.stemmer),l?this.tokenizer=m.ja.tokenizer:(m.tokenizer&&(m.tokenizer=m.ja.tokenizer),this.tokenizerFn&&(this.tokenizerFn=m.ja.tokenizer))};var j=new m.TinySegmenter;m.ja.tokenizer=function(e){var r,t,i,n,o,s,p,a,u;if(!arguments.length||null==e||null==e)return[];if(Array.isArray(e))return e.map(function(e){return l?new m.Token(e.toLowerCase()):e.toLowerCase()});for(r=(t=e.toString().toLowerCase().replace(/^\s+/,"")).length-1;0<=r;r--)if(/\S/.test(t.charAt(r))){t=t.substring(0,r+1);break}for(o=[],i=t.length,p=a=0;a<=i;a++)if(s=a-p,t.charAt(a).match(/\s/)||a==i){if(0<s)for(n=j.segment(t.slice(p,a)).filter(function(e){return!!e}),u=p,r=0;r<n.length;r++)l?o.push(new m.Token(n[r],{position:[u,n[r].length],index:o.length})):o.push(n[r]),u+=n[r].length;p=a+1}return o},m.ja.stemmer=function(e){return e},m.Pipeline.registerFunction(m.ja.stemmer,"stemmer-ja"),m.ja.wordCharacters="一二三四五六七八九十百千万億兆一-龠々〆ヵヶぁ-んァ-ヴーア-ン゙a-zA-Z--0-9-",m.ja.trimmer=m.trimmerSupport.generateTrimmer(m.ja.wordCharacters),m.Pipeline.registerFunction(m.ja.trimmer,"trimmer-ja"),m.ja.stopWordFilter=m.generateStopWordFilter("これ それ あれ この その あの ここ そこ あそこ こちら どこ だれ なに なん 何 私 貴方 貴方方 我々 私達 あの人 あのかた 彼女 彼 です あります おります います は が の に を で え から まで より も どの と し それで しかし".split(" ")),m.Pipeline.registerFunction(m.ja.stopWordFilter,"stopWordFilter-ja"),m.jp=m.ja,m.Pipeline.registerFunction(m.jp.stemmer,"stemmer-jp"),m.Pipeline.registerFunction(m.jp.trimmer,"trimmer-jp"),m.Pipeline.registerFunction(m.jp.stopWordFilter,"stopWordFilter-jp")}});

View File

@@ -1 +1 @@
!function(e,r){"function"==typeof define&&define.amd?define(r):"object"==typeof exports?module.exports=r():r()(e.lunr)}(this,function(){return function(n){if(void 0===n)throw new Error("Lunr is not present. Please include / require Lunr before this script.");if(void 0===n.stemmerSupport)throw new Error("Lunr stemmer support is not present. Please include / require Lunr stemmer support before this script.");var i="2"==n.version[0];n.jp=function(){this.pipeline.reset(),this.pipeline.add(n.jp.stopWordFilter,n.jp.stemmer),i?this.tokenizer=n.jp.tokenizer:(n.tokenizer&&(n.tokenizer=n.jp.tokenizer),this.tokenizerFn&&(this.tokenizerFn=n.jp.tokenizer))};var o=new n.TinySegmenter;n.jp.tokenizer=function(e){if(!arguments.length||null==e||null==e)return[];if(Array.isArray(e))return e.map(function(e){return i?new n.Token(e.toLowerCase()):e.toLowerCase()});for(var r=e.toString().toLowerCase().replace(/^\s+/,""),t=r.length-1;0<=t;t--)if(/\S/.test(r.charAt(t))){r=r.substring(0,t+1);break}return o.segment(r).filter(function(e){return!!e}).map(function(e){return i?new n.Token(e):e})},n.jp.stemmer=function(e){return e},n.Pipeline.registerFunction(n.jp.stemmer,"stemmer-jp"),n.jp.wordCharacters="一二三四五六七八九十百千万億兆一-龠々〆ヵヶぁ-んァ-ヴーア-ン゙a-zA-Z--0-9-",n.jp.stopWordFilter=function(e){if(-1===n.jp.stopWordFilter.stopWords.indexOf(i?e.toString():e))return e},n.jp.stopWordFilter=n.generateStopWordFilter("これ それ あれ この その あの ここ そこ あそこ こちら どこ だれ なに なん 何 私 貴方 貴方方 我々 私達 あの人 あのかた 彼女 彼 です あります おります います は が の に を で え から まで より も どの と し それで しかし".split(" ")),n.Pipeline.registerFunction(n.jp.stopWordFilter,"stopWordFilter-jp")}});
module.exports=require("./lunr.ja");

File diff suppressed because one or more lines are too long

View File

@@ -0,0 +1 @@
!function(e,r){"function"==typeof define&&define.amd?define(r):"object"==typeof exports?module.exports=r():r()(e.lunr)}(this,function(){return function(t){if(void 0===t)throw new Error("Lunr is not present. Please include / require Lunr before this script.");if(void 0===t.stemmerSupport)throw new Error("Lunr stemmer support is not present. Please include / require Lunr stemmer support before this script.");var i="2"==t.version[0];t.th=function(){this.pipeline.reset(),this.pipeline.add(t.th.trimmer),i?this.tokenizer=t.th.tokenizer:(t.tokenizer&&(t.tokenizer=t.th.tokenizer),this.tokenizerFn&&(this.tokenizerFn=t.th.tokenizer))},t.th.wordCharacters="[฀-๿]",t.th.trimmer=t.trimmerSupport.generateTrimmer(t.th.wordCharacters),t.Pipeline.registerFunction(t.th.trimmer,"trimmer-th");var n=t.wordcut;n.init(),t.th.tokenizer=function(e){if(!arguments.length||null==e||null==e)return[];if(Array.isArray(e))return e.map(function(e){return i?new t.Token(e):e});var r=e.toString().replace(/^\s+/,"");return n.cut(r).split("|")}}});

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because one or more lines are too long

View File

@@ -2,7 +2,7 @@
<!DOCTYPE html>
<!doctype html>
<html lang="en" class="no-js">
<head>
@@ -32,7 +32,7 @@
<meta name="lang:search.tokenizer" content="[\s\-]+">
<link rel="shortcut icon" href="../assets/images/favicon.png">
<meta name="generator" content="mkdocs-1.0.4, mkdocs-material-3.1.0">
<meta name="generator" content="mkdocs-1.0.4, mkdocs-material-4.2.0">
@@ -40,12 +40,12 @@
<link rel="stylesheet" href="../assets/stylesheets/application.11e41852.css">
<link rel="stylesheet" href="../assets/stylesheets/application.750b69bd.css">
<script src="../assets/javascripts/modernizr.20ef595d.js"></script>
<script src="../assets/javascripts/modernizr.74668098.js"></script>
@@ -58,6 +58,9 @@
</head>
<body dir="ltr">
@@ -112,22 +115,19 @@
<div class="md-flex__cell md-flex__cell--stretch">
<div class="md-flex__ellipsis md-header-nav__title" data-md-component="title">
<span class="md-header-nav__topic">
Yq
</span>
<span class="md-header-nav__topic">
Convert
</span>
<span class="md-header-nav__topic">
Yq
</span>
<span class="md-header-nav__topic">
Convert
</span>
</div>
</div>
<div class="md-flex__cell md-flex__cell--shrink">
<label class="md-icon md-icon--search md-header-nav__button" for="__search"></label>
<label class="md-icon md-icon--search md-header-nav__button" for="__search"></label>
<div class="md-search" data-md-component="search" role="dialog">
<label class="md-search__overlay" for="__search"></label>
<div class="md-search__inner" role="search">
@@ -150,7 +150,6 @@
</div>
</div>
</div>
</div>
@@ -161,20 +160,18 @@
<a href="https://github.com/mikefarah/yq/" title="Go to repository" class="md-source" data-md-source="github">
<div class="md-source__icon">
<svg viewBox="0 0 24 24" width="24" height="24">
<use xlink:href="#__github" width="24" height="24"></use>
</svg>
</div>
<div class="md-source__repository">
mikefarah/yq
<a href="https://github.com/mikefarah/yq/" title="Go to repository" class="md-source" data-md-source="github">
<div class="md-source__icon">
<svg viewBox="0 0 24 24" width="24" height="24">
<use xlink:href="#__github" width="24" height="24"></use>
</svg>
</div>
</a>
<div class="md-source__repository">
mikefarah/yq
</div>
</a>
</div>
</div>
@@ -210,20 +207,18 @@
<a href="https://github.com/mikefarah/yq/" title="Go to repository" class="md-source" data-md-source="github">
<div class="md-source__icon">
<svg viewBox="0 0 24 24" width="24" height="24">
<use xlink:href="#__github" width="24" height="24"></use>
</svg>
</div>
<div class="md-source__repository">
mikefarah/yq
<a href="https://github.com/mikefarah/yq/" title="Go to repository" class="md-source" data-md-source="github">
<div class="md-source__icon">
<svg viewBox="0 0 24 24" width="24" height="24">
<use xlink:href="#__github" width="24" height="24"></use>
</svg>
</div>
</a>
<div class="md-source__repository">
mikefarah/yq
</div>
</a>
</div>
<ul class="md-nav__list" data-md-scrollfix>
@@ -514,7 +509,6 @@ b:
Material for MkDocs</a>
</div>
<div class="md-footer-social">
<link rel="stylesheet" href="../assets/fonts/font-awesome.css">
@@ -524,20 +518,16 @@ b:
</div>
</div>
</div>
</footer>
</div>
<script src="../assets/javascripts/application.9e1f3b71.js"></script>
<script src="../assets/javascripts/application.39abc4af.js"></script>
<script>app.initialize({version:"1.0.4",url:{base:".."}})</script>
</body>
</html>

View File

@@ -2,7 +2,7 @@
<!DOCTYPE html>
<!doctype html>
<html lang="en" class="no-js">
<head>
@@ -32,7 +32,7 @@
<meta name="lang:search.tokenizer" content="[\s\-]+">
<link rel="shortcut icon" href="../assets/images/favicon.png">
<meta name="generator" content="mkdocs-1.0.4, mkdocs-material-3.1.0">
<meta name="generator" content="mkdocs-1.0.4, mkdocs-material-4.2.0">
@@ -40,12 +40,12 @@
<link rel="stylesheet" href="../assets/stylesheets/application.11e41852.css">
<link rel="stylesheet" href="../assets/stylesheets/application.750b69bd.css">
<script src="../assets/javascripts/modernizr.20ef595d.js"></script>
<script src="../assets/javascripts/modernizr.74668098.js"></script>
@@ -58,6 +58,9 @@
</head>
<body dir="ltr">
@@ -112,22 +115,19 @@
<div class="md-flex__cell md-flex__cell--stretch">
<div class="md-flex__ellipsis md-header-nav__title" data-md-component="title">
<span class="md-header-nav__topic">
Yq
</span>
<span class="md-header-nav__topic">
Create
</span>
<span class="md-header-nav__topic">
Yq
</span>
<span class="md-header-nav__topic">
Create
</span>
</div>
</div>
<div class="md-flex__cell md-flex__cell--shrink">
<label class="md-icon md-icon--search md-header-nav__button" for="__search"></label>
<label class="md-icon md-icon--search md-header-nav__button" for="__search"></label>
<div class="md-search" data-md-component="search" role="dialog">
<label class="md-search__overlay" for="__search"></label>
<div class="md-search__inner" role="search">
@@ -150,7 +150,6 @@
</div>
</div>
</div>
</div>
@@ -161,20 +160,18 @@
<a href="https://github.com/mikefarah/yq/" title="Go to repository" class="md-source" data-md-source="github">
<div class="md-source__icon">
<svg viewBox="0 0 24 24" width="24" height="24">
<use xlink:href="#__github" width="24" height="24"></use>
</svg>
</div>
<div class="md-source__repository">
mikefarah/yq
<a href="https://github.com/mikefarah/yq/" title="Go to repository" class="md-source" data-md-source="github">
<div class="md-source__icon">
<svg viewBox="0 0 24 24" width="24" height="24">
<use xlink:href="#__github" width="24" height="24"></use>
</svg>
</div>
</a>
<div class="md-source__repository">
mikefarah/yq
</div>
</a>
</div>
</div>
@@ -210,20 +207,18 @@
<a href="https://github.com/mikefarah/yq/" title="Go to repository" class="md-source" data-md-source="github">
<div class="md-source__icon">
<svg viewBox="0 0 24 24" width="24" height="24">
<use xlink:href="#__github" width="24" height="24"></use>
</svg>
</div>
<div class="md-source__repository">
mikefarah/yq
<a href="https://github.com/mikefarah/yq/" title="Go to repository" class="md-source" data-md-source="github">
<div class="md-source__icon">
<svg viewBox="0 0 24 24" width="24" height="24">
<use xlink:href="#__github" width="24" height="24"></use>
</svg>
</div>
</a>
<div class="md-source__repository">
mikefarah/yq
</div>
</a>
</div>
<ul class="md-nav__list" data-md-scrollfix>
@@ -337,6 +332,13 @@
</li>
<li class="md-nav__item">
<a href="#keys-and-values-with-leading-dashes" title="Keys (and values) with leading dashes" class="md-nav__link">
Keys (and values) with leading dashes
</a>
</li>
@@ -411,6 +413,13 @@
</li>
<li class="md-nav__item">
<a href="#keys-and-values-with-leading-dashes" title="Keys (and values) with leading dashes" class="md-nav__link">
Keys (and values) with leading dashes
</a>
</li>
@@ -449,7 +458,7 @@
<p>Create scripts follow the same format as the update scripts.</p>
<p>Given a script create_instructions.yaml of:</p>
<pre><code class="yaml">b.c: 3
b.e[0].name: Howdy Partner
b.e[+].name: Howdy Partner
</code></pre>
<p>then</p>
@@ -481,6 +490,15 @@ b.e[0].name: Howdy Partner
<p>Any valid yaml key can be specified as part of a key lookup.</p>
<p>Note that the path is in quotes to avoid the square brackets being interpreted by your shell.</p>
<h3 id="keys-and-values-with-leading-dashes">Keys (and values) with leading dashes<a class="headerlink" href="#keys-and-values-with-leading-dashes" title="Permanent link">&para;</a></h3>
<p>If a key or value has leading dashes, yq won't know that you are passing a value as opposed to a flag (and you will get a 'bad flag syntax' error).</p>
<p>To fix that, you will need to tell it to stop processing flags by adding '--' after the last flag like so:</p>
<pre><code class="bash">yq n -t -- --key --value
</code></pre>
<p>Will result in</p>
<p><code>`
--key: --value</code></p>
@@ -544,7 +562,6 @@ b.e[0].name: Howdy Partner
Material for MkDocs</a>
</div>
<div class="md-footer-social">
<link rel="stylesheet" href="../assets/fonts/font-awesome.css">
@@ -554,20 +571,16 @@ b.e[0].name: Howdy Partner
</div>
</div>
</div>
</footer>
</div>
<script src="../assets/javascripts/application.9e1f3b71.js"></script>
<script src="../assets/javascripts/application.39abc4af.js"></script>
<script>app.initialize({version:"1.0.4",url:{base:".."}})</script>
</body>
</html>

View File

@@ -2,7 +2,7 @@
<!DOCTYPE html>
<!doctype html>
<html lang="en" class="no-js">
<head>
@@ -32,7 +32,7 @@
<meta name="lang:search.tokenizer" content="[\s\-]+">
<link rel="shortcut icon" href="../assets/images/favicon.png">
<meta name="generator" content="mkdocs-1.0.4, mkdocs-material-3.1.0">
<meta name="generator" content="mkdocs-1.0.4, mkdocs-material-4.2.0">
@@ -40,12 +40,12 @@
<link rel="stylesheet" href="../assets/stylesheets/application.11e41852.css">
<link rel="stylesheet" href="../assets/stylesheets/application.750b69bd.css">
<script src="../assets/javascripts/modernizr.20ef595d.js"></script>
<script src="../assets/javascripts/modernizr.74668098.js"></script>
@@ -58,6 +58,9 @@
</head>
<body dir="ltr">
@@ -112,22 +115,19 @@
<div class="md-flex__cell md-flex__cell--stretch">
<div class="md-flex__ellipsis md-header-nav__title" data-md-component="title">
<span class="md-header-nav__topic">
Yq
</span>
<span class="md-header-nav__topic">
Delete
</span>
<span class="md-header-nav__topic">
Yq
</span>
<span class="md-header-nav__topic">
Delete
</span>
</div>
</div>
<div class="md-flex__cell md-flex__cell--shrink">
<label class="md-icon md-icon--search md-header-nav__button" for="__search"></label>
<label class="md-icon md-icon--search md-header-nav__button" for="__search"></label>
<div class="md-search" data-md-component="search" role="dialog">
<label class="md-search__overlay" for="__search"></label>
<div class="md-search__inner" role="search">
@@ -150,7 +150,6 @@
</div>
</div>
</div>
</div>
@@ -161,20 +160,18 @@
<a href="https://github.com/mikefarah/yq/" title="Go to repository" class="md-source" data-md-source="github">
<div class="md-source__icon">
<svg viewBox="0 0 24 24" width="24" height="24">
<use xlink:href="#__github" width="24" height="24"></use>
</svg>
</div>
<div class="md-source__repository">
mikefarah/yq
<a href="https://github.com/mikefarah/yq/" title="Go to repository" class="md-source" data-md-source="github">
<div class="md-source__icon">
<svg viewBox="0 0 24 24" width="24" height="24">
<use xlink:href="#__github" width="24" height="24"></use>
</svg>
</div>
</a>
<div class="md-source__repository">
mikefarah/yq
</div>
</a>
</div>
</div>
@@ -210,20 +207,18 @@
<a href="https://github.com/mikefarah/yq/" title="Go to repository" class="md-source" data-md-source="github">
<div class="md-source__icon">
<svg viewBox="0 0 24 24" width="24" height="24">
<use xlink:href="#__github" width="24" height="24"></use>
</svg>
</div>
<div class="md-source__repository">
mikefarah/yq
<a href="https://github.com/mikefarah/yq/" title="Go to repository" class="md-source" data-md-source="github">
<div class="md-source__icon">
<svg viewBox="0 0 24 24" width="24" height="24">
<use xlink:href="#__github" width="24" height="24"></use>
</svg>
</div>
</a>
<div class="md-source__repository">
mikefarah/yq
</div>
</a>
</div>
<ul class="md-nav__list" data-md-scrollfix>
@@ -330,6 +325,27 @@
Deleting nodes in-place
</a>
</li>
<li class="md-nav__item">
<a href="#splat" title="Splat" class="md-nav__link">
Splat
</a>
</li>
<li class="md-nav__item">
<a href="#prefix-splat" title="Prefix Splat" class="md-nav__link">
Prefix Splat
</a>
</li>
<li class="md-nav__item">
<a href="#array-splat" title="Array Splat" class="md-nav__link">
Array Splat
</a>
</li>
<li class="md-nav__item">
@@ -353,6 +369,13 @@
</li>
<li class="md-nav__item">
<a href="#keys-and-values-with-leading-dashes" title="Keys (and values) with leading dashes" class="md-nav__link">
Keys (and values) with leading dashes
</a>
</li>
@@ -444,6 +467,27 @@
Deleting nodes in-place
</a>
</li>
<li class="md-nav__item">
<a href="#splat" title="Splat" class="md-nav__link">
Splat
</a>
</li>
<li class="md-nav__item">
<a href="#prefix-splat" title="Prefix Splat" class="md-nav__link">
Prefix Splat
</a>
</li>
<li class="md-nav__item">
<a href="#array-splat" title="Array Splat" class="md-nav__link">
Array Splat
</a>
</li>
<li class="md-nav__item">
@@ -467,6 +511,13 @@
</li>
<li class="md-nav__item">
<a href="#keys-and-values-with-leading-dashes" title="Keys (and values) with leading dashes" class="md-nav__link">
Keys (and values) with leading dashes
</a>
</li>
@@ -543,6 +594,91 @@
</code></pre>
<p>will update the sample.yaml file so that the 'c' node is deleted</p>
<h3 id="splat">Splat<a class="headerlink" href="#splat" title="Permanent link">&para;</a></h3>
<p>Given a sample.yaml file of:</p>
<pre><code class="yaml">---
bob:
item1:
cats: bananas
dogs: woof
item2:
cats: apples
dogs: woof2
thing:
cats: oranges
dogs: woof3
</code></pre>
<p>then</p>
<pre><code class="bash">yq d sample.yaml bob.*.cats
</code></pre>
<p>will output:</p>
<pre><code class="yaml">---
bob:
item1:
dogs: woof
item2:
dogs: woof2
thing:
dogs: woof3
</code></pre>
<h3 id="prefix-splat">Prefix Splat<a class="headerlink" href="#prefix-splat" title="Permanent link">&para;</a></h3>
<p>Given a sample.yaml file of:</p>
<pre><code class="yaml">---
bob:
item1:
cats: bananas
dogs: woof
item2:
cats: apples
dogs: woof2
thing:
cats: oranges
dogs: woof3
</code></pre>
<p>then</p>
<pre><code class="bash">yq d sample.yaml bob.item*.cats
</code></pre>
<p>will output:</p>
<pre><code class="yaml">---
bob:
item1:
dogs: woof
item2:
dogs: woof2
thing:
cats: oranges
dogs: woof3
</code></pre>
<h3 id="array-splat">Array Splat<a class="headerlink" href="#array-splat" title="Permanent link">&para;</a></h3>
<p>Given a sample.yaml file of:</p>
<pre><code class="yaml">---
bob:
- cats: bananas
dogs: woof
- cats: apples
dogs: woof2
- cats: oranges
dogs: woof3
</code></pre>
<p>then</p>
<pre><code class="bash">yq d sample.yaml bob.[*].cats
</code></pre>
<p>will output:</p>
<pre><code class="yaml">---
bob:
- dogs: woof
- dogs: woof2
- dogs: woof3
</code></pre>
<h3 id="multiple-documents-delete-from-single-document">Multiple Documents - delete from single document<a class="headerlink" href="#multiple-documents-delete-from-single-document" title="Permanent link">&para;</a></h3>
<p>Given a sample.yaml file of:</p>
<pre><code class="yaml">something: else
@@ -601,6 +737,15 @@ b:
<p>Any valid yaml key can be specified as part of a key lookup.</p>
<p>Note that the path is in quotes to avoid the square brackets being interpreted by your shell.</p>
<h3 id="keys-and-values-with-leading-dashes">Keys (and values) with leading dashes<a class="headerlink" href="#keys-and-values-with-leading-dashes" title="Permanent link">&para;</a></h3>
<p>If a key or value has leading dashes, yq won't know that you are passing a value as opposed to a flag (and you will get a 'bad flag syntax' error).</p>
<p>To fix that, you will need to tell it to stop processing flags by adding '--' after the last flag like so:</p>
<pre><code class="bash">yq n -t -- --key --value
</code></pre>
<p>Will result in</p>
<p><code>`
--key: --value</code></p>
@@ -664,7 +809,6 @@ b:
Material for MkDocs</a>
</div>
<div class="md-footer-social">
<link rel="stylesheet" href="../assets/fonts/font-awesome.css">
@@ -674,20 +818,16 @@ b:
</div>
</div>
</div>
</footer>
</div>
<script src="../assets/javascripts/application.9e1f3b71.js"></script>
<script src="../assets/javascripts/application.39abc4af.js"></script>
<script>app.initialize({version:"1.0.4",url:{base:".."}})</script>
</body>
</html>

View File

@@ -2,7 +2,7 @@
<!DOCTYPE html>
<!doctype html>
<html lang="en" class="no-js">
<head>
@@ -32,7 +32,7 @@
<meta name="lang:search.tokenizer" content="[\s\-]+">
<link rel="shortcut icon" href="assets/images/favicon.png">
<meta name="generator" content="mkdocs-1.0.4, mkdocs-material-3.1.0">
<meta name="generator" content="mkdocs-1.0.4, mkdocs-material-4.2.0">
@@ -40,12 +40,12 @@
<link rel="stylesheet" href="assets/stylesheets/application.11e41852.css">
<link rel="stylesheet" href="assets/stylesheets/application.750b69bd.css">
<script src="assets/javascripts/modernizr.20ef595d.js"></script>
<script src="assets/javascripts/modernizr.74668098.js"></script>
@@ -58,6 +58,9 @@
</head>
<body dir="ltr">
@@ -112,22 +115,19 @@
<div class="md-flex__cell md-flex__cell--stretch">
<div class="md-flex__ellipsis md-header-nav__title" data-md-component="title">
<span class="md-header-nav__topic">
Yq
</span>
<span class="md-header-nav__topic">
Install
</span>
<span class="md-header-nav__topic">
Yq
</span>
<span class="md-header-nav__topic">
Install
</span>
</div>
</div>
<div class="md-flex__cell md-flex__cell--shrink">
<label class="md-icon md-icon--search md-header-nav__button" for="__search"></label>
<label class="md-icon md-icon--search md-header-nav__button" for="__search"></label>
<div class="md-search" data-md-component="search" role="dialog">
<label class="md-search__overlay" for="__search"></label>
<div class="md-search__inner" role="search">
@@ -150,7 +150,6 @@
</div>
</div>
</div>
</div>
@@ -161,20 +160,18 @@
<a href="https://github.com/mikefarah/yq/" title="Go to repository" class="md-source" data-md-source="github">
<div class="md-source__icon">
<svg viewBox="0 0 24 24" width="24" height="24">
<use xlink:href="#__github" width="24" height="24"></use>
</svg>
</div>
<div class="md-source__repository">
mikefarah/yq
<a href="https://github.com/mikefarah/yq/" title="Go to repository" class="md-source" data-md-source="github">
<div class="md-source__icon">
<svg viewBox="0 0 24 24" width="24" height="24">
<use xlink:href="#__github" width="24" height="24"></use>
</svg>
</div>
</a>
<div class="md-source__repository">
mikefarah/yq
</div>
</a>
</div>
</div>
@@ -210,20 +207,18 @@
<a href="https://github.com/mikefarah/yq/" title="Go to repository" class="md-source" data-md-source="github">
<div class="md-source__icon">
<svg viewBox="0 0 24 24" width="24" height="24">
<use xlink:href="#__github" width="24" height="24"></use>
</svg>
</div>
<div class="md-source__repository">
mikefarah/yq
<a href="https://github.com/mikefarah/yq/" title="Go to repository" class="md-source" data-md-source="github">
<div class="md-source__icon">
<svg viewBox="0 0 24 24" width="24" height="24">
<use xlink:href="#__github" width="24" height="24"></use>
</svg>
</div>
</a>
<div class="md-source__repository">
mikefarah/yq
</div>
</a>
</div>
<ul class="md-nav__list" data-md-scrollfix>
@@ -480,7 +475,6 @@ sudo apt install yq -y
Material for MkDocs</a>
</div>
<div class="md-footer-social">
<link rel="stylesheet" href="assets/fonts/font-awesome.css">
@@ -490,20 +484,16 @@ sudo apt install yq -y
</div>
</div>
</div>
</footer>
</div>
<script src="assets/javascripts/application.9e1f3b71.js"></script>
<script src="assets/javascripts/application.39abc4af.js"></script>
<script>app.initialize({version:"1.0.4",url:{base:"."}})</script>
</body>
</html>

View File

@@ -2,7 +2,7 @@
<!DOCTYPE html>
<!doctype html>
<html lang="en" class="no-js">
<head>
@@ -32,7 +32,7 @@
<meta name="lang:search.tokenizer" content="[\s\-]+">
<link rel="shortcut icon" href="../assets/images/favicon.png">
<meta name="generator" content="mkdocs-1.0.4, mkdocs-material-3.1.0">
<meta name="generator" content="mkdocs-1.0.4, mkdocs-material-4.2.0">
@@ -40,12 +40,12 @@
<link rel="stylesheet" href="../assets/stylesheets/application.11e41852.css">
<link rel="stylesheet" href="../assets/stylesheets/application.750b69bd.css">
<script src="../assets/javascripts/modernizr.20ef595d.js"></script>
<script src="../assets/javascripts/modernizr.74668098.js"></script>
@@ -58,6 +58,9 @@
</head>
<body dir="ltr">
@@ -112,22 +115,19 @@
<div class="md-flex__cell md-flex__cell--stretch">
<div class="md-flex__ellipsis md-header-nav__title" data-md-component="title">
<span class="md-header-nav__topic">
Yq
</span>
<span class="md-header-nav__topic">
Merge
</span>
<span class="md-header-nav__topic">
Yq
</span>
<span class="md-header-nav__topic">
Merge
</span>
</div>
</div>
<div class="md-flex__cell md-flex__cell--shrink">
<label class="md-icon md-icon--search md-header-nav__button" for="__search"></label>
<label class="md-icon md-icon--search md-header-nav__button" for="__search"></label>
<div class="md-search" data-md-component="search" role="dialog">
<label class="md-search__overlay" for="__search"></label>
<div class="md-search__inner" role="search">
@@ -150,7 +150,6 @@
</div>
</div>
</div>
</div>
@@ -161,20 +160,18 @@
<a href="https://github.com/mikefarah/yq/" title="Go to repository" class="md-source" data-md-source="github">
<div class="md-source__icon">
<svg viewBox="0 0 24 24" width="24" height="24">
<use xlink:href="#__github" width="24" height="24"></use>
</svg>
</div>
<div class="md-source__repository">
mikefarah/yq
<a href="https://github.com/mikefarah/yq/" title="Go to repository" class="md-source" data-md-source="github">
<div class="md-source__icon">
<svg viewBox="0 0 24 24" width="24" height="24">
<use xlink:href="#__github" width="24" height="24"></use>
</svg>
</div>
</a>
<div class="md-source__repository">
mikefarah/yq
</div>
</a>
</div>
</div>
@@ -210,20 +207,18 @@
<a href="https://github.com/mikefarah/yq/" title="Go to repository" class="md-source" data-md-source="github">
<div class="md-source__icon">
<svg viewBox="0 0 24 24" width="24" height="24">
<use xlink:href="#__github" width="24" height="24"></use>
</svg>
</div>
<div class="md-source__repository">
mikefarah/yq
<a href="https://github.com/mikefarah/yq/" title="Go to repository" class="md-source" data-md-source="github">
<div class="md-source__icon">
<svg viewBox="0 0 24 24" width="24" height="24">
<use xlink:href="#__github" width="24" height="24"></use>
</svg>
</div>
</a>
<div class="md-source__repository">
mikefarah/yq
</div>
</a>
</div>
<ul class="md-nav__list" data-md-scrollfix>
@@ -711,7 +706,6 @@ b: dog
Material for MkDocs</a>
</div>
<div class="md-footer-social">
<link rel="stylesheet" href="../assets/fonts/font-awesome.css">
@@ -721,20 +715,16 @@ b: dog
</div>
</div>
</div>
</footer>
</div>
<script src="../assets/javascripts/application.9e1f3b71.js"></script>
<script src="../assets/javascripts/application.39abc4af.js"></script>
<script>app.initialize({version:"1.0.4",url:{base:".."}})</script>
</body>
</html>

View File

@@ -2,7 +2,7 @@
<!DOCTYPE html>
<!doctype html>
<html lang="en" class="no-js">
<head>
@@ -32,7 +32,7 @@
<meta name="lang:search.tokenizer" content="[\s\-]+">
<link rel="shortcut icon" href="../assets/images/favicon.png">
<meta name="generator" content="mkdocs-1.0.4, mkdocs-material-3.1.0">
<meta name="generator" content="mkdocs-1.0.4, mkdocs-material-4.2.0">
@@ -40,12 +40,12 @@
<link rel="stylesheet" href="../assets/stylesheets/application.11e41852.css">
<link rel="stylesheet" href="../assets/stylesheets/application.750b69bd.css">
<script src="../assets/javascripts/modernizr.20ef595d.js"></script>
<script src="../assets/javascripts/modernizr.74668098.js"></script>
@@ -58,6 +58,9 @@
</head>
<body dir="ltr">
@@ -112,22 +115,19 @@
<div class="md-flex__cell md-flex__cell--stretch">
<div class="md-flex__ellipsis md-header-nav__title" data-md-component="title">
<span class="md-header-nav__topic">
Yq
</span>
<span class="md-header-nav__topic">
Prefix
</span>
<span class="md-header-nav__topic">
Yq
</span>
<span class="md-header-nav__topic">
Prefix
</span>
</div>
</div>
<div class="md-flex__cell md-flex__cell--shrink">
<label class="md-icon md-icon--search md-header-nav__button" for="__search"></label>
<label class="md-icon md-icon--search md-header-nav__button" for="__search"></label>
<div class="md-search" data-md-component="search" role="dialog">
<label class="md-search__overlay" for="__search"></label>
<div class="md-search__inner" role="search">
@@ -150,7 +150,6 @@
</div>
</div>
</div>
</div>
@@ -161,20 +160,18 @@
<a href="https://github.com/mikefarah/yq/" title="Go to repository" class="md-source" data-md-source="github">
<div class="md-source__icon">
<svg viewBox="0 0 24 24" width="24" height="24">
<use xlink:href="#__github" width="24" height="24"></use>
</svg>
</div>
<div class="md-source__repository">
mikefarah/yq
<a href="https://github.com/mikefarah/yq/" title="Go to repository" class="md-source" data-md-source="github">
<div class="md-source__icon">
<svg viewBox="0 0 24 24" width="24" height="24">
<use xlink:href="#__github" width="24" height="24"></use>
</svg>
</div>
</a>
<div class="md-source__repository">
mikefarah/yq
</div>
</a>
</div>
</div>
@@ -210,20 +207,18 @@
<a href="https://github.com/mikefarah/yq/" title="Go to repository" class="md-source" data-md-source="github">
<div class="md-source__icon">
<svg viewBox="0 0 24 24" width="24" height="24">
<use xlink:href="#__github" width="24" height="24"></use>
</svg>
</div>
<div class="md-source__repository">
mikefarah/yq
<a href="https://github.com/mikefarah/yq/" title="Go to repository" class="md-source" data-md-source="github">
<div class="md-source__icon">
<svg viewBox="0 0 24 24" width="24" height="24">
<use xlink:href="#__github" width="24" height="24"></use>
</svg>
</div>
</a>
<div class="md-source__repository">
mikefarah/yq
</div>
</a>
</div>
<ul class="md-nav__list" data-md-scrollfix>
@@ -612,7 +607,6 @@ c:
Material for MkDocs</a>
</div>
<div class="md-footer-social">
<link rel="stylesheet" href="../assets/fonts/font-awesome.css">
@@ -622,20 +616,16 @@ c:
</div>
</div>
</div>
</footer>
</div>
<script src="../assets/javascripts/application.9e1f3b71.js"></script>
<script src="../assets/javascripts/application.39abc4af.js"></script>
<script>app.initialize({version:"1.0.4",url:{base:".."}})</script>
</body>
</html>

View File

@@ -2,7 +2,7 @@
<!DOCTYPE html>
<!doctype html>
<html lang="en" class="no-js">
<head>
@@ -32,7 +32,7 @@
<meta name="lang:search.tokenizer" content="[\s\-]+">
<link rel="shortcut icon" href="../assets/images/favicon.png">
<meta name="generator" content="mkdocs-1.0.4, mkdocs-material-3.1.0">
<meta name="generator" content="mkdocs-1.0.4, mkdocs-material-4.2.0">
@@ -40,12 +40,12 @@
<link rel="stylesheet" href="../assets/stylesheets/application.11e41852.css">
<link rel="stylesheet" href="../assets/stylesheets/application.750b69bd.css">
<script src="../assets/javascripts/modernizr.20ef595d.js"></script>
<script src="../assets/javascripts/modernizr.74668098.js"></script>
@@ -58,6 +58,9 @@
</head>
<body dir="ltr">
@@ -112,22 +115,19 @@
<div class="md-flex__cell md-flex__cell--stretch">
<div class="md-flex__ellipsis md-header-nav__title" data-md-component="title">
<span class="md-header-nav__topic">
Yq
</span>
<span class="md-header-nav__topic">
Read
</span>
<span class="md-header-nav__topic">
Yq
</span>
<span class="md-header-nav__topic">
Read
</span>
</div>
</div>
<div class="md-flex__cell md-flex__cell--shrink">
<label class="md-icon md-icon--search md-header-nav__button" for="__search"></label>
<label class="md-icon md-icon--search md-header-nav__button" for="__search"></label>
<div class="md-search" data-md-component="search" role="dialog">
<label class="md-search__overlay" for="__search"></label>
<div class="md-search__inner" role="search">
@@ -150,7 +150,6 @@
</div>
</div>
</div>
</div>
@@ -161,20 +160,18 @@
<a href="https://github.com/mikefarah/yq/" title="Go to repository" class="md-source" data-md-source="github">
<div class="md-source__icon">
<svg viewBox="0 0 24 24" width="24" height="24">
<use xlink:href="#__github" width="24" height="24"></use>
</svg>
</div>
<div class="md-source__repository">
mikefarah/yq
<a href="https://github.com/mikefarah/yq/" title="Go to repository" class="md-source" data-md-source="github">
<div class="md-source__icon">
<svg viewBox="0 0 24 24" width="24" height="24">
<use xlink:href="#__github" width="24" height="24"></use>
</svg>
</div>
</a>
<div class="md-source__repository">
mikefarah/yq
</div>
</a>
</div>
</div>
@@ -210,20 +207,18 @@
<a href="https://github.com/mikefarah/yq/" title="Go to repository" class="md-source" data-md-source="github">
<div class="md-source__icon">
<svg viewBox="0 0 24 24" width="24" height="24">
<use xlink:href="#__github" width="24" height="24"></use>
</svg>
</div>
<div class="md-source__repository">
mikefarah/yq
<a href="https://github.com/mikefarah/yq/" title="Go to repository" class="md-source" data-md-source="github">
<div class="md-source__icon">
<svg viewBox="0 0 24 24" width="24" height="24">
<use xlink:href="#__github" width="24" height="24"></use>
</svg>
</div>
</a>
<div class="md-source__repository">
mikefarah/yq
</div>
</a>
</div>
<ul class="md-nav__list" data-md-scrollfix>
@@ -287,6 +282,13 @@
Splat
</a>
</li>
<li class="md-nav__item">
<a href="#prefix-splat" title="Prefix Splat" class="md-nav__link">
Prefix Splat
</a>
</li>
<li class="md-nav__item">
@@ -324,6 +326,13 @@
</li>
<li class="md-nav__item">
<a href="#keys-and-values-with-leading-dashes" title="Keys (and values) with leading dashes" class="md-nav__link">
Keys (and values) with leading dashes
</a>
</li>
@@ -444,6 +453,13 @@
Splat
</a>
</li>
<li class="md-nav__item">
<a href="#prefix-splat" title="Prefix Splat" class="md-nav__link">
Prefix Splat
</a>
</li>
<li class="md-nav__item">
@@ -481,6 +497,13 @@
</li>
<li class="md-nav__item">
<a href="#keys-and-values-with-leading-dashes" title="Keys (and values) with leading dashes" class="md-nav__link">
Keys (and values) with leading dashes
</a>
</li>
@@ -531,12 +554,36 @@ bob:
cats: bananas
item2:
cats: apples
thing:
cats: oranges
</code></pre>
<p>then</p>
<pre><code class="bash">yq r sample.yaml bob.*.cats
</code></pre>
<p>will output</p>
<pre><code class="yaml">- bananas
- apples
- oranges
</code></pre>
<h3 id="prefix-splat">Prefix Splat<a class="headerlink" href="#prefix-splat" title="Permanent link">&para;</a></h3>
<p>Given a sample.yaml file of:</p>
<pre><code class="yaml">---
bob:
item1:
cats: bananas
item2:
cats: apples
thing:
cats: oranges
</code></pre>
<p>then</p>
<pre><code class="bash">yq r sample.yaml bob.item*.cats
</code></pre>
<p>will output</p>
<pre><code class="yaml">- bananas
- apples
@@ -629,6 +676,15 @@ e.g.: given a sample file of</p>
<p>Any valid yaml key can be specified as part of a key lookup.</p>
<p>Note that the path is in quotes to avoid the square brackets being interpreted by your shell.</p>
<h3 id="keys-and-values-with-leading-dashes">Keys (and values) with leading dashes<a class="headerlink" href="#keys-and-values-with-leading-dashes" title="Permanent link">&para;</a></h3>
<p>If a key or value has leading dashes, yq won't know that you are passing a value as opposed to a flag (and you will get a 'bad flag syntax' error).</p>
<p>To fix that, you will need to tell it to stop processing flags by adding '--' after the last flag like so:</p>
<pre><code class="bash">yq n -t -- --key --value
</code></pre>
<p>Will result in</p>
<p><code>`
--key: --value</code></p>
@@ -692,7 +748,6 @@ e.g.: given a sample file of</p>
Material for MkDocs</a>
</div>
<div class="md-footer-social">
<link rel="stylesheet" href="../assets/fonts/font-awesome.css">
@@ -702,20 +757,16 @@ e.g.: given a sample file of</p>
</div>
</div>
</div>
</footer>
</div>
<script src="../assets/javascripts/application.9e1f3b71.js"></script>
<script src="../assets/javascripts/application.39abc4af.js"></script>
<script>app.initialize({version:"1.0.4",url:{base:".."}})</script>
</body>
</html>

File diff suppressed because one or more lines are too long

View File

@@ -2,42 +2,42 @@
<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">
<url>
<loc>None</loc>
<lastmod>2018-11-19</lastmod>
<lastmod>2019-05-16</lastmod>
<changefreq>daily</changefreq>
</url>
<url>
<loc>None</loc>
<lastmod>2018-11-19</lastmod>
<lastmod>2019-05-16</lastmod>
<changefreq>daily</changefreq>
</url>
<url>
<loc>None</loc>
<lastmod>2018-11-19</lastmod>
<lastmod>2019-05-16</lastmod>
<changefreq>daily</changefreq>
</url>
<url>
<loc>None</loc>
<lastmod>2018-11-19</lastmod>
<lastmod>2019-05-16</lastmod>
<changefreq>daily</changefreq>
</url>
<url>
<loc>None</loc>
<lastmod>2018-11-19</lastmod>
<lastmod>2019-05-16</lastmod>
<changefreq>daily</changefreq>
</url>
<url>
<loc>None</loc>
<lastmod>2018-11-19</lastmod>
<lastmod>2019-05-16</lastmod>
<changefreq>daily</changefreq>
</url>
<url>
<loc>None</loc>
<lastmod>2018-11-19</lastmod>
<lastmod>2019-05-16</lastmod>
<changefreq>daily</changefreq>
</url>
<url>
<loc>None</loc>
<lastmod>2018-11-19</lastmod>
<lastmod>2019-05-16</lastmod>
<changefreq>daily</changefreq>
</url>
</urlset>

Binary file not shown.

View File

@@ -2,7 +2,7 @@
<!DOCTYPE html>
<!doctype html>
<html lang="en" class="no-js">
<head>
@@ -32,20 +32,20 @@
<meta name="lang:search.tokenizer" content="[\s\-]+">
<link rel="shortcut icon" href="../../assets/images/favicon.png">
<meta name="generator" content="mkdocs-1.0.4, mkdocs-material-3.1.0">
<meta name="generator" content="mkdocs-1.0.4, mkdocs-material-4.2.0">
<title>Keys with dots - Yq</title>
<title>Niche - Yq</title>
<link rel="stylesheet" href="../../assets/stylesheets/application.11e41852.css">
<link rel="stylesheet" href="../../assets/stylesheets/application.750b69bd.css">
<script src="../../assets/javascripts/modernizr.20ef595d.js"></script>
<script src="../../assets/javascripts/modernizr.74668098.js"></script>
@@ -58,6 +58,9 @@
</head>
<body dir="ltr">
@@ -112,22 +115,19 @@
<div class="md-flex__cell md-flex__cell--stretch">
<div class="md-flex__ellipsis md-header-nav__title" data-md-component="title">
<span class="md-header-nav__topic">
Yq
</span>
<span class="md-header-nav__topic">
Keys with dots
</span>
<span class="md-header-nav__topic">
Yq
</span>
<span class="md-header-nav__topic">
Niche
</span>
</div>
</div>
<div class="md-flex__cell md-flex__cell--shrink">
<label class="md-icon md-icon--search md-header-nav__button" for="__search"></label>
<label class="md-icon md-icon--search md-header-nav__button" for="__search"></label>
<div class="md-search" data-md-component="search" role="dialog">
<label class="md-search__overlay" for="__search"></label>
<div class="md-search__inner" role="search">
@@ -150,7 +150,6 @@
</div>
</div>
</div>
</div>
@@ -161,20 +160,18 @@
<a href="https://github.com/mikefarah/yq/" title="Go to repository" class="md-source" data-md-source="github">
<div class="md-source__icon">
<svg viewBox="0 0 24 24" width="24" height="24">
<use xlink:href="#__github" width="24" height="24"></use>
</svg>
</div>
<div class="md-source__repository">
mikefarah/yq
<a href="https://github.com/mikefarah/yq/" title="Go to repository" class="md-source" data-md-source="github">
<div class="md-source__icon">
<svg viewBox="0 0 24 24" width="24" height="24">
<use xlink:href="#__github" width="24" height="24"></use>
</svg>
</div>
</a>
<div class="md-source__repository">
mikefarah/yq
</div>
</a>
</div>
</div>
@@ -210,20 +207,18 @@
<a href="https://github.com/mikefarah/yq/" title="Go to repository" class="md-source" data-md-source="github">
<div class="md-source__icon">
<svg viewBox="0 0 24 24" width="24" height="24">
<use xlink:href="#__github" width="24" height="24"></use>
</svg>
</div>
<div class="md-source__repository">
mikefarah/yq
<a href="https://github.com/mikefarah/yq/" title="Go to repository" class="md-source" data-md-source="github">
<div class="md-source__icon">
<svg viewBox="0 0 24 24" width="24" height="24">
<use xlink:href="#__github" width="24" height="24"></use>
</svg>
</div>
</a>
<div class="md-source__repository">
mikefarah/yq
</div>
</a>
</div>
<ul class="md-nav__list" data-md-scrollfix>
@@ -349,6 +344,13 @@
</li>
<li class="md-nav__item">
<a href="#keys-and-values-with-leading-dashes" title="Keys (and values) with leading dashes" class="md-nav__link">
Keys (and values) with leading dashes
</a>
</li>
@@ -365,10 +367,10 @@
<article class="md-content__inner md-typeset">
<a href="https://github.com/mikefarah/yq/edit/master/docs/snippets/keys_with_dots.md" title="Edit this page" class="md-icon md-content__icon">&#xE3C9;</a>
<a href="https://github.com/mikefarah/yq/edit/master/docs/snippets/niche.md" title="Edit this page" class="md-icon md-content__icon">&#xE3C9;</a>
<h1>Keys with dots</h1>
<h1>Niche</h1>
<h3 id="keys-with-dots">Keys with dots<a class="headerlink" href="#keys-with-dots" title="Permanent link">&para;</a></h3>
<p>When specifying a key that has a dot use key lookup indicator.</p>
@@ -384,6 +386,15 @@
<p>Any valid yaml key can be specified as part of a key lookup.</p>
<p>Note that the path is in quotes to avoid the square brackets being interpreted by your shell.</p>
<h3 id="keys-and-values-with-leading-dashes">Keys (and values) with leading dashes<a class="headerlink" href="#keys-and-values-with-leading-dashes" title="Permanent link">&para;</a></h3>
<p>If a key or value has leading dashes, yq won't know that you are passing a value as opposed to a flag (and you will get a 'bad flag syntax' error).</p>
<p>To fix that, you will need to tell it to stop processing flags by adding '--' after the last flag like so:</p>
<pre><code class="bash">yq n -t -- --key --value
</code></pre>
<p>Will result in</p>
<pre><code>--key: --value
</code></pre>
@@ -412,7 +423,6 @@
Material for MkDocs</a>
</div>
<div class="md-footer-social">
<link rel="stylesheet" href="../../assets/fonts/font-awesome.css">
@@ -422,20 +432,16 @@
</div>
</div>
</div>
</footer>
</div>
<script src="../../assets/javascripts/application.9e1f3b71.js"></script>
<script src="../../assets/javascripts/application.39abc4af.js"></script>
<script>app.initialize({version:"1.0.4",url:{base:"../.."}})</script>
</body>
</html>

View File

@@ -2,7 +2,7 @@
<!DOCTYPE html>
<!doctype html>
<html lang="en" class="no-js">
<head>
@@ -32,7 +32,7 @@
<meta name="lang:search.tokenizer" content="[\s\-]+">
<link rel="shortcut icon" href="../../assets/images/favicon.png">
<meta name="generator" content="mkdocs-1.0.4, mkdocs-material-3.1.0">
<meta name="generator" content="mkdocs-1.0.4, mkdocs-material-4.2.0">
@@ -40,12 +40,12 @@
<link rel="stylesheet" href="../../assets/stylesheets/application.11e41852.css">
<link rel="stylesheet" href="../../assets/stylesheets/application.750b69bd.css">
<script src="../../assets/javascripts/modernizr.20ef595d.js"></script>
<script src="../../assets/javascripts/modernizr.74668098.js"></script>
@@ -58,6 +58,9 @@
</head>
<body dir="ltr">
@@ -108,22 +111,19 @@
<div class="md-flex__cell md-flex__cell--stretch">
<div class="md-flex__ellipsis md-header-nav__title" data-md-component="title">
<span class="md-header-nav__topic">
Yq
</span>
<span class="md-header-nav__topic">
Works with json
</span>
<span class="md-header-nav__topic">
Yq
</span>
<span class="md-header-nav__topic">
Works with json
</span>
</div>
</div>
<div class="md-flex__cell md-flex__cell--shrink">
<label class="md-icon md-icon--search md-header-nav__button" for="__search"></label>
<label class="md-icon md-icon--search md-header-nav__button" for="__search"></label>
<div class="md-search" data-md-component="search" role="dialog">
<label class="md-search__overlay" for="__search"></label>
<div class="md-search__inner" role="search">
@@ -146,7 +146,6 @@
</div>
</div>
</div>
</div>
@@ -157,20 +156,18 @@
<a href="https://github.com/mikefarah/yq/" title="Go to repository" class="md-source" data-md-source="github">
<div class="md-source__icon">
<svg viewBox="0 0 24 24" width="24" height="24">
<use xlink:href="#__github" width="24" height="24"></use>
</svg>
</div>
<div class="md-source__repository">
mikefarah/yq
<a href="https://github.com/mikefarah/yq/" title="Go to repository" class="md-source" data-md-source="github">
<div class="md-source__icon">
<svg viewBox="0 0 24 24" width="24" height="24">
<use xlink:href="#__github" width="24" height="24"></use>
</svg>
</div>
</a>
<div class="md-source__repository">
mikefarah/yq
</div>
</a>
</div>
</div>
@@ -206,20 +203,18 @@
<a href="https://github.com/mikefarah/yq/" title="Go to repository" class="md-source" data-md-source="github">
<div class="md-source__icon">
<svg viewBox="0 0 24 24" width="24" height="24">
<use xlink:href="#__github" width="24" height="24"></use>
</svg>
</div>
<div class="md-source__repository">
mikefarah/yq
<a href="https://github.com/mikefarah/yq/" title="Go to repository" class="md-source" data-md-source="github">
<div class="md-source__icon">
<svg viewBox="0 0 24 24" width="24" height="24">
<use xlink:href="#__github" width="24" height="24"></use>
</svg>
</div>
</a>
<div class="md-source__repository">
mikefarah/yq
</div>
</a>
</div>
<ul class="md-nav__list" data-md-scrollfix>
@@ -366,7 +361,6 @@
Material for MkDocs</a>
</div>
<div class="md-footer-social">
<link rel="stylesheet" href="../../assets/fonts/font-awesome.css">
@@ -376,20 +370,16 @@
</div>
</div>
</div>
</footer>
</div>
<script src="../../assets/javascripts/application.9e1f3b71.js"></script>
<script src="../../assets/javascripts/application.39abc4af.js"></script>
<script>app.initialize({version:"1.0.4",url:{base:"../.."}})</script>
</body>
</html>

View File

@@ -2,7 +2,7 @@
<!DOCTYPE html>
<!doctype html>
<html lang="en" class="no-js">
<head>
@@ -32,7 +32,7 @@
<meta name="lang:search.tokenizer" content="[\s\-]+">
<link rel="shortcut icon" href="../assets/images/favicon.png">
<meta name="generator" content="mkdocs-1.0.4, mkdocs-material-3.1.0">
<meta name="generator" content="mkdocs-1.0.4, mkdocs-material-4.2.0">
@@ -40,12 +40,12 @@
<link rel="stylesheet" href="../assets/stylesheets/application.11e41852.css">
<link rel="stylesheet" href="../assets/stylesheets/application.750b69bd.css">
<script src="../assets/javascripts/modernizr.20ef595d.js"></script>
<script src="../assets/javascripts/modernizr.74668098.js"></script>
@@ -58,6 +58,9 @@
</head>
<body dir="ltr">
@@ -112,22 +115,19 @@
<div class="md-flex__cell md-flex__cell--stretch">
<div class="md-flex__ellipsis md-header-nav__title" data-md-component="title">
<span class="md-header-nav__topic">
Yq
</span>
<span class="md-header-nav__topic">
Write/Update
</span>
<span class="md-header-nav__topic">
Yq
</span>
<span class="md-header-nav__topic">
Write/Update
</span>
</div>
</div>
<div class="md-flex__cell md-flex__cell--shrink">
<label class="md-icon md-icon--search md-header-nav__button" for="__search"></label>
<label class="md-icon md-icon--search md-header-nav__button" for="__search"></label>
<div class="md-search" data-md-component="search" role="dialog">
<label class="md-search__overlay" for="__search"></label>
<div class="md-search__inner" role="search">
@@ -150,7 +150,6 @@
</div>
</div>
</div>
</div>
@@ -161,20 +160,18 @@
<a href="https://github.com/mikefarah/yq/" title="Go to repository" class="md-source" data-md-source="github">
<div class="md-source__icon">
<svg viewBox="0 0 24 24" width="24" height="24">
<use xlink:href="#__github" width="24" height="24"></use>
</svg>
</div>
<div class="md-source__repository">
mikefarah/yq
<a href="https://github.com/mikefarah/yq/" title="Go to repository" class="md-source" data-md-source="github">
<div class="md-source__icon">
<svg viewBox="0 0 24 24" width="24" height="24">
<use xlink:href="#__github" width="24" height="24"></use>
</svg>
</div>
</a>
<div class="md-source__repository">
mikefarah/yq
</div>
</a>
</div>
</div>
@@ -210,20 +207,18 @@
<a href="https://github.com/mikefarah/yq/" title="Go to repository" class="md-source" data-md-source="github">
<div class="md-source__icon">
<svg viewBox="0 0 24 24" width="24" height="24">
<use xlink:href="#__github" width="24" height="24"></use>
</svg>
</div>
<div class="md-source__repository">
mikefarah/yq
<a href="https://github.com/mikefarah/yq/" title="Go to repository" class="md-source" data-md-source="github">
<div class="md-source__icon">
<svg viewBox="0 0 24 24" width="24" height="24">
<use xlink:href="#__github" width="24" height="24"></use>
</svg>
</div>
</a>
<div class="md-source__repository">
mikefarah/yq
</div>
</a>
</div>
<ul class="md-nav__list" data-md-scrollfix>
@@ -299,6 +294,27 @@
Adding new fields
</a>
</li>
<li class="md-nav__item">
<a href="#splat" title="Splat" class="md-nav__link">
Splat
</a>
</li>
<li class="md-nav__item">
<a href="#prefix-splat" title="Prefix Splat" class="md-nav__link">
Prefix Splat
</a>
</li>
<li class="md-nav__item">
<a href="#array-splat" title="Array Splat" class="md-nav__link">
Array Splat
</a>
</li>
<li class="md-nav__item">
@@ -350,6 +366,13 @@
</li>
<li class="md-nav__item">
<a href="#keys-and-values-with-leading-dashes" title="Keys (and values) with leading dashes" class="md-nav__link">
Keys (and values) with leading dashes
</a>
</li>
@@ -458,6 +481,27 @@
Adding new fields
</a>
</li>
<li class="md-nav__item">
<a href="#splat" title="Splat" class="md-nav__link">
Splat
</a>
</li>
<li class="md-nav__item">
<a href="#prefix-splat" title="Prefix Splat" class="md-nav__link">
Prefix Splat
</a>
</li>
<li class="md-nav__item">
<a href="#array-splat" title="Array Splat" class="md-nav__link">
Array Splat
</a>
</li>
<li class="md-nav__item">
@@ -509,6 +553,13 @@
</li>
<li class="md-nav__item">
<a href="#keys-and-values-with-leading-dashes" title="Keys (and values) with leading dashes" class="md-nav__link">
Keys (and values) with leading dashes
</a>
</li>
@@ -560,7 +611,7 @@
</code></pre>
<p>then</p>
<pre><code class="bash">yq w sample.yaml b.d[0] &quot;new thing&quot;
<pre><code class="bash">yq w sample.yaml b.d[+] &quot;new thing&quot;
</code></pre>
<p>will output:</p>
@@ -570,6 +621,81 @@
- new thing
</code></pre>
<h3 id="splat">Splat<a class="headerlink" href="#splat" title="Permanent link">&para;</a></h3>
<p>Given a sample.yaml file of:</p>
<pre><code class="yaml">---
bob:
item1:
cats: bananas
item2:
cats: apples
thing:
cats: oranges
</code></pre>
<p>then</p>
<pre><code class="bash">yq w sample.yaml bob.*.cats meow
</code></pre>
<p>will output:</p>
<pre><code class="yaml">---
bob:
item1:
cats: meow
item2:
cats: meow
thing:
cats: meow
</code></pre>
<h3 id="prefix-splat">Prefix Splat<a class="headerlink" href="#prefix-splat" title="Permanent link">&para;</a></h3>
<p>Given a sample.yaml file of:</p>
<pre><code class="yaml">---
bob:
item1:
cats: bananas
item2:
cats: apples
thing:
cats: oranges
</code></pre>
<p>then</p>
<pre><code class="bash">yq w sample.yaml bob.item*.cats meow
</code></pre>
<p>will output:</p>
<pre><code class="yaml">---
bob:
item1:
cats: meow
item2:
cats: meow
thing:
cats: oranges
</code></pre>
<h3 id="array-splat">Array Splat<a class="headerlink" href="#array-splat" title="Permanent link">&para;</a></h3>
<p>Given a sample.yaml file of:</p>
<pre><code class="yaml">---
bob:
- cats: bananas
- cats: apples
- cats: oranges
</code></pre>
<p>then</p>
<pre><code class="bash">yq w sample.yaml bob[*].cats meow
</code></pre>
<p>will output:</p>
<pre><code class="yaml">---
bob:
- cats: meow
- cats: meow
- cats: meow
</code></pre>
<h3 id="appending-value-to-an-array-field">Appending value to an array field<a class="headerlink" href="#appending-value-to-an-array-field" title="Permanent link">&para;</a></h3>
<p>Given a sample.yaml file of:</p>
<pre><code class="yaml">b:
@@ -655,7 +781,7 @@ b:
<p>and a script update_instructions.yaml of:</p>
<pre><code class="yaml">b.c: 3
b.e[0].name: Howdy Partner
b.e[+].name: Howdy Partner
</code></pre>
<p>then</p>
@@ -697,6 +823,15 @@ b.e[0].name: Howdy Partner
<p>Any valid yaml key can be specified as part of a key lookup.</p>
<p>Note that the path is in quotes to avoid the square brackets being interpreted by your shell.</p>
<h3 id="keys-and-values-with-leading-dashes">Keys (and values) with leading dashes<a class="headerlink" href="#keys-and-values-with-leading-dashes" title="Permanent link">&para;</a></h3>
<p>If a key or value has leading dashes, yq won't know that you are passing a value as opposed to a flag (and you will get a 'bad flag syntax' error).</p>
<p>To fix that, you will need to tell it to stop processing flags by adding '--' after the last flag like so:</p>
<pre><code class="bash">yq n -t -- --key --value
</code></pre>
<p>Will result in</p>
<p><code>`
--key: --value</code></p>
@@ -760,7 +895,6 @@ b.e[0].name: Howdy Partner
Material for MkDocs</a>
</div>
<div class="md-footer-social">
<link rel="stylesheet" href="../assets/fonts/font-awesome.css">
@@ -770,20 +904,16 @@ b.e[0].name: Howdy Partner
</div>
</div>
</div>
</footer>
</div>
<script src="../assets/javascripts/application.9e1f3b71.js"></script>
<script src="../assets/javascripts/application.39abc4af.js"></script>
<script>app.initialize({version:"1.0.4",url:{base:".."}})</script>
</body>
</html>

View File

@@ -1 +1,14 @@
b: dog
deep1:
hostA:
value: 1234
notRelevant:
value: bananas
hostB:
value: 5678
deep2:
hostC:
value: 1234
notRelevant:
value: bananas
hostD:
value: 5678

View File

@@ -1,2 +1,2 @@
b.c: cat
b.e[0].name: Mike Farah
b.e[+].name: Mike Farah

View File

@@ -0,0 +1,2 @@
5:
6: camel!

12
go.mod Normal file
View File

@@ -0,0 +1,12 @@
module github.com/mikefarah/yq/v2
require (
github.com/mikefarah/yaml/v2 v2.4.0
github.com/pkg/errors v0.8.1
github.com/spf13/cobra v0.0.5
golang.org/x/tools v0.0.0-20191030203535-5e247c9ad0a0 // indirect
gopkg.in/imdario/mergo.v0 v0.3.7
gopkg.in/op/go-logging.v1 v1.0.0-20160211212156-b2cb9fa56473
)
go 1.13

50
go.sum Normal file
View File

@@ -0,0 +1,50 @@
github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU=
github.com/armon/consul-api v0.0.0-20180202201655-eb2c6b5be1b6/go.mod h1:grANhF5doyWs3UAsr3K4I6qtAmlQcZDesFNEHPZAzj8=
github.com/coreos/etcd v3.3.10+incompatible/go.mod h1:uF7uidLiAD3TWHmW31ZFd/JWoc32PjwdhPthX9715RE=
github.com/coreos/go-etcd v2.0.0+incompatible/go.mod h1:Jez6KQU2B/sWsbdaef3ED8NzMklzPG4d5KIOhIy30Tk=
github.com/coreos/go-semver v0.2.0/go.mod h1:nnelYz7RCh+5ahJtPPxZlU+153eP4D4r3EedlOD2RNk=
github.com/cpuguy83/go-md2man v1.0.10/go.mod h1:SmD6nW6nTyfqj6ABTjUi3V3JVMnlJmwcJI5acqYI6dE=
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/fsnotify/fsnotify v1.4.7/go.mod h1:jwhsz4b93w/PPRr/qN1Yymfu8t87LnFCMoQvtojpjFo=
github.com/hashicorp/hcl v1.0.0/go.mod h1:E5yfLk+7swimpb2L/Alb/PJmXilQ/rhwaUYs4T20WEQ=
github.com/inconshreveable/mousetrap v1.0.0 h1:Z8tu5sraLXCXIcARxBp/8cbvlwVa7Z1NHg9XEKhtSvM=
github.com/inconshreveable/mousetrap v1.0.0/go.mod h1:PxqpIevigyE2G7u3NXJIT2ANytuPF1OarO4DADm73n8=
github.com/magiconair/properties v1.8.0/go.mod h1:PppfXfuXeibc/6YijjN8zIbojt8czPbwD3XqdrwzmxQ=
github.com/mikefarah/yaml/v2 v2.4.0 h1:eYqfooY0BnvKTJxr7+ABJs13n3dg9n347GScDaU2Lww=
github.com/mikefarah/yaml/v2 v2.4.0/go.mod h1:ahVqZF4n1W4NqwvVnZzC4es67xsW9uR/RRf2RRxieJU=
github.com/mitchellh/go-homedir v1.1.0/go.mod h1:SfyaCUpYCn1Vlf4IUYiD9fPX4A5wJrkLzIz1N1q0pr0=
github.com/mitchellh/mapstructure v1.1.2/go.mod h1:FVVH3fgwuzCH5S8UJGiWEs2h04kUh9fWfEaFds41c1Y=
github.com/pelletier/go-toml v1.2.0/go.mod h1:5z9KED0ma1S8pY6P1sdut58dfprrGBbd/94hg7ilaic=
github.com/pkg/errors v0.8.1 h1:iURUrRGxPUNPdy5/HRSm+Yj6okJ6UtLINN0Q9M4+h3I=
github.com/pkg/errors v0.8.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/russross/blackfriday v1.5.2/go.mod h1:JO/DiYxRf+HjHt06OyowR9PTA263kcR/rfWxYHBV53g=
github.com/spf13/afero v1.1.2/go.mod h1:j4pytiNVoe2o6bmDsKpLACNPDBIoEAkihy7loJ1B0CQ=
github.com/spf13/cast v1.3.0/go.mod h1:Qx5cxh0v+4UWYiBimWS+eyWzqEqokIECu5etghLkUJE=
github.com/spf13/cobra v0.0.5 h1:f0B+LkLX6DtmRH1isoNA9VTtNUK9K8xYd28JNNfOv/s=
github.com/spf13/cobra v0.0.5/go.mod h1:3K3wKZymM7VvHMDS9+Akkh4K60UwM26emMESw8tLCHU=
github.com/spf13/jwalterweatherman v1.0.0/go.mod h1:cQK4TGJAtQXfYWX+Ddv3mKDzgVb68N+wFjFa4jdeBTo=
github.com/spf13/pflag v1.0.3 h1:zPAT6CGy6wXeQ7NtTnaTerfKOsV6V6F8agHXFiazDkg=
github.com/spf13/pflag v1.0.3/go.mod h1:DYY7MBk1bdzusC3SYhjObp+wFpr4gzcvqqNjLnInEg4=
github.com/spf13/viper v1.3.2/go.mod h1:ZiWeW+zYFKm7srdB9IoDzzZXaJaI5eL9QjNiN/DMA2s=
github.com/stretchr/testify v1.2.2/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs=
github.com/ugorji/go/codec v0.0.0-20181204163529-d75b2dcb6bc8/go.mod h1:VFNgLljTbGfSG7qAOspJ7OScBnGdDN/yBr0sguwnwf0=
github.com/xordataexchange/crypt v0.0.3-0.20170626215501-b2862e3d0a77/go.mod h1:aYKd//L2LvnjZzWKhF00oedf4jCCReLcmhLdhm1A27Q=
golang.org/x/crypto v0.0.0-20181203042331-505ab145d0a9/go.mod h1:6SG95UA2DQfeDnfUPMdvaQW0Q7yPrPDi9nlGo2tz2b4=
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
golang.org/x/net v0.0.0-20190620200207-3b0461eec859/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sys v0.0.0-20181205085412-a5c9d58dba9a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
golang.org/x/tools v0.0.0-20191030203535-5e247c9ad0a0 h1:s5lp4ug7qHzUccgyFdjsX7OZDzHXRaePrF3B3vmUiuM=
golang.org/x/tools v0.0.0-20191030203535-5e247c9ad0a0/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo=
golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/imdario/mergo.v0 v0.3.7 h1:QDotlIZtaO/p+Um0ok18HRTpq5i5/SAk/qprsor+9c8=
gopkg.in/imdario/mergo.v0 v0.3.7/go.mod h1:9qPP6AGrlC1G2PTNXko614FwGZvorN7MiBU0Eppok+U=
gopkg.in/op/go-logging.v1 v1.0.0-20160211212156-b2cb9fa56473 h1:6D+BvnJ/j6e222UW8s2qTSe3wGBtvo0MbVQG/c5k8RE=
gopkg.in/op/go-logging.v1 v1.0.0-20160211212156-b2cb9fa56473/go.mod h1:N1eN2tsCx0Ydtgjl4cqmbRCsY4/+z4cYDeqwZTk6zog=
gopkg.in/yaml.v2 v2.2.2 h1:ZCJp+EgiOT7lHqUV2J862kp8Qj64Jo6az82+3Td9dZw=
gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=

View File

@@ -5,7 +5,7 @@ import (
"fmt"
"strconv"
yaml "gopkg.in/mikefarah/yaml.v2"
yaml "github.com/mikefarah/yaml/v2"
)
func jsonToString(context interface{}) (string, error) {

View File

@@ -20,7 +20,7 @@ Create scripts follow the same format as the update scripts.
Given a script create_instructions.yaml of:
```yaml
b.c: 3
b.e[0].name: Howdy Partner
b.e[+].name: Howdy Partner
```
then
@@ -41,4 +41,4 @@ You can also pipe the instructions in:
cat create_instructions.yaml | yq n -s -
```
{!snippets/keys_with_dots.md!}
{!snippets/niche.md!}

View File

@@ -59,6 +59,93 @@ yq d -i sample.yaml b.c
will update the sample.yaml file so that the 'c' node is deleted
### Splat
Given a sample.yaml file of:
```yaml
---
bob:
item1:
cats: bananas
dogs: woof
item2:
cats: apples
dogs: woof2
thing:
cats: oranges
dogs: woof3
```
then
```bash
yq d sample.yaml bob.*.cats
```
will output:
```yaml
---
bob:
item1:
dogs: woof
item2:
dogs: woof2
thing:
dogs: woof3
```
### Prefix Splat
Given a sample.yaml file of:
```yaml
---
bob:
item1:
cats: bananas
dogs: woof
item2:
cats: apples
dogs: woof2
thing:
cats: oranges
dogs: woof3
```
then
```bash
yq d sample.yaml bob.item*.cats
```
will output:
```yaml
---
bob:
item1:
dogs: woof
item2:
dogs: woof2
thing:
cats: oranges
dogs: woof3
```
### Array Splat
Given a sample.yaml file of:
```yaml
---
bob:
- cats: bananas
dogs: woof
- cats: apples
dogs: woof2
- cats: oranges
dogs: woof3
```
then
```bash
yq d sample.yaml bob.[*].cats
```
will output:
```yaml
---
bob:
- dogs: woof
- dogs: woof2
- dogs: woof3
```
### Multiple Documents - delete from single document
Given a sample.yaml file of:
@@ -107,4 +194,4 @@ b:
Note that '*' is in quotes to avoid being interpreted by your shell.
{!snippets/keys_with_dots.md!}
{!snippets/niche.md!}

View File

@@ -32,6 +32,8 @@ bob:
cats: bananas
item2:
cats: apples
thing:
cats: oranges
```
then
```bash
@@ -41,6 +43,29 @@ will output
```yaml
- bananas
- apples
- oranges
```
### Prefix Splat
Given a sample.yaml file of:
```yaml
---
bob:
item1:
cats: bananas
item2:
cats: apples
thing:
cats: oranges
```
then
```bash
yq r sample.yaml bob.item*.cats
```
will output
```yaml
- bananas
- apples
```
### Multiple Documents - specify a single document
@@ -122,4 +147,4 @@ will output:
```
Note that the path is in quotes to avoid the square brackets being interpreted by your shell.
{!snippets/keys_with_dots.md!}
{!snippets/niche.md!}

View File

@@ -1,19 +0,0 @@
### Keys with dots
When specifying a key that has a dot use key lookup indicator.
```yaml
b:
foo.bar: 7
```
```bash
yaml r sample.yaml 'b[foo.bar]'
```
```bash
yaml w sample.yaml 'b[foo.bar]' 9
```
Any valid yaml key can be specified as part of a key lookup.
Note that the path is in quotes to avoid the square brackets being interpreted by your shell.

35
mkdocs/snippets/niche.md Normal file
View File

@@ -0,0 +1,35 @@
### Keys with dots
When specifying a key that has a dot use key lookup indicator.
```yaml
b:
foo.bar: 7
```
```bash
yaml r sample.yaml 'b[foo.bar]'
```
```bash
yaml w sample.yaml 'b[foo.bar]' 9
```
Any valid yaml key can be specified as part of a key lookup.
Note that the path is in quotes to avoid the square brackets being interpreted by your shell.
### Keys (and values) with leading dashes
If a key or value has leading dashes, yq won't know that you are passing a value as opposed to a flag (and you will get a 'bad flag syntax' error).
To fix that, you will need to tell it to stop processing flags by adding '--' after the last flag like so:
```bash
yq n -t -- --key --value
```
Will result in
```
--key: --value
```

View File

@@ -33,7 +33,7 @@ b:
```
then
```bash
yq w sample.yaml b.d[0] "new thing"
yq w sample.yaml b.d[+] "new thing"
```
will output:
```yaml
@@ -43,6 +43,84 @@ b:
- new thing
```
### Splat
Given a sample.yaml file of:
```yaml
---
bob:
item1:
cats: bananas
item2:
cats: apples
thing:
cats: oranges
```
then
```bash
yq w sample.yaml bob.*.cats meow
```
will output:
```yaml
---
bob:
item1:
cats: meow
item2:
cats: meow
thing:
cats: meow
```
### Prefix Splat
Given a sample.yaml file of:
```yaml
---
bob:
item1:
cats: bananas
item2:
cats: apples
thing:
cats: oranges
```
then
```bash
yq w sample.yaml bob.item*.cats meow
```
will output:
```yaml
---
bob:
item1:
cats: meow
item2:
cats: meow
thing:
cats: oranges
```
### Array Splat
Given a sample.yaml file of:
```yaml
---
bob:
- cats: bananas
- cats: apples
- cats: oranges
```
then
```bash
yq w sample.yaml bob[*].cats meow
```
will output:
```yaml
---
bob:
- cats: meow
- cats: meow
- cats: meow
```
### Appending value to an array field
Given a sample.yaml file of:
```yaml
@@ -136,7 +214,7 @@ b:
and a script update_instructions.yaml of:
```yaml
b.c: 3
b.e[0].name: Howdy Partner
b.e[+].name: Howdy Partner
```
then
@@ -169,4 +247,4 @@ my:
path: -3
```
{!snippets/keys_with_dots.md!}
{!snippets/niche.md!}

View File

@@ -20,9 +20,14 @@
then use the UI (https://snapcraft.io/yq/release)
- go get
- update the readme instructions
- brew
- brew bump-formula-pr --url=https://github.com/mikefarah/yq/archive/2.2.0.tar.gz yq
- if that fails with random ruby errors try:
- clearing out the gems rm -rf .gem/ruby/2.3.0
- export HOMEBREW_FORCE_VENDOR_RUBY=1
- docker
- build and push latest and new version tag

View File

@@ -6,7 +6,7 @@ set -e
X=$(./yq w ./examples/sample.yaml b.c 3 | ./yq r - b.c)
if [[ $X != 3 ]]; then
echo "Failed acceptance test: expected 2 but was $X"
echo "Failed acceptance test: expected 3 but was $X"
exit 1
fi
echo "acceptance tests passed"

View File

@@ -3,24 +3,14 @@
set -o errexit
set -o pipefail
gometalinter \
--skip=examples \
--tests \
--vendor \
--disable=aligncheck \
--disable=gotype \
--disable=goconst \
--cyclo-over=20 \
--deadline=300s \
./...
./bin/golangci-lint run
gometalinter \
--skip=examples \
--tests \
--vendor \
--disable=aligncheck \
--disable=gotype \
--disable=goconst \
--disable=gocyclo \
--deadline=300s \
./...
# ./bin/golangci-lint \
# --tests \
# --vendor \
# --disable=aligncheck \
# --disable=gotype \
# --disable=goconst \
# --disable=gocyclo \
# --deadline=300s \
# ./...

View File

@@ -1,10 +1,4 @@
#!/bin/sh
go get -u github.com/alecthomas/gometalinter
go get -u golang.org/x/tools/cmd/goimports
go get -u github.com/mitchellh/gox
go get -u github.com/kardianos/govendor
go get -u github.com/aktau/github-release
# install all the linters
gometalinter --install --update
set -e
wget -O - -q https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s v1.21.0
go get golang.org/x/tools/cmd/goimports

2
scripts/doctools.sh Normal file → Executable file
View File

@@ -1,4 +1,4 @@
#!/bin.bash
#!/bin/bash
brew install mkdocs libyaml
pip3 install markdown-include

View File

@@ -10,11 +10,13 @@ REPO="yq"
release() {
github-release release \
--user "$OWNER" \
--draft \
--repo "$REPO" \
--tag "$CURRENT"
}
upload() {
mkdir -p ./build-done
while IFS= read -r -d $'\0'; do
file=$REPLY
BINARY=$(basename "${file}")
@@ -26,6 +28,7 @@ upload() {
--tag "$CURRENT" \
--name "${BINARY}" \
--file "$file"
mv "$file" "./build-done/${BINARY}"
done < <(find ./build -mindepth 1 -maxdepth 1 -print0)
}

View File

@@ -1,3 +1,3 @@
#!/bin/bash
go test -v $(go list ./... | grep -v -E 'vendor|examples')
go test -v $(go list ./... | grep -v -E 'examples')

View File

@@ -1,5 +1,5 @@
name: yq
version: '2.3.0'
version: '2.4.1'
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.
@@ -19,4 +19,4 @@ parts:
go-importpath: github.com/mikefarah/yq
after: [go]
go:
source-tag: go1.9.4
source-tag: go1.11

View File

@@ -9,8 +9,8 @@ import (
"strings"
"testing"
yaml "gopkg.in/mikefarah/yaml.v2"
cobra "gopkg.in/spf13/cobra.v0"
yaml "github.com/mikefarah/yaml/v2"
"github.com/spf13/cobra"
)
type resulter struct {

49
vendor/vendor.json vendored
View File

@@ -1,49 +0,0 @@
{
"comment": "",
"ignore": "test",
"package": [
{
"checksumSHA1": "40vJyUB4ezQSn/NSadsKEOrudMc=",
"path": "github.com/inconshreveable/mousetrap",
"revision": "76626ae9c91c4f2a10f34cad8ce83ea42c93bb75",
"revisionTime": "2014-10-17T20:07:13Z"
},
{
"checksumSHA1": "ljd3FhYRJ91cLZz3wsH9BQQ2JbA=",
"path": "github.com/pkg/errors",
"revision": "816c9085562cd7ee03e7f8188a1cfd942858cded",
"revisionTime": "2018-03-11T21:45:15Z"
},
{
"checksumSHA1": "OJI0OgC5V8gZtfS1e0CDYMhkDNc=",
"path": "github.com/spf13/pflag",
"revision": "3ebe029320b2676d667ae88da602a5f854788a8a",
"revisionTime": "2018-06-01T13:25:42Z"
},
{
"checksumSHA1": "RwlkCZz8VFXAE4aHQQOSC0hLu5k=",
"path": "gopkg.in/imdario/mergo.v0",
"revision": "9316a62528ac99aaecb4e47eadd6dc8aa6533d58",
"revisionTime": "2018-06-08T14:01:56Z"
},
{
"checksumSHA1": "7wtGubs4v7+RZovtlmyT9KwA/gE=",
"path": "gopkg.in/mikefarah/yaml.v2",
"revision": "e175af14aaa1d0eff2ee04b691e4a4827a111416",
"revisionTime": "2018-06-13T04:05:11Z"
},
{
"checksumSHA1": "rL5r44ASTGubGW88gqQwlvVQshw=",
"path": "gopkg.in/op/go-logging.v1",
"revision": "b2cb9fa56473e98db8caba80237377e83fe44db5",
"revisionTime": "2016-02-11T21:21:56Z"
},
{
"checksumSHA1": "xsZjAbfLrXcMtY6fyQ8QC6EvJD0=",
"path": "gopkg.in/spf13/cobra.v0",
"revision": "ef82de70bb3f60c65fb8eebacbb2d122ef517385",
"revisionTime": "2018-04-27T13:45:50Z"
}
],
"rootPath": "github.com/mikefarah/yq"
}

View File

@@ -11,7 +11,7 @@ var (
GitDescribe string
// Version is main version number that is being run at the moment.
Version = "2.3.0"
Version = "2.4.1"
// 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

27
yq.go
View File

@@ -12,9 +12,9 @@ import (
errors "github.com/pkg/errors"
yaml "gopkg.in/mikefarah/yaml.v2"
yaml "github.com/mikefarah/yaml/v2"
"github.com/spf13/cobra"
logging "gopkg.in/op/go-logging.v1"
cobra "gopkg.in/spf13/cobra.v0"
)
var trimOutput = true
@@ -40,7 +40,9 @@ func main() {
func newCommandCLI() *cobra.Command {
yaml.DefaultMapType = reflect.TypeOf(yaml.MapSlice{})
var rootCmd = &cobra.Command{
Use: "yq",
Use: "yq",
Short: "yq is a lightweight and portable command-line YAML processor.",
Long: `yq is a lightweight and portable command-line YAML processor. It aims to be the jq or sed of yaml files.`,
RunE: func(cmd *cobra.Command, args []string) error {
if version {
cmd.Print(GetVersionDisplay())
@@ -95,6 +97,7 @@ yq r - a.b.c (reads from stdin)
yq r things.yaml a.*.c
yq r -d1 things.yaml a.array[0].blah
yq r things.yaml a.array[*].blah
yq r -- things.yaml --key-starting-with-dashes
`,
Long: "Outputs the value of the given path in the yaml file to STDOUT",
RunE: readProperty,
@@ -111,7 +114,7 @@ func createWriteCmd() *cobra.Command {
Short: "yq w [--inplace/-i] [--script/-s script_file] [--doc/-d index] sample.yaml a.b.c newValue",
Example: `
yq write things.yaml a.b.c cat
yq write --inplace things.yaml a.b.c cat
yq write --inplace -- things.yaml a.b.c --cat
yq w -i things.yaml a.b.c cat
yq w --script update_script.yaml things.yaml
yq w -i -s update_script.yaml things.yaml
@@ -147,6 +150,7 @@ func createPrefixCmd() *cobra.Command {
Example: `
yq prefix things.yaml a.b.c
yq prefix --inplace things.yaml a.b.c
yq prefix --inplace -- things.yaml --key-starting-with-dash
yq p -i things.yaml a.b.c
yq p --doc 2 things.yaml a.b.d
yq p -d2 things.yaml a.b.d
@@ -169,6 +173,7 @@ func createDeleteCmd() *cobra.Command {
Example: `
yq delete things.yaml a.b.c
yq delete --inplace things.yaml a.b.c
yq delete --inplace -- things.yaml --key-starting-with-dash
yq d -i things.yaml a.b.c
yq d things.yaml a.b.c
`,
@@ -190,6 +195,7 @@ func createNewCmd() *cobra.Command {
Example: `
yq new a.b.c cat
yq n a.b.c cat
yq n -- --key-starting-with-dash cat
yq n --script create_script.yaml
`,
Long: `Creates a new yaml w.r.t the given path and value.
@@ -499,7 +505,7 @@ func deleteProperty(cmd *cobra.Command, args []string) error {
var updateData = func(dataBucket interface{}, currentIndex int) (interface{}, error) {
if updateAll || currentIndex == docIndexInt {
log.Debugf("Deleting path in doc %v", currentIndex)
return deleteChildValue(dataBucket, paths), nil
return deleteChildValue(dataBucket, paths)
}
return dataBucket, nil
}
@@ -620,13 +626,18 @@ func marshalContext(context interface{}) (string, error) {
func safelyRenameFile(from string, to string) {
if renameError := os.Rename(from, to); renameError != nil {
log.Warningf("Error renaming from %v to %v, attemting to copy contents", from, to)
log.Warning(renameError.Error())
log.Debugf("Error renaming from %v to %v, attemting to copy contents", from, to)
log.Debug(renameError.Error())
// can't do this rename when running in docker to a file targeted in a mounted volume,
// so gracefully degrade to copying the entire contents.
if copyError := copyFileContents(from, to); copyError != nil {
log.Errorf("Failed copying from %v to %v", from, to)
log.Errorf(copyError.Error())
log.Error(copyError.Error())
} else {
removeErr := os.Remove(from)
if removeErr != nil {
log.Errorf("failed removing original file: %s", from)
}
}
}
}