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

Compare commits

...

16 Commits

Author SHA1 Message Date
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
47 changed files with 992 additions and 4415 deletions

View File

@@ -8,21 +8,40 @@ 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
```
@@ -63,6 +82,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 +93,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

View File

@@ -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"
)
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:]
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)
}
// must be an array
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)
}
}
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)
}
log.Debugf("\tdetected an array, so traversing element with index %d\n", idx)
return deleteArray(child, remainingPaths, idx)
index, err := strconv.ParseInt(head, 10, 64)
if err != nil {
return nil, fmt.Errorf("error accessing array: %v", err)
}
return deleteArray(child, remainingPaths, index)
}
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,7 +111,6 @@
<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>
@@ -116,12 +118,10 @@
</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>
<div class="md-search" data-md-component="search" role="dialog">
@@ -147,7 +147,6 @@
</div>
</div>
</div>
<div class="md-flex__cell md-flex__cell--shrink">
@@ -157,8 +156,7 @@
<a href="https://github.com/mikefarah/yq/" title="Go to repository" class="md-source" data-md-source="github">
<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">
@@ -169,8 +167,7 @@
<div class="md-source__repository">
mikefarah/yq
</div>
</a>
</a>
</div>
</div>
@@ -206,8 +203,7 @@
<a href="https://github.com/mikefarah/yq/" title="Go to repository" class="md-source" data-md-source="github">
<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">
@@ -218,8 +214,7 @@
<div class="md-source__repository">
mikefarah/yq
</div>
</a>
</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,7 +115,6 @@
<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>
@@ -120,12 +122,10 @@
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>
<div class="md-search" data-md-component="search" role="dialog">
@@ -151,7 +151,6 @@
</div>
</div>
</div>
<div class="md-flex__cell md-flex__cell--shrink">
@@ -161,8 +160,7 @@
<a href="https://github.com/mikefarah/yq/" title="Go to repository" class="md-source" data-md-source="github">
<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">
@@ -173,8 +171,7 @@
<div class="md-source__repository">
mikefarah/yq
</div>
</a>
</a>
</div>
</div>
@@ -210,8 +207,7 @@
<a href="https://github.com/mikefarah/yq/" title="Go to repository" class="md-source" data-md-source="github">
<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">
@@ -222,8 +218,7 @@
<div class="md-source__repository">
mikefarah/yq
</div>
</a>
</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,7 +115,6 @@
<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>
@@ -120,12 +122,10 @@
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>
<div class="md-search" data-md-component="search" role="dialog">
@@ -151,7 +151,6 @@
</div>
</div>
</div>
<div class="md-flex__cell md-flex__cell--shrink">
@@ -161,8 +160,7 @@
<a href="https://github.com/mikefarah/yq/" title="Go to repository" class="md-source" data-md-source="github">
<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">
@@ -173,8 +171,7 @@
<div class="md-source__repository">
mikefarah/yq
</div>
</a>
</a>
</div>
</div>
@@ -210,8 +207,7 @@
<a href="https://github.com/mikefarah/yq/" title="Go to repository" class="md-source" data-md-source="github">
<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">
@@ -222,8 +218,7 @@
<div class="md-source__repository">
mikefarah/yq
</div>
</a>
</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>
@@ -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,7 +115,6 @@
<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>
@@ -120,12 +122,10 @@
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>
<div class="md-search" data-md-component="search" role="dialog">
@@ -151,7 +151,6 @@
</div>
</div>
</div>
<div class="md-flex__cell md-flex__cell--shrink">
@@ -161,8 +160,7 @@
<a href="https://github.com/mikefarah/yq/" title="Go to repository" class="md-source" data-md-source="github">
<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">
@@ -173,8 +171,7 @@
<div class="md-source__repository">
mikefarah/yq
</div>
</a>
</a>
</div>
</div>
@@ -210,8 +207,7 @@
<a href="https://github.com/mikefarah/yq/" title="Go to repository" class="md-source" data-md-source="github">
<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">
@@ -222,8 +218,7 @@
<div class="md-source__repository">
mikefarah/yq
</div>
</a>
</a>
</div>
<ul class="md-nav__list" data-md-scrollfix>
@@ -353,6 +348,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>
@@ -467,6 +469,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>
@@ -601,6 +610,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 +682,6 @@ b:
Material for MkDocs</a>
</div>
<div class="md-footer-social">
<link rel="stylesheet" href="../assets/fonts/font-awesome.css">
@@ -674,20 +691,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,7 +115,6 @@
<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>
@@ -120,12 +122,10 @@
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>
<div class="md-search" data-md-component="search" role="dialog">
@@ -151,7 +151,6 @@
</div>
</div>
</div>
<div class="md-flex__cell md-flex__cell--shrink">
@@ -161,8 +160,7 @@
<a href="https://github.com/mikefarah/yq/" title="Go to repository" class="md-source" data-md-source="github">
<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">
@@ -173,8 +171,7 @@
<div class="md-source__repository">
mikefarah/yq
</div>
</a>
</a>
</div>
</div>
@@ -210,8 +207,7 @@
<a href="https://github.com/mikefarah/yq/" title="Go to repository" class="md-source" data-md-source="github">
<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">
@@ -222,8 +218,7 @@
<div class="md-source__repository">
mikefarah/yq
</div>
</a>
</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,7 +115,6 @@
<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>
@@ -120,12 +122,10 @@
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>
<div class="md-search" data-md-component="search" role="dialog">
@@ -151,7 +151,6 @@
</div>
</div>
</div>
<div class="md-flex__cell md-flex__cell--shrink">
@@ -161,8 +160,7 @@
<a href="https://github.com/mikefarah/yq/" title="Go to repository" class="md-source" data-md-source="github">
<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">
@@ -173,8 +171,7 @@
<div class="md-source__repository">
mikefarah/yq
</div>
</a>
</a>
</div>
</div>
@@ -210,8 +207,7 @@
<a href="https://github.com/mikefarah/yq/" title="Go to repository" class="md-source" data-md-source="github">
<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">
@@ -222,8 +218,7 @@
<div class="md-source__repository">
mikefarah/yq
</div>
</a>
</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,7 +115,6 @@
<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>
@@ -120,12 +122,10 @@
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>
<div class="md-search" data-md-component="search" role="dialog">
@@ -151,7 +151,6 @@
</div>
</div>
</div>
<div class="md-flex__cell md-flex__cell--shrink">
@@ -161,8 +160,7 @@
<a href="https://github.com/mikefarah/yq/" title="Go to repository" class="md-source" data-md-source="github">
<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">
@@ -173,8 +171,7 @@
<div class="md-source__repository">
mikefarah/yq
</div>
</a>
</a>
</div>
</div>
@@ -210,8 +207,7 @@
<a href="https://github.com/mikefarah/yq/" title="Go to repository" class="md-source" data-md-source="github">
<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">
@@ -222,8 +218,7 @@
<div class="md-source__repository">
mikefarah/yq
</div>
</a>
</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,7 +115,6 @@
<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>
@@ -120,12 +122,10 @@
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>
<div class="md-search" data-md-component="search" role="dialog">
@@ -151,7 +151,6 @@
</div>
</div>
</div>
<div class="md-flex__cell md-flex__cell--shrink">
@@ -161,8 +160,7 @@
<a href="https://github.com/mikefarah/yq/" title="Go to repository" class="md-source" data-md-source="github">
<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">
@@ -173,8 +171,7 @@
<div class="md-source__repository">
mikefarah/yq
</div>
</a>
</a>
</div>
</div>
@@ -210,8 +207,7 @@
<a href="https://github.com/mikefarah/yq/" title="Go to repository" class="md-source" data-md-source="github">
<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">
@@ -222,8 +218,7 @@
<div class="md-source__repository">
mikefarah/yq
</div>
</a>
</a>
</div>
<ul class="md-nav__list" data-md-scrollfix>
@@ -324,6 +319,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>
@@ -481,6 +483,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>
@@ -629,6 +638,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 +710,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 +719,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-14</lastmod>
<changefreq>daily</changefreq>
</url>
<url>
<loc>None</loc>
<lastmod>2018-11-19</lastmod>
<lastmod>2019-05-14</lastmod>
<changefreq>daily</changefreq>
</url>
<url>
<loc>None</loc>
<lastmod>2018-11-19</lastmod>
<lastmod>2019-05-14</lastmod>
<changefreq>daily</changefreq>
</url>
<url>
<loc>None</loc>
<lastmod>2018-11-19</lastmod>
<lastmod>2019-05-14</lastmod>
<changefreq>daily</changefreq>
</url>
<url>
<loc>None</loc>
<lastmod>2018-11-19</lastmod>
<lastmod>2019-05-14</lastmod>
<changefreq>daily</changefreq>
</url>
<url>
<loc>None</loc>
<lastmod>2018-11-19</lastmod>
<lastmod>2019-05-14</lastmod>
<changefreq>daily</changefreq>
</url>
<url>
<loc>None</loc>
<lastmod>2018-11-19</lastmod>
<lastmod>2019-05-14</lastmod>
<changefreq>daily</changefreq>
</url>
<url>
<loc>None</loc>
<lastmod>2018-11-19</lastmod>
<lastmod>2019-05-14</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,20 +115,17 @@
<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
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>
<div class="md-search" data-md-component="search" role="dialog">
@@ -151,7 +151,6 @@
</div>
</div>
</div>
<div class="md-flex__cell md-flex__cell--shrink">
@@ -161,8 +160,7 @@
<a href="https://github.com/mikefarah/yq/" title="Go to repository" class="md-source" data-md-source="github">
<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">
@@ -173,8 +171,7 @@
<div class="md-source__repository">
mikefarah/yq
</div>
</a>
</a>
</div>
</div>
@@ -210,8 +207,7 @@
<a href="https://github.com/mikefarah/yq/" title="Go to repository" class="md-source" data-md-source="github">
<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">
@@ -222,8 +218,7 @@
<div class="md-source__repository">
mikefarah/yq
</div>
</a>
</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,7 +111,6 @@
<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>
@@ -116,12 +118,10 @@
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>
<div class="md-search" data-md-component="search" role="dialog">
@@ -147,7 +147,6 @@
</div>
</div>
</div>
<div class="md-flex__cell md-flex__cell--shrink">
@@ -157,8 +156,7 @@
<a href="https://github.com/mikefarah/yq/" title="Go to repository" class="md-source" data-md-source="github">
<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">
@@ -169,8 +167,7 @@
<div class="md-source__repository">
mikefarah/yq
</div>
</a>
</a>
</div>
</div>
@@ -206,8 +203,7 @@
<a href="https://github.com/mikefarah/yq/" title="Go to repository" class="md-source" data-md-source="github">
<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">
@@ -218,8 +214,7 @@
<div class="md-source__repository">
mikefarah/yq
</div>
</a>
</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,7 +115,6 @@
<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>
@@ -120,12 +122,10 @@
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>
<div class="md-search" data-md-component="search" role="dialog">
@@ -151,7 +151,6 @@
</div>
</div>
</div>
<div class="md-flex__cell md-flex__cell--shrink">
@@ -161,8 +160,7 @@
<a href="https://github.com/mikefarah/yq/" title="Go to repository" class="md-source" data-md-source="github">
<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">
@@ -173,8 +171,7 @@
<div class="md-source__repository">
mikefarah/yq
</div>
</a>
</a>
</div>
</div>
@@ -210,8 +207,7 @@
<a href="https://github.com/mikefarah/yq/" title="Go to repository" class="md-source" data-md-source="github">
<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">
@@ -222,8 +218,7 @@
<div class="md-source__repository">
mikefarah/yq
</div>
</a>
</a>
</div>
<ul class="md-nav__list" data-md-scrollfix>
@@ -350,6 +345,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>
@@ -509,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>
@@ -697,6 +706,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 +778,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 +787,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!

View File

@@ -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

@@ -107,4 +107,4 @@ b:
Note that '*' is in quotes to avoid being interpreted by your shell.
{!snippets/keys_with_dots.md!}
{!snippets/niche.md!}

View File

@@ -122,4 +122,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

@@ -169,4 +169,4 @@ my:
path: -3
```
{!snippets/keys_with_dots.md!}
{!snippets/niche.md!}

View File

@@ -23,6 +23,9 @@
- 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

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,6 +10,7 @@ REPO="yq"
release() {
github-release release \
--user "$OWNER" \
--draft \
--repo "$REPO" \
--tag "$CURRENT"
}

View File

@@ -1,5 +1,5 @@
name: yq
version: '2.3.0'
version: '2.4.0'
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

@@ -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.0"
// 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

10
yq.go
View File

@@ -41,6 +41,8 @@ func newCommandCLI() *cobra.Command {
yaml.DefaultMapType = reflect.TypeOf(yaml.MapSlice{})
var rootCmd = &cobra.Command{
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
}