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

Compare commits

..

25 Commits
2.2.0 ... 2.4.0

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
Mike Farah
9b4972e46e Increment version for new functionality 2019-03-22 09:15:26 +11:00
Renzo Crisóstomo
23543ee031 Add test for --allow-empty flag in merge command 2019-03-22 09:13:39 +11:00
Renzo Crisóstomo
75c7d40c44 Add --allow-empty flag to merge command 2019-03-22 09:13:39 +11:00
Mikhail Novosyolov
44b8a5e80f Fix Debian 'Architecture'
When it's 'all', architecture-independent packages are built, and so now an x86_64 executable is packaged to noarch packaged.
2019-03-21 12:39:47 +11:00
Mike Farah
77c8f22a79 Bump golang version to 1.11 2019-01-21 09:37:22 +11:00
Roberto Mier Escandon
386a0ca3c3 Bump debian pkg to 2.2-1 version 2019-01-21 09:06:43 +11:00
Mike Farah
53a20d4421 Bumb version 2019-01-07 10:23:37 +11:00
Kyle Titus
478208b7c4 Added Windows support for the "--inplace" command flag 2019-01-07 10:07:08 +11:00
Mike Farah
1159d0a212 Fixing snapcraft yml 2018-11-21 13:39:03 +11:00
57 changed files with 1093 additions and 4460 deletions

View File

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

View File

@@ -1,4 +1,4 @@
FROM golang:1.9 as builder FROM golang:1.11 as builder
WORKDIR /go/src/mikefarah/yq WORKDIR /go/src/mikefarah/yq

View File

@@ -14,7 +14,6 @@ help:
@echo ' make build Build yq binary.' @echo ' make build Build yq binary.'
@echo ' make install Install yq.' @echo ' make install Install yq.'
@echo ' make xcompile Build cross-compiled binaries of yq.' @echo ' make xcompile Build cross-compiled binaries of yq.'
@echo ' make snap Build a snap package of yq.'
@echo ' make vendor Install dependencies using govendor.' @echo ' make vendor Install dependencies using govendor.'
@echo ' make format Run code formatter.' @echo ' make format Run code formatter.'
@echo ' make check Run static code analysis (lint).' @echo ' make check Run static code analysis (lint).'
@@ -65,10 +64,6 @@ xcompile: check
@find build -type d -exec chmod 755 {} \; || : @find build -type d -exec chmod 755 {} \; || :
@find build -type f -exec chmod 755 {} \; || : @find build -type f -exec chmod 755 {} \; || :
.PHONY: snap
snap:
snapcraft
.PHONY: install .PHONY: install
install: build install: build
${DOCKRUN} go install ${DOCKRUN} go install

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. The aim of the project is to be the [jq](https://github.com/stedolan/jq) or sed of yaml files.
## Install ## Install
On MacOS: ### On MacOS:
``` ```
brew install yq brew install yq
``` ```
On Ubuntu and other Linux distros supporting `snap` packages: ### On Ubuntu and other Linux distros supporting `snap` packages:
``` ```
snap install yq 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 add-apt-repository ppa:rmescandon/yq
sudo apt update sudo apt update
sudo apt install yq -y 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 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. 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: Usage:
yq [flags] yq [flags]
yq [command] yq [command]
@@ -72,9 +93,9 @@ Available Commands:
help Help about any command help Help about any command
merge yq m [--inplace/-i] [--doc/-d index] [--overwrite/-x] [--append/-a] sample.yaml sample2.yaml 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 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 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 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: Flags:
-h, --help help for yq -h, --help help for yq

View File

@@ -3,10 +3,11 @@ package main
import ( import (
"fmt" "fmt"
"os" "os"
"runtime"
"strings" "strings"
"testing" "testing"
"gopkg.in/spf13/cobra.v0" cobra "gopkg.in/spf13/cobra.v0"
) )
func getRootCommand() *cobra.Command { func getRootCommand() *cobra.Command {
@@ -23,7 +24,18 @@ func TestRootCmd(t *testing.T) {
if !strings.Contains(result.Output, "Usage:") { if !strings.Contains(result.Output, "Usage:") {
t.Error("Expected usage message to be printed out, but the usage message was not found.") 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) { func TestRootCmd_VerboseLong(t *testing.T) {
@@ -121,7 +133,7 @@ func TestReadBadDocumentIndexCmd(t *testing.T) {
if result.Error == nil { if result.Error == nil {
t.Error("Expected command to fail due to invalid path") t.Error("Expected command to fail due to invalid path")
} }
expectedOutput := `Asked to process document index 1 but there are only 1 document(s)` expectedOutput := `asked to process document index 1 but there are only 1 document(s)`
assertResult(t, expectedOutput, result.Error.Error()) assertResult(t, expectedOutput, result.Error.Error())
} }
@@ -239,7 +251,7 @@ func TestReadCmd_ArrayYaml_ErrorBadPath(t *testing.T) {
if result.Error == nil { if result.Error == nil {
t.Error("Expected command to fail due to invalid path") t.Error("Expected command to fail due to invalid path")
} }
expectedOutput := `Error reading path in document index 0: Error accessing array: strconv.ParseInt: parsing "x": invalid syntax` expectedOutput := `Error reading path in document index 0: error accessing array: strconv.ParseInt: parsing "x": invalid syntax`
assertResult(t, expectedOutput, result.Error.Error()) assertResult(t, expectedOutput, result.Error.Error())
} }
@@ -249,7 +261,7 @@ func TestReadCmd_ArrayYaml_Splat_ErrorBadPath(t *testing.T) {
if result.Error == nil { if result.Error == nil {
t.Error("Expected command to fail due to invalid path") t.Error("Expected command to fail due to invalid path")
} }
expectedOutput := `Error reading path in document index 0: Error accessing array: strconv.ParseInt: parsing "x": invalid syntax` expectedOutput := `Error reading path in document index 0: error accessing array: strconv.ParseInt: parsing "x": invalid syntax`
assertResult(t, expectedOutput, result.Error.Error()) assertResult(t, expectedOutput, result.Error.Error())
} }
@@ -279,7 +291,12 @@ func TestReadCmd_ErrorUnreadableFile(t *testing.T) {
if result.Error == nil { if result.Error == nil {
t.Error("Expected command to fail due to unknown file") t.Error("Expected command to fail due to unknown file")
} }
expectedOutput := `open fake-unknown: no such file or directory` var expectedOutput string
if runtime.GOOS == "windows" {
expectedOutput = `open fake-unknown: The system cannot find the file specified.`
} else {
expectedOutput = `open fake-unknown: no such file or directory`
}
assertResult(t, expectedOutput, result.Error.Error()) assertResult(t, expectedOutput, result.Error.Error())
} }
@@ -301,7 +318,7 @@ func TestReadCmd_ErrorBadPath(t *testing.T) {
if result.Error == nil { if result.Error == nil {
t.Fatal("Expected command to fail due to invalid path") t.Fatal("Expected command to fail due to invalid path")
} }
expectedOutput := `Error reading path in document index 0: Error accessing array: strconv.ParseInt: parsing "x": invalid syntax` expectedOutput := `Error reading path in document index 0: error accessing array: strconv.ParseInt: parsing "x": invalid syntax`
assertResult(t, expectedOutput, result.Error.Error()) assertResult(t, expectedOutput, result.Error.Error())
} }
@@ -368,12 +385,11 @@ func TestPrefixCmdArray(t *testing.T) {
defer removeTempYamlFile(filename) defer removeTempYamlFile(filename)
cmd := getRootCommand() 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 { if result.Error != nil {
t.Error(result.Error) t.Error(result.Error)
} }
expectedOutput := `- d: expectedOutput := `- d:
- null
- b: - b:
c: 3 c: 3
` `
@@ -451,7 +467,7 @@ func TestPrefixBadDocumentIndexCmd(t *testing.T) {
if result.Error == nil { if result.Error == nil {
t.Error("Expected command to fail due to invalid path") t.Error("Expected command to fail due to invalid path")
} }
expectedOutput := `Asked to process document index 1 but there are only 1 document(s)` expectedOutput := `asked to process document index 1 but there are only 1 document(s)`
assertResult(t, expectedOutput, result.Error.Error()) assertResult(t, expectedOutput, result.Error.Error())
} }
func TestPrefixMultiAllCmd(t *testing.T) { func TestPrefixMultiAllCmd(t *testing.T) {
@@ -493,7 +509,12 @@ func TestPrefixCmd_ErrorUnreadableFile(t *testing.T) {
if result.Error == nil { if result.Error == nil {
t.Error("Expected command to fail due to unknown file") t.Error("Expected command to fail due to unknown file")
} }
expectedOutput := `open fake-unknown: no such file or directory` var expectedOutput string
if runtime.GOOS == "windows" {
expectedOutput = `open fake-unknown: The system cannot find the file specified.`
} else {
expectedOutput = `open fake-unknown: no such file or directory`
}
assertResult(t, expectedOutput, result.Error.Error()) assertResult(t, expectedOutput, result.Error.Error())
} }
@@ -636,7 +657,7 @@ func TestWriteBadDocumentIndexCmd(t *testing.T) {
if result.Error == nil { if result.Error == nil {
t.Error("Expected command to fail due to invalid path") t.Error("Expected command to fail due to invalid path")
} }
expectedOutput := `Asked to process document index 1 but there are only 1 document(s)` expectedOutput := `asked to process document index 1 but there are only 1 document(s)`
assertResult(t, expectedOutput, result.Error.Error()) assertResult(t, expectedOutput, result.Error.Error())
} }
func TestWriteMultiAllCmd(t *testing.T) { func TestWriteMultiAllCmd(t *testing.T) {
@@ -693,7 +714,12 @@ func TestWriteCmd_ErrorUnreadableFile(t *testing.T) {
if result.Error == nil { if result.Error == nil {
t.Error("Expected command to fail due to unknown file") t.Error("Expected command to fail due to unknown file")
} }
expectedOutput := `open fake-unknown: no such file or directory` var expectedOutput string
if runtime.GOOS == "windows" {
expectedOutput = `open fake-unknown: The system cannot find the file specified.`
} else {
expectedOutput = `open fake-unknown: no such file or directory`
}
assertResult(t, expectedOutput, result.Error.Error()) assertResult(t, expectedOutput, result.Error.Error())
} }
@@ -759,7 +785,7 @@ func TestWriteCmd_AppendEmptyArray(t *testing.T) {
defer removeTempYamlFile(filename) defer removeTempYamlFile(filename)
cmd := getRootCommand() 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 { if result.Error != nil {
t.Error(result.Error) t.Error(result.Error)
} }
@@ -770,6 +796,66 @@ b:
assertResult(t, expectedOutput, result.Output) 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) { func TestDeleteYaml(t *testing.T) {
content := `a: 2 content := `a: 2
b: b:
@@ -792,6 +878,102 @@ b:
assertResult(t, expectedOutput, result.Output) 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) { func TestDeleteYamlArray(t *testing.T) {
content := `- 1 content := `- 1
- 2 - 2
@@ -1019,7 +1201,12 @@ func TestMergeCmd_ErrorUnreadableFile(t *testing.T) {
if result.Error == nil { if result.Error == nil {
t.Error("Expected command to fail due to unknown file") t.Error("Expected command to fail due to unknown file")
} }
expectedOutput := `Error updating document at index 0: open fake-unknown: no such file or directory` var expectedOutput string
if runtime.GOOS == "windows" {
expectedOutput = `Error updating document at index 0: open fake-unknown: The system cannot find the file specified.`
} else {
expectedOutput = `Error updating document at index 0: open fake-unknown: no such file or directory`
}
assertResult(t, expectedOutput, result.Error.Error()) assertResult(t, expectedOutput, result.Error.Error())
} }
@@ -1063,3 +1250,17 @@ c:
assertResult(t, expectedOutput, strings.Trim(gotOutput, "\n ")) assertResult(t, expectedOutput, strings.Trim(gotOutput, "\n "))
assertResult(t, os.FileMode(int(0666)), info.Mode()) assertResult(t, os.FileMode(int(0666)), info.Mode())
} }
func TestMergeAllowEmptyCmd(t *testing.T) {
cmd := getRootCommand()
result := runCmd(cmd, "merge --allow-empty examples/data1.yaml examples/empty.yaml")
if result.Error != nil {
t.Error(result.Error)
}
expectedOutput := `a: simple
b:
- 1
- 2
`
assertResult(t, expectedOutput, result.Output)
}

View File

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

View File

@@ -4,8 +4,6 @@ import (
"fmt" "fmt"
"sort" "sort"
"testing" "testing"
yaml "gopkg.in/mikefarah/yaml.v2"
) )
func TestReadMap_simple(t *testing.T) { func TestReadMap_simple(t *testing.T) {
@@ -18,18 +16,37 @@ b:
assertResult(t, 2, got) 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) { func TestReadMap_splat(t *testing.T) {
var data = parseData(` var data = parseData(`
--- ---
mapSplat: mapSplat:
item1: things item1: things
item2: whatever item2: whatever
otherThing: cat
`) `)
res, _ := readMap(data, "mapSplat", []string{"*"}) res, _ := readMap(data, "mapSplat", []string{"*"})
result := res.([]interface{}) assertResult(t, "[things whatever cat]", fmt.Sprintf("%v", res))
var actual = []string{result[0].(string), result[1].(string)} }
sort.Strings(actual)
assertResult(t, "[things whatever]", fmt.Sprintf("%v", actual)) 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) { func TestReadMap_deep_splat(t *testing.T) {
@@ -92,7 +109,7 @@ b:
if err == nil { if err == nil {
t.Fatal("Expected error due to invalid path") t.Fatal("Expected error due to invalid path")
} }
expectedOutput := `Error accessing array: strconv.ParseInt: parsing "x": invalid syntax` expectedOutput := `error accessing array: strconv.ParseInt: parsing "x": invalid syntax`
assertResult(t, expectedOutput, err.Error()) assertResult(t, expectedOutput, err.Error())
} }
@@ -112,7 +129,7 @@ b:
if err == nil { if err == nil {
t.Fatal("Expected error due to invalid path") t.Fatal("Expected error due to invalid path")
} }
expectedOutput := `Error accessing array: strconv.ParseInt: parsing "x": invalid syntax` expectedOutput := `error accessing array: strconv.ParseInt: parsing "x": invalid syntax`
assertResult(t, expectedOutput, err.Error()) assertResult(t, expectedOutput, err.Error())
} }
@@ -132,7 +149,7 @@ b:
if err == nil { if err == nil {
t.Fatal("Expected error due to invalid path") t.Fatal("Expected error due to invalid path")
} }
expectedOutput := `Error accessing array: strconv.ParseInt: parsing "x": invalid syntax` expectedOutput := `error accessing array: strconv.ParseInt: parsing "x": invalid syntax`
assertResult(t, expectedOutput, err.Error()) assertResult(t, expectedOutput, err.Error())
} }
@@ -180,8 +197,7 @@ func TestWrite_really_simple(t *testing.T) {
`) `)
updated := writeMap(data, []string{"b"}, "4") updated := writeMap(data, []string{"b"}, "4")
b := entryInSlice(updated, "b").Value assertResult(t, "[{b 4}]", fmt.Sprintf("%v", updated))
assertResult(t, "4", b)
} }
func TestWrite_simple(t *testing.T) { func TestWrite_simple(t *testing.T) {
@@ -191,9 +207,7 @@ b:
`) `)
updated := writeMap(data, []string{"b", "c"}, "4") updated := writeMap(data, []string{"b", "c"}, "4")
b := entryInSlice(updated, "b").Value.(yaml.MapSlice) assertResult(t, "[{b [{c 4}]}]", fmt.Sprintf("%v", updated))
c := entryInSlice(b, "c").Value
assertResult(t, "4", c)
} }
func TestWrite_new(t *testing.T) { func TestWrite_new(t *testing.T) {
@@ -203,9 +217,7 @@ b:
`) `)
updated := writeMap(data, []string{"b", "d"}, "4") updated := writeMap(data, []string{"b", "d"}, "4")
b := entryInSlice(updated, "b").Value.(yaml.MapSlice) assertResult(t, "[{b [{c 2} {d 4}]}]", fmt.Sprintf("%v", updated))
d := entryInSlice(b, "d").Value
assertResult(t, "4", d)
} }
func TestWrite_new_deep(t *testing.T) { func TestWrite_new_deep(t *testing.T) {
@@ -215,8 +227,7 @@ b:
`) `)
updated := writeMap(data, []string{"b", "d", "f"}, "4") updated := writeMap(data, []string{"b", "d", "f"}, "4")
got, _ := readMap(updated, "b", []string{"d", "f"}) assertResult(t, "[{b [{c 2} {d [{f 4}]}]}]", fmt.Sprintf("%v", updated))
assertResult(t, "4", got)
} }
func TestWrite_array(t *testing.T) { func TestWrite_array(t *testing.T) {
@@ -227,8 +238,7 @@ b:
updated := writeMap(data, []string{"b", "0"}, "bb") updated := writeMap(data, []string{"b", "0"}, "bb")
b := entryInSlice(updated, "b").Value.([]interface{}) assertResult(t, "[{b [bb]}]", fmt.Sprintf("%v", updated))
assertResult(t, "bb", b[0].(string))
} }
func TestWrite_new_array(t *testing.T) { func TestWrite_new_array(t *testing.T) {
@@ -238,20 +248,19 @@ b:
`) `)
updated := writeMap(data, []string{"b", "0"}, "4") updated := writeMap(data, []string{"b", "0"}, "4")
got, _ := readMap(updated, "b", []string{"0"}) assertResult(t, "[{b [{c 2} {0 4}]}]", fmt.Sprintf("%v", updated))
assertResult(t, "4", got)
} }
func TestWrite_new_array_deep(t *testing.T) { func TestWrite_new_array_deep(t *testing.T) {
var data = parseData(` var data = parseData(`
b: a: apple
c: 2
`) `)
var expected = `b: var expected = `a: apple
b:
- c: "4"` - c: "4"`
updated := writeMap(data, []string{"b", "0", "c"}, "4") updated := writeMap(data, []string{"b", "+", "c"}, "4")
got, _ := yamlToString(updated) got, _ := yamlToString(updated)
assertResult(t, expected, got) assertResult(t, expected, got)
} }
@@ -261,10 +270,14 @@ func TestWrite_new_map_array_deep(t *testing.T) {
b: b:
c: 2 c: 2
`) `)
var expected = `b:
c: 2
d:
- "4"`
updated := writeMap(data, []string{"b", "d", "0"}, "4") updated := writeMap(data, []string{"b", "d", "+"}, "4")
got, _ := readMap(updated, "b", []string{"d", "0"}) got, _ := yamlToString(updated)
assertResult(t, "4", got) assertResult(t, expected, got)
} }
func TestWrite_add_to_array(t *testing.T) { func TestWrite_add_to_array(t *testing.T) {
@@ -289,8 +302,7 @@ b:
`) `)
updated := writeMap(data, []string{"b"}, "4") updated := writeMap(data, []string{"b"}, "4")
b := entryInSlice(updated, "b").Value assertResult(t, "[{b 4}]", fmt.Sprintf("%v", updated))
assertResult(t, "4", fmt.Sprintf("%v", b))
} }
func TestWriteMap_no_paths(t *testing.T) { func TestWriteMap_no_paths(t *testing.T) {
@@ -318,7 +330,7 @@ b: 456
b: 456 b: 456
`) `)
result := deleteMap(data, []string{"a"}) result, _ := deleteMap(data, []string{"a"})
assertResult(t, fmt.Sprintf("%v", expected), fmt.Sprintf("%v", result)) 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(` var data = parseData(`
a: mystring a: mystring
`) `)
result := deleteMap(data, []string{"a", "0"}) result, _ := deleteMap(data, []string{"a", "0"})
assertResult(t, fmt.Sprintf("%v", data), fmt.Sprintf("%v", result)) assertResult(t, fmt.Sprintf("%v", data), fmt.Sprintf("%v", result))
} }
@@ -338,7 +350,7 @@ a: [3, 4]
var expected = parseData(` var expected = parseData(`
a: [3] a: [3]
`) `)
result := deleteMap(data, []string{"a", "1"}) result, _ := deleteMap(data, []string{"a", "1"})
assertResult(t, fmt.Sprintf("%v", expected), fmt.Sprintf("%v", result)) 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(` var data = parseData(`
a: [3, 4] 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)) 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(` var data = parseData(`
a: [3, 4] 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)) assertResult(t, fmt.Sprintf("%v", data), fmt.Sprintf("%v", result))
} }
@@ -364,7 +376,7 @@ a: [3, 4]
b: b:
- name: test - name: test
`) `)
result := deleteMap(data, []string{}) result, _ := deleteMap(data, []string{})
assertResult(t, fmt.Sprintf("%v", data), fmt.Sprintf("%v", result)) assertResult(t, fmt.Sprintf("%v", data), fmt.Sprintf("%v", result))
} }
@@ -382,6 +394,6 @@ b:
- name: john - name: john
value: test 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)) assertResult(t, fmt.Sprintf("%v", expected), fmt.Sprintf("%v", result))
} }

12
debian/changelog vendored
View File

@@ -1,3 +1,15 @@
yq (2.2-1) bionic; urgency=medium
* Added Windows support for the "--inplace" command flag
* Prefix now supports arrays
* Add prefix command
* Bump Alpine version to 3.8
* Improved docker build process
* Lint fixes
* Build support for all linux architectures supported by gox
-- Roberto Mier Escandon <rmescandon@gmail.com> Sat, 19 Jan 2019 15:50:47 +0100
yq (2.1-0) bionic; urgency=medium yq (2.1-0) bionic; urgency=medium
* Ability to read multiple documents in a single file * Ability to read multiple documents in a single file

2
debian/control vendored
View File

@@ -12,7 +12,7 @@ Vcs-Browser: https://github.com/mikefarah/yq.git
Vcs-Git: https://github.com/mikefarah/yq.git Vcs-Git: https://github.com/mikefarah/yq.git
Package: yq Package: yq
Architecture: all Architecture: any
Built-Using: ${misc:Built-Using} Built-Using: ${misc:Built-Using}
Depends: ${shlibs:Depends}, Depends: ${shlibs:Depends},
${misc:Depends} ${misc:Depends}

View File

@@ -2,7 +2,7 @@
<!DOCTYPE html> <!doctype html>
<html lang="en" class="no-js"> <html lang="en" class="no-js">
<head> <head>
@@ -32,7 +32,7 @@
<meta name="lang:search.tokenizer" content="[\s\-]+"> <meta name="lang:search.tokenizer" content="[\s\-]+">
<link rel="shortcut icon" href="/assets/images/favicon.png"> <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> </head>
<body dir="ltr"> <body dir="ltr">
@@ -108,21 +111,18 @@
<div class="md-flex__cell md-flex__cell--stretch"> <div class="md-flex__cell md-flex__cell--stretch">
<div class="md-flex__ellipsis md-header-nav__title" data-md-component="title"> <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 class="md-header-nav__topic"> </span>
Yq
</span>
<span class="md-header-nav__topic">
</span>
</div> </div>
</div> </div>
<div class="md-flex__cell md-flex__cell--shrink"> <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"> <div class="md-search" data-md-component="search" role="dialog">
<label class="md-search__overlay" for="__search"></label> <label class="md-search__overlay" for="__search"></label>
@@ -147,7 +147,6 @@
</div> </div>
</div> </div>
</div> </div>
<div class="md-flex__cell md-flex__cell--shrink"> <div class="md-flex__cell md-flex__cell--shrink">
@@ -157,20 +156,18 @@
<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">
<div class="md-source__icon"> <use xlink:href="#__github" width="24" height="24"></use>
<svg viewBox="0 0 24 24" width="24" height="24"> </svg>
<use xlink:href="#__github" width="24" height="24"></use>
</svg>
</div>
<div class="md-source__repository">
mikefarah/yq
</div> </div>
</a>
<div class="md-source__repository">
mikefarah/yq
</div>
</a>
</div> </div>
</div> </div>
@@ -206,20 +203,18 @@
<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">
<div class="md-source__icon"> <use xlink:href="#__github" width="24" height="24"></use>
<svg viewBox="0 0 24 24" width="24" height="24"> </svg>
<use xlink:href="#__github" width="24" height="24"></use>
</svg>
</div>
<div class="md-source__repository">
mikefarah/yq
</div> </div>
</a>
<div class="md-source__repository">
mikefarah/yq
</div>
</a>
</div> </div>
<ul class="md-nav__list" data-md-scrollfix> <ul class="md-nav__list" data-md-scrollfix>
@@ -357,7 +352,6 @@
Material for MkDocs</a> Material for MkDocs</a>
</div> </div>
<div class="md-footer-social"> <div class="md-footer-social">
<link rel="stylesheet" href="/assets/fonts/font-awesome.css"> <link rel="stylesheet" href="/assets/fonts/font-awesome.css">
@@ -367,20 +361,16 @@
</div> </div>
</div> </div>
</div> </div>
</footer> </footer>
</div> </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> <script>app.initialize({version:"1.0.4",url:{base:"/"}})</script>
</body> </body>
</html> </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"> <html lang="en" class="no-js">
<head> <head>
@@ -32,7 +32,7 @@
<meta name="lang:search.tokenizer" content="[\s\-]+"> <meta name="lang:search.tokenizer" content="[\s\-]+">
<link rel="shortcut icon" href="../assets/images/favicon.png"> <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> </head>
<body dir="ltr"> <body dir="ltr">
@@ -112,21 +115,18 @@
<div class="md-flex__cell md-flex__cell--stretch"> <div class="md-flex__cell md-flex__cell--stretch">
<div class="md-flex__ellipsis md-header-nav__title" data-md-component="title"> <div class="md-flex__ellipsis md-header-nav__title" data-md-component="title">
<span class="md-header-nav__topic">
<span class="md-header-nav__topic"> Yq
Yq </span>
</span> <span class="md-header-nav__topic">
<span class="md-header-nav__topic"> Convert
Convert </span>
</span>
</div> </div>
</div> </div>
<div class="md-flex__cell md-flex__cell--shrink"> <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"> <div class="md-search" data-md-component="search" role="dialog">
<label class="md-search__overlay" for="__search"></label> <label class="md-search__overlay" for="__search"></label>
@@ -151,7 +151,6 @@
</div> </div>
</div> </div>
</div> </div>
<div class="md-flex__cell md-flex__cell--shrink"> <div class="md-flex__cell md-flex__cell--shrink">
@@ -161,20 +160,18 @@
<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">
<div class="md-source__icon"> <use xlink:href="#__github" width="24" height="24"></use>
<svg viewBox="0 0 24 24" width="24" height="24"> </svg>
<use xlink:href="#__github" width="24" height="24"></use>
</svg>
</div>
<div class="md-source__repository">
mikefarah/yq
</div> </div>
</a>
<div class="md-source__repository">
mikefarah/yq
</div>
</a>
</div> </div>
</div> </div>
@@ -210,20 +207,18 @@
<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">
<div class="md-source__icon"> <use xlink:href="#__github" width="24" height="24"></use>
<svg viewBox="0 0 24 24" width="24" height="24"> </svg>
<use xlink:href="#__github" width="24" height="24"></use>
</svg>
</div>
<div class="md-source__repository">
mikefarah/yq
</div> </div>
</a>
<div class="md-source__repository">
mikefarah/yq
</div>
</a>
</div> </div>
<ul class="md-nav__list" data-md-scrollfix> <ul class="md-nav__list" data-md-scrollfix>
@@ -514,7 +509,6 @@ b:
Material for MkDocs</a> Material for MkDocs</a>
</div> </div>
<div class="md-footer-social"> <div class="md-footer-social">
<link rel="stylesheet" href="../assets/fonts/font-awesome.css"> <link rel="stylesheet" href="../assets/fonts/font-awesome.css">
@@ -524,20 +518,16 @@ b:
</div> </div>
</div> </div>
</div> </div>
</footer> </footer>
</div> </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> <script>app.initialize({version:"1.0.4",url:{base:".."}})</script>
</body> </body>
</html> </html>

View File

@@ -2,7 +2,7 @@
<!DOCTYPE html> <!doctype html>
<html lang="en" class="no-js"> <html lang="en" class="no-js">
<head> <head>
@@ -32,7 +32,7 @@
<meta name="lang:search.tokenizer" content="[\s\-]+"> <meta name="lang:search.tokenizer" content="[\s\-]+">
<link rel="shortcut icon" href="../assets/images/favicon.png"> <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> </head>
<body dir="ltr"> <body dir="ltr">
@@ -112,21 +115,18 @@
<div class="md-flex__cell md-flex__cell--stretch"> <div class="md-flex__cell md-flex__cell--stretch">
<div class="md-flex__ellipsis md-header-nav__title" data-md-component="title"> <div class="md-flex__ellipsis md-header-nav__title" data-md-component="title">
<span class="md-header-nav__topic">
<span class="md-header-nav__topic"> Yq
Yq </span>
</span> <span class="md-header-nav__topic">
<span class="md-header-nav__topic"> Create
Create </span>
</span>
</div> </div>
</div> </div>
<div class="md-flex__cell md-flex__cell--shrink"> <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"> <div class="md-search" data-md-component="search" role="dialog">
<label class="md-search__overlay" for="__search"></label> <label class="md-search__overlay" for="__search"></label>
@@ -151,7 +151,6 @@
</div> </div>
</div> </div>
</div> </div>
<div class="md-flex__cell md-flex__cell--shrink"> <div class="md-flex__cell md-flex__cell--shrink">
@@ -161,20 +160,18 @@
<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">
<div class="md-source__icon"> <use xlink:href="#__github" width="24" height="24"></use>
<svg viewBox="0 0 24 24" width="24" height="24"> </svg>
<use xlink:href="#__github" width="24" height="24"></use>
</svg>
</div>
<div class="md-source__repository">
mikefarah/yq
</div> </div>
</a>
<div class="md-source__repository">
mikefarah/yq
</div>
</a>
</div> </div>
</div> </div>
@@ -210,20 +207,18 @@
<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">
<div class="md-source__icon"> <use xlink:href="#__github" width="24" height="24"></use>
<svg viewBox="0 0 24 24" width="24" height="24"> </svg>
<use xlink:href="#__github" width="24" height="24"></use>
</svg>
</div>
<div class="md-source__repository">
mikefarah/yq
</div> </div>
</a>
<div class="md-source__repository">
mikefarah/yq
</div>
</a>
</div> </div>
<ul class="md-nav__list" data-md-scrollfix> <ul class="md-nav__list" data-md-scrollfix>
@@ -337,6 +332,13 @@
</li> </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>
<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>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> <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> Material for MkDocs</a>
</div> </div>
<div class="md-footer-social"> <div class="md-footer-social">
<link rel="stylesheet" href="../assets/fonts/font-awesome.css"> <link rel="stylesheet" href="../assets/fonts/font-awesome.css">
@@ -554,20 +571,16 @@ b.e[0].name: Howdy Partner
</div> </div>
</div> </div>
</div> </div>
</footer> </footer>
</div> </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> <script>app.initialize({version:"1.0.4",url:{base:".."}})</script>
</body> </body>
</html> </html>

View File

@@ -2,7 +2,7 @@
<!DOCTYPE html> <!doctype html>
<html lang="en" class="no-js"> <html lang="en" class="no-js">
<head> <head>
@@ -32,7 +32,7 @@
<meta name="lang:search.tokenizer" content="[\s\-]+"> <meta name="lang:search.tokenizer" content="[\s\-]+">
<link rel="shortcut icon" href="../assets/images/favicon.png"> <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> </head>
<body dir="ltr"> <body dir="ltr">
@@ -112,21 +115,18 @@
<div class="md-flex__cell md-flex__cell--stretch"> <div class="md-flex__cell md-flex__cell--stretch">
<div class="md-flex__ellipsis md-header-nav__title" data-md-component="title"> <div class="md-flex__ellipsis md-header-nav__title" data-md-component="title">
<span class="md-header-nav__topic">
<span class="md-header-nav__topic"> Yq
Yq </span>
</span> <span class="md-header-nav__topic">
<span class="md-header-nav__topic"> Delete
Delete </span>
</span>
</div> </div>
</div> </div>
<div class="md-flex__cell md-flex__cell--shrink"> <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"> <div class="md-search" data-md-component="search" role="dialog">
<label class="md-search__overlay" for="__search"></label> <label class="md-search__overlay" for="__search"></label>
@@ -151,7 +151,6 @@
</div> </div>
</div> </div>
</div> </div>
<div class="md-flex__cell md-flex__cell--shrink"> <div class="md-flex__cell md-flex__cell--shrink">
@@ -161,20 +160,18 @@
<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">
<div class="md-source__icon"> <use xlink:href="#__github" width="24" height="24"></use>
<svg viewBox="0 0 24 24" width="24" height="24"> </svg>
<use xlink:href="#__github" width="24" height="24"></use>
</svg>
</div>
<div class="md-source__repository">
mikefarah/yq
</div> </div>
</a>
<div class="md-source__repository">
mikefarah/yq
</div>
</a>
</div> </div>
</div> </div>
@@ -210,20 +207,18 @@
<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">
<div class="md-source__icon"> <use xlink:href="#__github" width="24" height="24"></use>
<svg viewBox="0 0 24 24" width="24" height="24"> </svg>
<use xlink:href="#__github" width="24" height="24"></use>
</svg>
</div>
<div class="md-source__repository">
mikefarah/yq
</div> </div>
</a>
<div class="md-source__repository">
mikefarah/yq
</div>
</a>
</div> </div>
<ul class="md-nav__list" data-md-scrollfix> <ul class="md-nav__list" data-md-scrollfix>
@@ -353,6 +348,13 @@
</li> </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>
<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>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> <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> Material for MkDocs</a>
</div> </div>
<div class="md-footer-social"> <div class="md-footer-social">
<link rel="stylesheet" href="../assets/fonts/font-awesome.css"> <link rel="stylesheet" href="../assets/fonts/font-awesome.css">
@@ -674,20 +691,16 @@ b:
</div> </div>
</div> </div>
</div> </div>
</footer> </footer>
</div> </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> <script>app.initialize({version:"1.0.4",url:{base:".."}})</script>
</body> </body>
</html> </html>

View File

@@ -2,7 +2,7 @@
<!DOCTYPE html> <!doctype html>
<html lang="en" class="no-js"> <html lang="en" class="no-js">
<head> <head>
@@ -32,7 +32,7 @@
<meta name="lang:search.tokenizer" content="[\s\-]+"> <meta name="lang:search.tokenizer" content="[\s\-]+">
<link rel="shortcut icon" href="assets/images/favicon.png"> <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> </head>
<body dir="ltr"> <body dir="ltr">
@@ -112,21 +115,18 @@
<div class="md-flex__cell md-flex__cell--stretch"> <div class="md-flex__cell md-flex__cell--stretch">
<div class="md-flex__ellipsis md-header-nav__title" data-md-component="title"> <div class="md-flex__ellipsis md-header-nav__title" data-md-component="title">
<span class="md-header-nav__topic">
<span class="md-header-nav__topic"> Yq
Yq </span>
</span> <span class="md-header-nav__topic">
<span class="md-header-nav__topic"> Install
Install </span>
</span>
</div> </div>
</div> </div>
<div class="md-flex__cell md-flex__cell--shrink"> <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"> <div class="md-search" data-md-component="search" role="dialog">
<label class="md-search__overlay" for="__search"></label> <label class="md-search__overlay" for="__search"></label>
@@ -151,7 +151,6 @@
</div> </div>
</div> </div>
</div> </div>
<div class="md-flex__cell md-flex__cell--shrink"> <div class="md-flex__cell md-flex__cell--shrink">
@@ -161,20 +160,18 @@
<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">
<div class="md-source__icon"> <use xlink:href="#__github" width="24" height="24"></use>
<svg viewBox="0 0 24 24" width="24" height="24"> </svg>
<use xlink:href="#__github" width="24" height="24"></use>
</svg>
</div>
<div class="md-source__repository">
mikefarah/yq
</div> </div>
</a>
<div class="md-source__repository">
mikefarah/yq
</div>
</a>
</div> </div>
</div> </div>
@@ -210,20 +207,18 @@
<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">
<div class="md-source__icon"> <use xlink:href="#__github" width="24" height="24"></use>
<svg viewBox="0 0 24 24" width="24" height="24"> </svg>
<use xlink:href="#__github" width="24" height="24"></use>
</svg>
</div>
<div class="md-source__repository">
mikefarah/yq
</div> </div>
</a>
<div class="md-source__repository">
mikefarah/yq
</div>
</a>
</div> </div>
<ul class="md-nav__list" data-md-scrollfix> <ul class="md-nav__list" data-md-scrollfix>
@@ -480,7 +475,6 @@ sudo apt install yq -y
Material for MkDocs</a> Material for MkDocs</a>
</div> </div>
<div class="md-footer-social"> <div class="md-footer-social">
<link rel="stylesheet" href="assets/fonts/font-awesome.css"> <link rel="stylesheet" href="assets/fonts/font-awesome.css">
@@ -490,20 +484,16 @@ sudo apt install yq -y
</div> </div>
</div> </div>
</div> </div>
</footer> </footer>
</div> </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> <script>app.initialize({version:"1.0.4",url:{base:"."}})</script>
</body> </body>
</html> </html>

View File

@@ -2,7 +2,7 @@
<!DOCTYPE html> <!doctype html>
<html lang="en" class="no-js"> <html lang="en" class="no-js">
<head> <head>
@@ -32,7 +32,7 @@
<meta name="lang:search.tokenizer" content="[\s\-]+"> <meta name="lang:search.tokenizer" content="[\s\-]+">
<link rel="shortcut icon" href="../assets/images/favicon.png"> <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> </head>
<body dir="ltr"> <body dir="ltr">
@@ -112,21 +115,18 @@
<div class="md-flex__cell md-flex__cell--stretch"> <div class="md-flex__cell md-flex__cell--stretch">
<div class="md-flex__ellipsis md-header-nav__title" data-md-component="title"> <div class="md-flex__ellipsis md-header-nav__title" data-md-component="title">
<span class="md-header-nav__topic">
<span class="md-header-nav__topic"> Yq
Yq </span>
</span> <span class="md-header-nav__topic">
<span class="md-header-nav__topic"> Merge
Merge </span>
</span>
</div> </div>
</div> </div>
<div class="md-flex__cell md-flex__cell--shrink"> <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"> <div class="md-search" data-md-component="search" role="dialog">
<label class="md-search__overlay" for="__search"></label> <label class="md-search__overlay" for="__search"></label>
@@ -151,7 +151,6 @@
</div> </div>
</div> </div>
</div> </div>
<div class="md-flex__cell md-flex__cell--shrink"> <div class="md-flex__cell md-flex__cell--shrink">
@@ -161,20 +160,18 @@
<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">
<div class="md-source__icon"> <use xlink:href="#__github" width="24" height="24"></use>
<svg viewBox="0 0 24 24" width="24" height="24"> </svg>
<use xlink:href="#__github" width="24" height="24"></use>
</svg>
</div>
<div class="md-source__repository">
mikefarah/yq
</div> </div>
</a>
<div class="md-source__repository">
mikefarah/yq
</div>
</a>
</div> </div>
</div> </div>
@@ -210,20 +207,18 @@
<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">
<div class="md-source__icon"> <use xlink:href="#__github" width="24" height="24"></use>
<svg viewBox="0 0 24 24" width="24" height="24"> </svg>
<use xlink:href="#__github" width="24" height="24"></use>
</svg>
</div>
<div class="md-source__repository">
mikefarah/yq
</div> </div>
</a>
<div class="md-source__repository">
mikefarah/yq
</div>
</a>
</div> </div>
<ul class="md-nav__list" data-md-scrollfix> <ul class="md-nav__list" data-md-scrollfix>
@@ -711,7 +706,6 @@ b: dog
Material for MkDocs</a> Material for MkDocs</a>
</div> </div>
<div class="md-footer-social"> <div class="md-footer-social">
<link rel="stylesheet" href="../assets/fonts/font-awesome.css"> <link rel="stylesheet" href="../assets/fonts/font-awesome.css">
@@ -721,20 +715,16 @@ b: dog
</div> </div>
</div> </div>
</div> </div>
</footer> </footer>
</div> </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> <script>app.initialize({version:"1.0.4",url:{base:".."}})</script>
</body> </body>
</html> </html>

View File

@@ -2,7 +2,7 @@
<!DOCTYPE html> <!doctype html>
<html lang="en" class="no-js"> <html lang="en" class="no-js">
<head> <head>
@@ -32,7 +32,7 @@
<meta name="lang:search.tokenizer" content="[\s\-]+"> <meta name="lang:search.tokenizer" content="[\s\-]+">
<link rel="shortcut icon" href="../assets/images/favicon.png"> <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> </head>
<body dir="ltr"> <body dir="ltr">
@@ -112,21 +115,18 @@
<div class="md-flex__cell md-flex__cell--stretch"> <div class="md-flex__cell md-flex__cell--stretch">
<div class="md-flex__ellipsis md-header-nav__title" data-md-component="title"> <div class="md-flex__ellipsis md-header-nav__title" data-md-component="title">
<span class="md-header-nav__topic">
<span class="md-header-nav__topic"> Yq
Yq </span>
</span> <span class="md-header-nav__topic">
<span class="md-header-nav__topic"> Prefix
Prefix </span>
</span>
</div> </div>
</div> </div>
<div class="md-flex__cell md-flex__cell--shrink"> <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"> <div class="md-search" data-md-component="search" role="dialog">
<label class="md-search__overlay" for="__search"></label> <label class="md-search__overlay" for="__search"></label>
@@ -151,7 +151,6 @@
</div> </div>
</div> </div>
</div> </div>
<div class="md-flex__cell md-flex__cell--shrink"> <div class="md-flex__cell md-flex__cell--shrink">
@@ -161,20 +160,18 @@
<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">
<div class="md-source__icon"> <use xlink:href="#__github" width="24" height="24"></use>
<svg viewBox="0 0 24 24" width="24" height="24"> </svg>
<use xlink:href="#__github" width="24" height="24"></use>
</svg>
</div>
<div class="md-source__repository">
mikefarah/yq
</div> </div>
</a>
<div class="md-source__repository">
mikefarah/yq
</div>
</a>
</div> </div>
</div> </div>
@@ -210,20 +207,18 @@
<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">
<div class="md-source__icon"> <use xlink:href="#__github" width="24" height="24"></use>
<svg viewBox="0 0 24 24" width="24" height="24"> </svg>
<use xlink:href="#__github" width="24" height="24"></use>
</svg>
</div>
<div class="md-source__repository">
mikefarah/yq
</div> </div>
</a>
<div class="md-source__repository">
mikefarah/yq
</div>
</a>
</div> </div>
<ul class="md-nav__list" data-md-scrollfix> <ul class="md-nav__list" data-md-scrollfix>
@@ -612,7 +607,6 @@ c:
Material for MkDocs</a> Material for MkDocs</a>
</div> </div>
<div class="md-footer-social"> <div class="md-footer-social">
<link rel="stylesheet" href="../assets/fonts/font-awesome.css"> <link rel="stylesheet" href="../assets/fonts/font-awesome.css">
@@ -622,20 +616,16 @@ c:
</div> </div>
</div> </div>
</div> </div>
</footer> </footer>
</div> </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> <script>app.initialize({version:"1.0.4",url:{base:".."}})</script>
</body> </body>
</html> </html>

View File

@@ -2,7 +2,7 @@
<!DOCTYPE html> <!doctype html>
<html lang="en" class="no-js"> <html lang="en" class="no-js">
<head> <head>
@@ -32,7 +32,7 @@
<meta name="lang:search.tokenizer" content="[\s\-]+"> <meta name="lang:search.tokenizer" content="[\s\-]+">
<link rel="shortcut icon" href="../assets/images/favicon.png"> <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> </head>
<body dir="ltr"> <body dir="ltr">
@@ -112,21 +115,18 @@
<div class="md-flex__cell md-flex__cell--stretch"> <div class="md-flex__cell md-flex__cell--stretch">
<div class="md-flex__ellipsis md-header-nav__title" data-md-component="title"> <div class="md-flex__ellipsis md-header-nav__title" data-md-component="title">
<span class="md-header-nav__topic">
<span class="md-header-nav__topic"> Yq
Yq </span>
</span> <span class="md-header-nav__topic">
<span class="md-header-nav__topic"> Read
Read </span>
</span>
</div> </div>
</div> </div>
<div class="md-flex__cell md-flex__cell--shrink"> <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"> <div class="md-search" data-md-component="search" role="dialog">
<label class="md-search__overlay" for="__search"></label> <label class="md-search__overlay" for="__search"></label>
@@ -151,7 +151,6 @@
</div> </div>
</div> </div>
</div> </div>
<div class="md-flex__cell md-flex__cell--shrink"> <div class="md-flex__cell md-flex__cell--shrink">
@@ -161,20 +160,18 @@
<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">
<div class="md-source__icon"> <use xlink:href="#__github" width="24" height="24"></use>
<svg viewBox="0 0 24 24" width="24" height="24"> </svg>
<use xlink:href="#__github" width="24" height="24"></use>
</svg>
</div>
<div class="md-source__repository">
mikefarah/yq
</div> </div>
</a>
<div class="md-source__repository">
mikefarah/yq
</div>
</a>
</div> </div>
</div> </div>
@@ -210,20 +207,18 @@
<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">
<div class="md-source__icon"> <use xlink:href="#__github" width="24" height="24"></use>
<svg viewBox="0 0 24 24" width="24" height="24"> </svg>
<use xlink:href="#__github" width="24" height="24"></use>
</svg>
</div>
<div class="md-source__repository">
mikefarah/yq
</div> </div>
</a>
<div class="md-source__repository">
mikefarah/yq
</div>
</a>
</div> </div>
<ul class="md-nav__list" data-md-scrollfix> <ul class="md-nav__list" data-md-scrollfix>
@@ -324,6 +319,13 @@
</li> </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>
<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>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> <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> Material for MkDocs</a>
</div> </div>
<div class="md-footer-social"> <div class="md-footer-social">
<link rel="stylesheet" href="../assets/fonts/font-awesome.css"> <link rel="stylesheet" href="../assets/fonts/font-awesome.css">
@@ -702,20 +719,16 @@ e.g.: given a sample file of</p>
</div> </div>
</div> </div>
</div> </div>
</footer> </footer>
</div> </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> <script>app.initialize({version:"1.0.4",url:{base:".."}})</script>
</body> </body>
</html> </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"> <urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">
<url> <url>
<loc>None</loc> <loc>None</loc>
<lastmod>2018-11-19</lastmod> <lastmod>2019-05-14</lastmod>
<changefreq>daily</changefreq> <changefreq>daily</changefreq>
</url> </url>
<url> <url>
<loc>None</loc> <loc>None</loc>
<lastmod>2018-11-19</lastmod> <lastmod>2019-05-14</lastmod>
<changefreq>daily</changefreq> <changefreq>daily</changefreq>
</url> </url>
<url> <url>
<loc>None</loc> <loc>None</loc>
<lastmod>2018-11-19</lastmod> <lastmod>2019-05-14</lastmod>
<changefreq>daily</changefreq> <changefreq>daily</changefreq>
</url> </url>
<url> <url>
<loc>None</loc> <loc>None</loc>
<lastmod>2018-11-19</lastmod> <lastmod>2019-05-14</lastmod>
<changefreq>daily</changefreq> <changefreq>daily</changefreq>
</url> </url>
<url> <url>
<loc>None</loc> <loc>None</loc>
<lastmod>2018-11-19</lastmod> <lastmod>2019-05-14</lastmod>
<changefreq>daily</changefreq> <changefreq>daily</changefreq>
</url> </url>
<url> <url>
<loc>None</loc> <loc>None</loc>
<lastmod>2018-11-19</lastmod> <lastmod>2019-05-14</lastmod>
<changefreq>daily</changefreq> <changefreq>daily</changefreq>
</url> </url>
<url> <url>
<loc>None</loc> <loc>None</loc>
<lastmod>2018-11-19</lastmod> <lastmod>2019-05-14</lastmod>
<changefreq>daily</changefreq> <changefreq>daily</changefreq>
</url> </url>
<url> <url>
<loc>None</loc> <loc>None</loc>
<lastmod>2018-11-19</lastmod> <lastmod>2019-05-14</lastmod>
<changefreq>daily</changefreq> <changefreq>daily</changefreq>
</url> </url>
</urlset> </urlset>

Binary file not shown.

View File

@@ -2,7 +2,7 @@
<!DOCTYPE html> <!doctype html>
<html lang="en" class="no-js"> <html lang="en" class="no-js">
<head> <head>
@@ -32,20 +32,20 @@
<meta name="lang:search.tokenizer" content="[\s\-]+"> <meta name="lang:search.tokenizer" content="[\s\-]+">
<link rel="shortcut icon" href="../../assets/images/favicon.png"> <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> </head>
<body dir="ltr"> <body dir="ltr">
@@ -112,21 +115,18 @@
<div class="md-flex__cell md-flex__cell--stretch"> <div class="md-flex__cell md-flex__cell--stretch">
<div class="md-flex__ellipsis md-header-nav__title" data-md-component="title"> <div class="md-flex__ellipsis md-header-nav__title" data-md-component="title">
<span class="md-header-nav__topic">
<span class="md-header-nav__topic"> Yq
Yq </span>
</span> <span class="md-header-nav__topic">
<span class="md-header-nav__topic"> Niche
Keys with dots </span>
</span>
</div> </div>
</div> </div>
<div class="md-flex__cell md-flex__cell--shrink"> <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"> <div class="md-search" data-md-component="search" role="dialog">
<label class="md-search__overlay" for="__search"></label> <label class="md-search__overlay" for="__search"></label>
@@ -151,7 +151,6 @@
</div> </div>
</div> </div>
</div> </div>
<div class="md-flex__cell md-flex__cell--shrink"> <div class="md-flex__cell md-flex__cell--shrink">
@@ -161,20 +160,18 @@
<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">
<div class="md-source__icon"> <use xlink:href="#__github" width="24" height="24"></use>
<svg viewBox="0 0 24 24" width="24" height="24"> </svg>
<use xlink:href="#__github" width="24" height="24"></use>
</svg>
</div>
<div class="md-source__repository">
mikefarah/yq
</div> </div>
</a>
<div class="md-source__repository">
mikefarah/yq
</div>
</a>
</div> </div>
</div> </div>
@@ -210,20 +207,18 @@
<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">
<div class="md-source__icon"> <use xlink:href="#__github" width="24" height="24"></use>
<svg viewBox="0 0 24 24" width="24" height="24"> </svg>
<use xlink:href="#__github" width="24" height="24"></use>
</svg>
</div>
<div class="md-source__repository">
mikefarah/yq
</div> </div>
</a>
<div class="md-source__repository">
mikefarah/yq
</div>
</a>
</div> </div>
<ul class="md-nav__list" data-md-scrollfix> <ul class="md-nav__list" data-md-scrollfix>
@@ -349,6 +344,13 @@
</li> </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"> <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> <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> <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>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> <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> Material for MkDocs</a>
</div> </div>
<div class="md-footer-social"> <div class="md-footer-social">
<link rel="stylesheet" href="../../assets/fonts/font-awesome.css"> <link rel="stylesheet" href="../../assets/fonts/font-awesome.css">
@@ -422,20 +432,16 @@
</div> </div>
</div> </div>
</div> </div>
</footer> </footer>
</div> </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> <script>app.initialize({version:"1.0.4",url:{base:"../.."}})</script>
</body> </body>
</html> </html>

View File

@@ -2,7 +2,7 @@
<!DOCTYPE html> <!doctype html>
<html lang="en" class="no-js"> <html lang="en" class="no-js">
<head> <head>
@@ -32,7 +32,7 @@
<meta name="lang:search.tokenizer" content="[\s\-]+"> <meta name="lang:search.tokenizer" content="[\s\-]+">
<link rel="shortcut icon" href="../../assets/images/favicon.png"> <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> </head>
<body dir="ltr"> <body dir="ltr">
@@ -108,21 +111,18 @@
<div class="md-flex__cell md-flex__cell--stretch"> <div class="md-flex__cell md-flex__cell--stretch">
<div class="md-flex__ellipsis md-header-nav__title" data-md-component="title"> <div class="md-flex__ellipsis md-header-nav__title" data-md-component="title">
<span class="md-header-nav__topic">
<span class="md-header-nav__topic"> Yq
Yq </span>
</span> <span class="md-header-nav__topic">
<span class="md-header-nav__topic"> Works with json
Works with json </span>
</span>
</div> </div>
</div> </div>
<div class="md-flex__cell md-flex__cell--shrink"> <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"> <div class="md-search" data-md-component="search" role="dialog">
<label class="md-search__overlay" for="__search"></label> <label class="md-search__overlay" for="__search"></label>
@@ -147,7 +147,6 @@
</div> </div>
</div> </div>
</div> </div>
<div class="md-flex__cell md-flex__cell--shrink"> <div class="md-flex__cell md-flex__cell--shrink">
@@ -157,20 +156,18 @@
<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">
<div class="md-source__icon"> <use xlink:href="#__github" width="24" height="24"></use>
<svg viewBox="0 0 24 24" width="24" height="24"> </svg>
<use xlink:href="#__github" width="24" height="24"></use>
</svg>
</div>
<div class="md-source__repository">
mikefarah/yq
</div> </div>
</a>
<div class="md-source__repository">
mikefarah/yq
</div>
</a>
</div> </div>
</div> </div>
@@ -206,20 +203,18 @@
<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">
<div class="md-source__icon"> <use xlink:href="#__github" width="24" height="24"></use>
<svg viewBox="0 0 24 24" width="24" height="24"> </svg>
<use xlink:href="#__github" width="24" height="24"></use>
</svg>
</div>
<div class="md-source__repository">
mikefarah/yq
</div> </div>
</a>
<div class="md-source__repository">
mikefarah/yq
</div>
</a>
</div> </div>
<ul class="md-nav__list" data-md-scrollfix> <ul class="md-nav__list" data-md-scrollfix>
@@ -366,7 +361,6 @@
Material for MkDocs</a> Material for MkDocs</a>
</div> </div>
<div class="md-footer-social"> <div class="md-footer-social">
<link rel="stylesheet" href="../../assets/fonts/font-awesome.css"> <link rel="stylesheet" href="../../assets/fonts/font-awesome.css">
@@ -376,20 +370,16 @@
</div> </div>
</div> </div>
</div> </div>
</footer> </footer>
</div> </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> <script>app.initialize({version:"1.0.4",url:{base:"../.."}})</script>
</body> </body>
</html> </html>

View File

@@ -2,7 +2,7 @@
<!DOCTYPE html> <!doctype html>
<html lang="en" class="no-js"> <html lang="en" class="no-js">
<head> <head>
@@ -32,7 +32,7 @@
<meta name="lang:search.tokenizer" content="[\s\-]+"> <meta name="lang:search.tokenizer" content="[\s\-]+">
<link rel="shortcut icon" href="../assets/images/favicon.png"> <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> </head>
<body dir="ltr"> <body dir="ltr">
@@ -112,21 +115,18 @@
<div class="md-flex__cell md-flex__cell--stretch"> <div class="md-flex__cell md-flex__cell--stretch">
<div class="md-flex__ellipsis md-header-nav__title" data-md-component="title"> <div class="md-flex__ellipsis md-header-nav__title" data-md-component="title">
<span class="md-header-nav__topic">
<span class="md-header-nav__topic"> Yq
Yq </span>
</span> <span class="md-header-nav__topic">
<span class="md-header-nav__topic"> Write/Update
Write/Update </span>
</span>
</div> </div>
</div> </div>
<div class="md-flex__cell md-flex__cell--shrink"> <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"> <div class="md-search" data-md-component="search" role="dialog">
<label class="md-search__overlay" for="__search"></label> <label class="md-search__overlay" for="__search"></label>
@@ -151,7 +151,6 @@
</div> </div>
</div> </div>
</div> </div>
<div class="md-flex__cell md-flex__cell--shrink"> <div class="md-flex__cell md-flex__cell--shrink">
@@ -161,20 +160,18 @@
<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">
<div class="md-source__icon"> <use xlink:href="#__github" width="24" height="24"></use>
<svg viewBox="0 0 24 24" width="24" height="24"> </svg>
<use xlink:href="#__github" width="24" height="24"></use>
</svg>
</div>
<div class="md-source__repository">
mikefarah/yq
</div> </div>
</a>
<div class="md-source__repository">
mikefarah/yq
</div>
</a>
</div> </div>
</div> </div>
@@ -210,20 +207,18 @@
<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">
<div class="md-source__icon"> <use xlink:href="#__github" width="24" height="24"></use>
<svg viewBox="0 0 24 24" width="24" height="24"> </svg>
<use xlink:href="#__github" width="24" height="24"></use>
</svg>
</div>
<div class="md-source__repository">
mikefarah/yq
</div> </div>
</a>
<div class="md-source__repository">
mikefarah/yq
</div>
</a>
</div> </div>
<ul class="md-nav__list" data-md-scrollfix> <ul class="md-nav__list" data-md-scrollfix>
@@ -350,6 +345,13 @@
</li> </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>
<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>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> <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> Material for MkDocs</a>
</div> </div>
<div class="md-footer-social"> <div class="md-footer-social">
<link rel="stylesheet" href="../assets/fonts/font-awesome.css"> <link rel="stylesheet" href="../assets/fonts/font-awesome.css">
@@ -770,20 +787,16 @@ b.e[0].name: Howdy Partner
</div> </div>
</div> </div>
</div> </div>
</footer> </footer>
</div> </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> <script>app.initialize({version:"1.0.4",url:{base:".."}})</script>
</body> </body>
</html> </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

2
examples/empty.yaml Normal file
View File

@@ -0,0 +1,2 @@
# a: apple
# b: cat

View File

@@ -1,2 +1,2 @@
b.c: cat 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

@@ -17,16 +17,16 @@ func jsonToString(context interface{}) (string, error) {
} }
func toJSON(context interface{}) interface{} { func toJSON(context interface{}) interface{} {
switch context.(type) { switch context := context.(type) {
case []interface{}: case []interface{}:
oldArray := context.([]interface{}) oldArray := context
newArray := make([]interface{}, len(oldArray)) newArray := make([]interface{}, len(oldArray))
for index, value := range oldArray { for index, value := range oldArray {
newArray[index] = toJSON(value) newArray[index] = toJSON(value)
} }
return newArray return newArray
case yaml.MapSlice: case yaml.MapSlice:
oldMap := context.(yaml.MapSlice) oldMap := context
newMap := make(map[string]interface{}) newMap := make(map[string]interface{})
for _, entry := range oldMap { for _, entry := range oldMap {
if str, ok := entry.Key.(string); ok { if str, ok := entry.Key.(string); ok {

View File

@@ -1,6 +1,6 @@
package main package main
import "gopkg.in/imdario/mergo.v0" import mergo "gopkg.in/imdario/mergo.v0"
func merge(dst interface{}, src interface{}, overwrite bool, append bool) error { func merge(dst interface{}, src interface{}, overwrite bool, append bool) error {
if overwrite { if overwrite {

View File

@@ -41,4 +41,4 @@ You can also pipe the instructions in:
cat create_instructions.yaml | yq n -s - 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. 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. 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 path: -3
``` ```
{!snippets/keys_with_dots.md!} {!snippets/niche.md!}

View File

@@ -1,5 +1,6 @@
- increment version in version.go - increment version in version.go
- increment version in snapcraft.yaml - increment version in snapcraft.yaml
- commit
- tag git with same version number - tag git with same version number
- be sure to also tag with 'v' for gopkg.in - be sure to also tag with 'v' for gopkg.in
- make sure local build passes - make sure local build passes
@@ -21,11 +22,14 @@
- brew - brew
- brew bump-formula-pr --url=https://github.com/mikefarah/yq/archive/2.1.2.tar.gz yq - 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 - docker
- build and push latest and new version tag - build and push latest and new version tag
- docker build . --arg -t mikefarah/yq:latest -t mikefarah/yq:VERSION - docker build . -t mikefarah/yq:latest -t mikefarah/yq:VERSION
- debian package - debian package
- execute - execute

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

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

View File

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

View File

@@ -1,5 +1,5 @@
name: yq name: yq
version: 2.2.0 version: '2.4.0'
summary: A lightweight and portable command-line YAML processor summary: A lightweight and portable command-line YAML processor
description: | description: |
The aim of the project is to be the jq or sed of yaml files. The aim of the project is to be the jq or sed of yaml files.
@@ -19,4 +19,4 @@ parts:
go-importpath: github.com/mikefarah/yq go-importpath: github.com/mikefarah/yq
after: [go] after: [go]
go: go:
source-tag: go1.9.4 source-tag: go1.11

View File

@@ -10,7 +10,7 @@ import (
"testing" "testing"
yaml "gopkg.in/mikefarah/yaml.v2" yaml "gopkg.in/mikefarah/yaml.v2"
"gopkg.in/spf13/cobra.v0" cobra "gopkg.in/spf13/cobra.v0"
) )
type resulter struct { type resulter struct {

View File

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

29
yq.go
View File

@@ -22,6 +22,7 @@ var writeInplace = false
var writeScript = "" var writeScript = ""
var outputToJSON = false var outputToJSON = false
var overwriteFlag = false var overwriteFlag = false
var allowEmptyFlag = false
var appendFlag = false var appendFlag = false
var verbose = false var verbose = false
var version = false var version = false
@@ -39,7 +40,9 @@ func main() {
func newCommandCLI() *cobra.Command { func newCommandCLI() *cobra.Command {
yaml.DefaultMapType = reflect.TypeOf(yaml.MapSlice{}) yaml.DefaultMapType = reflect.TypeOf(yaml.MapSlice{})
var rootCmd = &cobra.Command{ 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 { RunE: func(cmd *cobra.Command, args []string) error {
if version { if version {
cmd.Print(GetVersionDisplay()) cmd.Print(GetVersionDisplay())
@@ -94,6 +97,7 @@ yq r - a.b.c (reads from stdin)
yq r things.yaml a.*.c yq r things.yaml a.*.c
yq r -d1 things.yaml a.array[0].blah yq r -d1 things.yaml a.array[0].blah
yq r things.yaml a.array[*].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", Long: "Outputs the value of the given path in the yaml file to STDOUT",
RunE: readProperty, RunE: readProperty,
@@ -110,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", Short: "yq w [--inplace/-i] [--script/-s script_file] [--doc/-d index] sample.yaml a.b.c newValue",
Example: ` Example: `
yq write things.yaml a.b.c cat 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 -i things.yaml a.b.c cat
yq w --script update_script.yaml things.yaml yq w --script update_script.yaml things.yaml
yq w -i -s update_script.yaml things.yaml yq w -i -s update_script.yaml things.yaml
@@ -146,6 +150,7 @@ func createPrefixCmd() *cobra.Command {
Example: ` Example: `
yq prefix things.yaml a.b.c yq prefix things.yaml a.b.c
yq prefix --inplace 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 -i things.yaml a.b.c
yq p --doc 2 things.yaml a.b.d yq p --doc 2 things.yaml a.b.d
yq p -d2 things.yaml a.b.d yq p -d2 things.yaml a.b.d
@@ -168,6 +173,7 @@ func createDeleteCmd() *cobra.Command {
Example: ` Example: `
yq delete things.yaml a.b.c yq delete things.yaml a.b.c
yq delete --inplace 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 -i things.yaml a.b.c
yq d things.yaml a.b.c yq d things.yaml a.b.c
`, `,
@@ -189,6 +195,7 @@ func createNewCmd() *cobra.Command {
Example: ` Example: `
yq new a.b.c cat yq new a.b.c cat
yq n a.b.c cat yq n a.b.c cat
yq n -- --key-starting-with-dash cat
yq n --script create_script.yaml yq n --script create_script.yaml
`, `,
Long: `Creates a new yaml w.r.t the given path and value. Long: `Creates a new yaml w.r.t the given path and value.
@@ -229,6 +236,7 @@ Note that if you set both flags only overwrite will take effect.
cmdMerge.PersistentFlags().BoolVarP(&writeInplace, "inplace", "i", false, "update the yaml file inplace") cmdMerge.PersistentFlags().BoolVarP(&writeInplace, "inplace", "i", false, "update the yaml file inplace")
cmdMerge.PersistentFlags().BoolVarP(&overwriteFlag, "overwrite", "x", false, "update the yaml file by overwriting existing values") cmdMerge.PersistentFlags().BoolVarP(&overwriteFlag, "overwrite", "x", false, "update the yaml file by overwriting existing values")
cmdMerge.PersistentFlags().BoolVarP(&appendFlag, "append", "a", false, "update the yaml file by appending array values") cmdMerge.PersistentFlags().BoolVarP(&appendFlag, "append", "a", false, "update the yaml file by appending array values")
cmdMerge.PersistentFlags().BoolVarP(&allowEmptyFlag, "allow-empty", "e", false, "allow empty yaml files")
cmdMerge.PersistentFlags().StringVarP(&docIndex, "doc", "d", "0", "process document index number (0 based, * for all documents)") cmdMerge.PersistentFlags().StringVarP(&docIndex, "doc", "d", "0", "process document index number (0 based, * for all documents)")
return cmdMerge return cmdMerge
} }
@@ -255,7 +263,7 @@ func readProperty(cmd *cobra.Command, args []string) error {
if errorReading == io.EOF { if errorReading == io.EOF {
log.Debugf("done %v / %v", currentIndex, docIndexInt) log.Debugf("done %v / %v", currentIndex, docIndexInt)
if !updateAll && currentIndex <= docIndexInt { if !updateAll && currentIndex <= docIndexInt {
return fmt.Errorf("Asked to process document index %v but there are only %v document(s)", docIndex, currentIndex) return fmt.Errorf("asked to process document index %v but there are only %v document(s)", docIndex, currentIndex)
} }
return nil return nil
} }
@@ -370,7 +378,7 @@ func mapYamlDecoder(updateData updateDataFn, encoder *yaml.Encoder) yamlDecoderF
if errorReading == io.EOF { if errorReading == io.EOF {
if !updateAll && currentIndex <= docIndexInt { if !updateAll && currentIndex <= docIndexInt {
return fmt.Errorf("Asked to process document index %v but there are only %v document(s)", docIndex, currentIndex) return fmt.Errorf("asked to process document index %v but there are only %v document(s)", docIndex, currentIndex)
} }
return nil return nil
} else if errorReading != nil { } else if errorReading != nil {
@@ -462,11 +470,11 @@ func readAndUpdate(stdOut io.Writer, inputFile string, updateData updateDataFn)
if err != nil { if err != nil {
return err return err
} }
err = tempFile.Chmod(info.Mode()) destinationName = tempFile.Name()
err = os.Chmod(destinationName, info.Mode())
if err != nil { if err != nil {
return err return err
} }
destinationName = tempFile.Name()
destination = tempFile destination = tempFile
defer func() { defer func() {
safelyCloseFile(tempFile) safelyCloseFile(tempFile)
@@ -497,7 +505,7 @@ func deleteProperty(cmd *cobra.Command, args []string) error {
var updateData = func(dataBucket interface{}, currentIndex int) (interface{}, error) { var updateData = func(dataBucket interface{}, currentIndex int) (interface{}, error) {
if updateAll || currentIndex == docIndexInt { if updateAll || currentIndex == docIndexInt {
log.Debugf("Deleting path in doc %v", currentIndex) log.Debugf("Deleting path in doc %v", currentIndex)
return deleteChildValue(dataBucket, paths), nil return deleteChildValue(dataBucket, paths)
} }
return dataBucket, nil return dataBucket, nil
} }
@@ -530,6 +538,9 @@ func mergeProperties(cmd *cobra.Command, args []string) error {
for _, f := range filesToMerge { for _, f := range filesToMerge {
var fileToMerge interface{} var fileToMerge interface{}
if err := readData(f, 0, &fileToMerge); err != nil { if err := readData(f, 0, &fileToMerge); err != nil {
if allowEmptyFlag && err == io.EOF {
continue
}
return nil, err return nil, err
} }
mapDataBucket["root"] = fileToMerge mapDataBucket["root"] = fileToMerge
@@ -589,9 +600,9 @@ func toString(context interface{}) (string, error) {
} }
func yamlToString(context interface{}) (string, error) { func yamlToString(context interface{}) (string, error) {
switch context.(type) { switch context := context.(type) {
case string: case string:
return context.(string), nil return context, nil
default: default:
return marshalContext(context) return marshalContext(context)
} }

View File

@@ -2,6 +2,7 @@ package main
import ( import (
"fmt" "fmt"
"runtime"
"testing" "testing"
) )
@@ -64,6 +65,11 @@ func TestNewYaml_WithUnknownScript(t *testing.T) {
if err == nil { if err == nil {
t.Error("Expected error due to unknown file") t.Error("Expected error due to unknown file")
} }
expectedOutput := `open fake-unknown: no such file or directory` var expectedOutput string
if runtime.GOOS == "windows" {
expectedOutput = `open fake-unknown: The system cannot find the file specified.`
} else {
expectedOutput = `open fake-unknown: no such file or directory`
}
assertResult(t, expectedOutput, err.Error()) assertResult(t, expectedOutput, err.Error())
} }