mirror of
https://github.com/mikefarah/yq.git
synced 2024-12-19 20:19:04 +00:00
Merge branch 'v3'
This commit is contained in:
commit
789ea02096
1
.gitignore
vendored
1
.gitignore
vendored
@ -23,6 +23,7 @@ _cgo_export.*
|
||||
|
||||
_testmain.go
|
||||
coverage.out
|
||||
coverage.html
|
||||
*.exe
|
||||
*.test
|
||||
*.prof
|
||||
|
61
README.md
61
README.md
@ -1,26 +1,14 @@
|
||||
# yq
|
||||
|
||||
[![Build Status](https://travis-ci.com/mikefarah/yq.svg?branch=master)](https://travis-ci.com/mikefarah/yq) ![Docker Pulls](https://img.shields.io/docker/pulls/mikefarah/yq.svg) ![Github Releases (by Release)](https://img.shields.io/github/downloads/mikefarah/yq/total.svg) ![Go Report](https://goreportcard.com/badge/github.com/mikefarah/yq)
|
||||
[![Build Status](https://api.travis-ci.com/mikefarah/yq.svg?branch=master)](https://travis-ci.com/mikefarah/yq/) ![Docker Pulls](https://img.shields.io/docker/pulls/mikefarah/yq.svg) ![Github Releases (by Release)](https://img.shields.io/github/downloads/mikefarah/yq/total.svg) ![Go Report](https://goreportcard.com/badge/github.com/mikefarah/yq)
|
||||
|
||||
|
||||
a lightweight and portable command-line YAML processor
|
||||
|
||||
The aim of the project is to be the [jq](https://github.com/stedolan/jq) or sed of yaml files.
|
||||
|
||||
|
||||
## Major upgrade - V3 beta is out!
|
||||
|
||||
This addresses a number of features requests and issues that have been raised :)
|
||||
|
||||
Currently only available only available as a [binary release here](https://github.com/mikefarah/yq/releases/tag/3.0.0-beta) or via docker mikefarah/yq:3.0.0-beta!
|
||||
|
||||
It does have a few breaking changes listed on the [release page](https://github.com/mikefarah/yq/releases/tag/3.0.0-beta)
|
||||
|
||||
The updated user docs are available [here](https://mikefarah.gitbook.io/yq/)
|
||||
|
||||
Looking forward to feedback - once this is out of beta it will be added to the remaining package managers, and be the default version downloaded (and merged into master).
|
||||
|
||||
V2 will no longer have any new features added, and will be moved to a branch (v2). It will have limited maintenance for bugs for a few months.
|
||||
## New version!
|
||||
V3 is officially out - if you've been using v2 and want/need to upgrade, checkout the [upgrade guide](https://mikefarah.gitbook.io/yq/upgrading-from-v2).
|
||||
|
||||
## Install
|
||||
|
||||
@ -59,7 +47,7 @@ sudo apt install yq -y
|
||||
```
|
||||
### or, [Download latest binary](https://github.com/mikefarah/yq/releases/latest) or alternatively:
|
||||
```
|
||||
GO111MODULE=on go get github.com/mikefarah/yq/v2
|
||||
GO111MODULE=on go get github.com/mikefarah/yq/v3
|
||||
```
|
||||
|
||||
## Run with Docker
|
||||
@ -86,44 +74,39 @@ yq() {
|
||||
|
||||
## Features
|
||||
- Written in portable go, so you can download a lovely dependency free binary
|
||||
- Deep read a yaml file with a given path
|
||||
- Update a yaml file given a path
|
||||
- Update a yaml file given a script file
|
||||
- [Deep read a yaml file with a given path expression](https://mikefarah.gitbook.io/yq/commands/read#basic)
|
||||
- [List matching paths of a given path expression](https://mikefarah.gitbook.io/yq/commands/read#path-only)
|
||||
- Update a yaml file given a [path expression](https://mikefarah.gitbook.io/yq/commands/write-update#basic) or [script file](https://mikefarah.gitbook.io/yq/commands/write-update#basic)
|
||||
- Update creates any missing entries in the path on the fly
|
||||
- Create a yaml file given a deep path and value
|
||||
- Create a yaml file given a script file
|
||||
- Prefix a path to a yaml file
|
||||
- Convert from json to yaml
|
||||
- Convert from yaml to json
|
||||
- Pipe data in by using '-'
|
||||
- Merge multiple yaml files where each additional file sets values for missing or null value keys.
|
||||
- Merge multiple yaml files and override previous values.
|
||||
- Merge multiple yaml files and append array values.
|
||||
- Supports multiple documents in a single yaml file
|
||||
- Keeps yaml formatting and comments when updating
|
||||
- Create a yaml file given a [deep path and value](https://mikefarah.gitbook.io/yq/commands/create#creating-a-simple-yaml-file) or a [script file](https://mikefarah.gitbook.io/yq/commands/create#creating-using-a-create-script)
|
||||
- [Prefix a path to a yaml file](https://mikefarah.gitbook.io/yq/commands/prefix)
|
||||
- [Convert to/from json to yaml](https://mikefarah.gitbook.io/yq/usage/convert)
|
||||
- [Pipe data in by using '-'](https://mikefarah.gitbook.io/yq/commands/read#from-stdin)
|
||||
- [Merge](https://mikefarah.gitbook.io/yq/commands/merge) multiple yaml files with various options for [overriding](https://mikefarah.gitbook.io/yq/commands/merge#overwrite-values) and [appending](https://mikefarah.gitbook.io/yq/commands/merge#append-values-with-arrays)
|
||||
- Supports multiple documents in a single yaml file for [reading](https://mikefarah.gitbook.io/yq/commands/read#multiple-documents), [writing](https://mikefarah.gitbook.io/yq/commands/write-update#multiple-documents) and [merging](https://mikefarah.gitbook.io/yq/commands/merge#multiple-documents)
|
||||
|
||||
## [Usage](https://mikefarah.gitbook.io/yq/v/v2.x/)
|
||||
## [Usage](https://mikefarah.gitbook.io/yq/)
|
||||
|
||||
Check out the [documentation](https://mikefarah.gitbook.io/yq/v/v2.x/) for more detailed and advanced usage.
|
||||
Check out the [documentation](https://mikefarah.gitbook.io/yq/) for more detailed and advanced usage.
|
||||
|
||||
```
|
||||
yq is a lightweight and portable command-line YAML processor. It aims to be the jq or sed of yaml files.
|
||||
|
||||
Usage:
|
||||
yq [flags]
|
||||
yq [command]
|
||||
|
||||
Available Commands:
|
||||
delete yq d [--inplace/-i] [--doc/-d index] sample.yaml a.b.c
|
||||
delete yq d [--inplace/-i] [--doc/-d index] sample.yaml 'b.e(name==fred).value'
|
||||
help Help about any command
|
||||
merge yq m [--inplace/-i] [--doc/-d index] [--overwrite/-x] [--append/-a] sample.yaml sample2.yaml
|
||||
new yq n [--script/-s script_file] a.b.c newValue
|
||||
prefix yq p [--inplace/-i] [--doc/-d index] sample.yaml a.b.c
|
||||
read yq r [--doc/-d index] sample.yaml a.b.c
|
||||
write yq w [--inplace/-i] [--script/-s script_file] [--doc/-d index] sample.yaml a.b.c newValue
|
||||
read yq r [--printMode/-p pv] sample.yaml 'b.e(name==fr*).value'
|
||||
write yq w [--inplace/-i] [--script/-s script_file] [--doc/-d index] sample.yaml 'b.e(name==fr*).value' newValue
|
||||
|
||||
Flags:
|
||||
-h, --help help for yq
|
||||
-t, --trim trim yaml output (default true)
|
||||
-j, --tojson output as json
|
||||
-v, --verbose verbose mode
|
||||
-V, --version Print version information and quit
|
||||
|
||||
@ -139,8 +122,4 @@ Use "yq [command] --help" for more information about a command.
|
||||
3. add unit tests
|
||||
4. apply changes to go.mod
|
||||
5. `make [local] build`
|
||||
6. If required, update the user documentation
|
||||
- Update README.md and/or documentation under the mkdocs folder
|
||||
- `make [local] build-docs`
|
||||
- browse to docs/index.html and check your changes
|
||||
7. profit
|
||||
|
74
Upgrade Notes
Normal file
74
Upgrade Notes
Normal file
@ -0,0 +1,74 @@
|
||||
|
||||
Major release! Upgraded underlying yaml parser, re-written majority of yq. This has brought on a number of features that have been in demand for a while (see below).
|
||||
|
||||
This is in beta and needs some community feedback and testing :)
|
||||
|
||||
# New Features
|
||||
- Keeps yaml comments and formatting, can specify yaml tags when updating. https://github.com/mikefarah/yq/issues/19, https://github.com/mikefarah/yq/issues/169, https://github.com/mikefarah/yq/issues/107, https://github.com/mikefarah/yq/issues/171, https://github.com/mikefarah/yq/issues/245, https://github.com/mikefarah/yq/issues/303,https://github.com/mikefarah/yq/issues/308,https://github.com/mikefarah/yq/issues/314
|
||||
- Handles anchors! https://github.com/mikefarah/yq/issues/310, https://github.com/mikefarah/yq/issues/178
|
||||
- Can print out matching paths and values when splatting https://github.com/mikefarah/yq/issues/20
|
||||
- JSON output works for all commands! Yaml files with multiple documents are printed out as one JSON document per line.
|
||||
- Deep splat (**) to match arbitrary paths
|
||||
|
||||
|
||||
# Breaking changes
|
||||
|
||||
## Update scripts file format has changed to be more powerful.
|
||||
Comments can be added, and delete commands have been introduced.
|
||||
|
||||
Before:
|
||||
```yaml
|
||||
b.e[+].name: Mike Farah
|
||||
```
|
||||
|
||||
After:
|
||||
```yaml
|
||||
- command: update
|
||||
path: b.e[+].thing
|
||||
value:
|
||||
#great
|
||||
things: frog # wow!
|
||||
- command: delete
|
||||
path: b.d
|
||||
```
|
||||
|
||||
https://github.com/mikefarah/yq/issues/305
|
||||
|
||||
## Reading and splatting, matching results are printed once per line.
|
||||
e.g:
|
||||
|
||||
```json
|
||||
parent:
|
||||
childA:
|
||||
no: matches here
|
||||
childB:
|
||||
there: matches
|
||||
hi: no match
|
||||
there2: also matches
|
||||
```
|
||||
|
||||
```bash
|
||||
yq r sample.yaml 'parent.*.there*'
|
||||
```
|
||||
|
||||
old
|
||||
```yaml
|
||||
- null
|
||||
- - matches
|
||||
- also matches
|
||||
```
|
||||
|
||||
new
|
||||
```yaml
|
||||
matches
|
||||
also matches
|
||||
```
|
||||
|
||||
and you can print the matching paths:
|
||||
|
||||
yq r --printMode pv sample.yaml 'parent.*.there*'
|
||||
|
||||
```yaml
|
||||
parent.childB.there: matches
|
||||
parent.childB.there2: also matches
|
||||
```
|
File diff suppressed because it is too large
Load Diff
22
cmd/constant.go
Normal file
22
cmd/constant.go
Normal file
@ -0,0 +1,22 @@
|
||||
package cmd
|
||||
|
||||
import (
|
||||
"github.com/mikefarah/yq/v3/pkg/yqlib"
|
||||
logging "gopkg.in/op/go-logging.v1"
|
||||
)
|
||||
|
||||
var customTag = ""
|
||||
var printMode = "v"
|
||||
var writeInplace = false
|
||||
var writeScript = ""
|
||||
var outputToJSON = false
|
||||
var overwriteFlag = false
|
||||
var autoCreateFlag = true
|
||||
var allowEmptyFlag = false
|
||||
var appendFlag = false
|
||||
var verbose = false
|
||||
var version = false
|
||||
var docIndex = "0"
|
||||
var log = logging.MustGetLogger("yq")
|
||||
var lib = yqlib.NewYqLib()
|
||||
var valueParser = yqlib.NewValueParser()
|
41
cmd/delete.go
Normal file
41
cmd/delete.go
Normal file
@ -0,0 +1,41 @@
|
||||
package cmd
|
||||
|
||||
import (
|
||||
"github.com/mikefarah/yq/v3/pkg/yqlib"
|
||||
errors "github.com/pkg/errors"
|
||||
"github.com/spf13/cobra"
|
||||
)
|
||||
|
||||
func createDeleteCmd() *cobra.Command {
|
||||
var cmdDelete = &cobra.Command{
|
||||
Use: "delete [yaml_file] [path_expression]",
|
||||
Aliases: []string{"d"},
|
||||
Short: "yq d [--inplace/-i] [--doc/-d index] sample.yaml 'b.e(name==fred).value'",
|
||||
Example: `
|
||||
yq delete things.yaml 'a.b.c'
|
||||
yq delete things.yaml 'a.*.c'
|
||||
yq delete things.yaml 'a.(child.subchild==co*).c'
|
||||
yq delete things.yaml 'a.**'
|
||||
yq delete --inplace things.yaml 'a.b.c'
|
||||
yq delete --inplace -- things.yaml '--key-starting-with-dash' # need to use '--' to stop processing arguments as flags
|
||||
yq d -i things.yaml 'a.b.c'
|
||||
`,
|
||||
Long: `Deletes the nodes matching the given path expression from the YAML file.
|
||||
Outputs to STDOUT unless the inplace flag is used, in which case the file is updated instead.
|
||||
`,
|
||||
RunE: deleteProperty,
|
||||
}
|
||||
cmdDelete.PersistentFlags().BoolVarP(&writeInplace, "inplace", "i", false, "update the yaml file inplace")
|
||||
cmdDelete.PersistentFlags().StringVarP(&docIndex, "doc", "d", "0", "process document index number (0 based, * for all documents)")
|
||||
return cmdDelete
|
||||
}
|
||||
|
||||
func deleteProperty(cmd *cobra.Command, args []string) error {
|
||||
if len(args) < 2 {
|
||||
return errors.New("Must provide <filename> <path_to_delete>")
|
||||
}
|
||||
var updateCommands []yqlib.UpdateCommand = make([]yqlib.UpdateCommand, 1)
|
||||
updateCommands[0] = yqlib.UpdateCommand{Command: "delete", Path: args[1]}
|
||||
|
||||
return updateDoc(args[0], updateCommands, cmd.OutOrStdout())
|
||||
}
|
62
cmd/merge.go
Normal file
62
cmd/merge.go
Normal file
@ -0,0 +1,62 @@
|
||||
package cmd
|
||||
|
||||
import (
|
||||
"strings"
|
||||
|
||||
"github.com/mikefarah/yq/v3/pkg/yqlib"
|
||||
errors "github.com/pkg/errors"
|
||||
"github.com/spf13/cobra"
|
||||
)
|
||||
|
||||
func createMergeCmd() *cobra.Command {
|
||||
var cmdMerge = &cobra.Command{
|
||||
Use: "merge [initial_yaml_file] [additional_yaml_file]...",
|
||||
Aliases: []string{"m"},
|
||||
Short: "yq m [--inplace/-i] [--doc/-d index] [--overwrite/-x] [--append/-a] sample.yaml sample2.yaml",
|
||||
Example: `
|
||||
yq merge things.yaml other.yaml
|
||||
yq merge --inplace things.yaml other.yaml
|
||||
yq m -i things.yaml other.yaml
|
||||
yq m --overwrite things.yaml other.yaml
|
||||
yq m -i -x things.yaml other.yaml
|
||||
yq m -i -a things.yaml other.yaml
|
||||
yq m -i --autocreate=false things.yaml other.yaml
|
||||
`,
|
||||
Long: `Updates the yaml file by adding/updating the path(s) and value(s) from additional yaml file(s).
|
||||
Outputs to STDOUT unless the inplace flag is used, in which case the file is updated instead.
|
||||
|
||||
If overwrite flag is set then existing values will be overwritten using the values from each additional yaml file.
|
||||
If append flag is set then existing arrays will be merged with the arrays from each additional yaml file.
|
||||
`,
|
||||
RunE: mergeProperties,
|
||||
}
|
||||
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(&autoCreateFlag, "autocreate", "c", true, "automatically create any missing entries")
|
||||
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)")
|
||||
return cmdMerge
|
||||
}
|
||||
|
||||
func mergeProperties(cmd *cobra.Command, args []string) error {
|
||||
if len(args) < 2 {
|
||||
return errors.New("Must provide at least 2 yaml files")
|
||||
}
|
||||
// first generate update commands from the file
|
||||
var filesToMerge = args[1:]
|
||||
var updateCommands []yqlib.UpdateCommand = make([]yqlib.UpdateCommand, 0)
|
||||
|
||||
for _, fileToMerge := range filesToMerge {
|
||||
matchingNodes, errorProcessingFile := readYamlFile(fileToMerge, "**", false, 0)
|
||||
if errorProcessingFile != nil && (!allowEmptyFlag || !strings.HasPrefix(errorProcessingFile.Error(), "Could not process document index")) {
|
||||
return errorProcessingFile
|
||||
}
|
||||
for _, matchingNode := range matchingNodes {
|
||||
mergePath := lib.MergePathStackToString(matchingNode.PathStack, appendFlag)
|
||||
updateCommands = append(updateCommands, yqlib.UpdateCommand{Command: "update", Path: mergePath, Value: matchingNode.Node, Overwrite: overwriteFlag})
|
||||
}
|
||||
}
|
||||
|
||||
return updateDoc(args[0], updateCommands, cmd.OutOrStdout())
|
||||
}
|
54
cmd/new.go
Normal file
54
cmd/new.go
Normal file
@ -0,0 +1,54 @@
|
||||
package cmd
|
||||
|
||||
import (
|
||||
"github.com/spf13/cobra"
|
||||
yaml "gopkg.in/yaml.v3"
|
||||
)
|
||||
|
||||
func createNewCmd() *cobra.Command {
|
||||
var cmdNew = &cobra.Command{
|
||||
Use: "new [path] [value]",
|
||||
Aliases: []string{"n"},
|
||||
Short: "yq n [--script/-s script_file] a.b.c newValue",
|
||||
Example: `
|
||||
yq new 'a.b.c' cat
|
||||
yq n 'a.b.c' --tag '!!str' true # force 'true' to be interpreted as a string instead of bool
|
||||
yq n 'a.b[+]' cat
|
||||
yq n -- '--key-starting-with-dash' cat # need to use '--' to stop processing arguments as flags
|
||||
yq n --script create_script.yaml
|
||||
`,
|
||||
Long: `Creates a new yaml w.r.t the given path and value.
|
||||
Outputs to STDOUT
|
||||
|
||||
Create Scripts:
|
||||
Note that you can give a create script to perform more sophisticated yaml. This follows the same format as the update script.
|
||||
`,
|
||||
RunE: newProperty,
|
||||
}
|
||||
cmdNew.PersistentFlags().StringVarP(&writeScript, "script", "s", "", "yaml script for creating yaml")
|
||||
cmdNew.PersistentFlags().StringVarP(&customTag, "tag", "t", "", "set yaml tag (e.g. !!int)")
|
||||
return cmdNew
|
||||
}
|
||||
|
||||
func newProperty(cmd *cobra.Command, args []string) error {
|
||||
var updateCommands, updateCommandsError = readUpdateCommands(args, 2, "Must provide <path_to_update> <value>")
|
||||
if updateCommandsError != nil {
|
||||
return updateCommandsError
|
||||
}
|
||||
newNode := lib.New(updateCommands[0].Path)
|
||||
|
||||
for _, updateCommand := range updateCommands {
|
||||
|
||||
errorUpdating := lib.Update(&newNode, updateCommand, true)
|
||||
|
||||
if errorUpdating != nil {
|
||||
return errorUpdating
|
||||
}
|
||||
}
|
||||
|
||||
var encoder = yaml.NewEncoder(cmd.OutOrStdout())
|
||||
encoder.SetIndent(2)
|
||||
errorEncoding := encoder.Encode(&newNode)
|
||||
encoder.Close()
|
||||
return errorEncoding
|
||||
}
|
50
cmd/prefix.go
Normal file
50
cmd/prefix.go
Normal file
@ -0,0 +1,50 @@
|
||||
package cmd
|
||||
|
||||
import (
|
||||
"github.com/mikefarah/yq/v3/pkg/yqlib"
|
||||
errors "github.com/pkg/errors"
|
||||
"github.com/spf13/cobra"
|
||||
yaml "gopkg.in/yaml.v3"
|
||||
)
|
||||
|
||||
func createPrefixCmd() *cobra.Command {
|
||||
var cmdPrefix = &cobra.Command{
|
||||
Use: "prefix [yaml_file] [path]",
|
||||
Aliases: []string{"p"},
|
||||
Short: "yq p [--inplace/-i] [--doc/-d index] sample.yaml a.b.c",
|
||||
Example: `
|
||||
yq prefix things.yaml 'a.b.c'
|
||||
yq prefix --inplace things.yaml 'a.b.c'
|
||||
yq prefix --inplace -- things.yaml '--key-starting-with-dash' # need to use '--' to stop processing arguments as flags
|
||||
yq p -i things.yaml 'a.b.c'
|
||||
yq p --doc 2 things.yaml 'a.b.d'
|
||||
yq p -d2 things.yaml 'a.b.d'
|
||||
`,
|
||||
Long: `Prefixes w.r.t to the yaml file at the given path.
|
||||
Outputs to STDOUT unless the inplace flag is used, in which case the file is updated instead.
|
||||
`,
|
||||
RunE: prefixProperty,
|
||||
}
|
||||
cmdPrefix.PersistentFlags().BoolVarP(&writeInplace, "inplace", "i", false, "update the yaml file inplace")
|
||||
cmdPrefix.PersistentFlags().StringVarP(&docIndex, "doc", "d", "0", "process document index number (0 based, * for all documents)")
|
||||
return cmdPrefix
|
||||
}
|
||||
|
||||
func prefixProperty(cmd *cobra.Command, args []string) error {
|
||||
|
||||
if len(args) < 2 {
|
||||
return errors.New("Must provide <filename> <prefixed_path>")
|
||||
}
|
||||
updateCommand := yqlib.UpdateCommand{Command: "update", Path: args[1]}
|
||||
log.Debugf("args %v", args)
|
||||
|
||||
var updateAll, docIndexInt, errorParsingDocIndex = parseDocumentIndex()
|
||||
if errorParsingDocIndex != nil {
|
||||
return errorParsingDocIndex
|
||||
}
|
||||
|
||||
var updateData = func(dataBucket *yaml.Node, currentIndex int) error {
|
||||
return prefixDocument(updateAll, docIndexInt, currentIndex, dataBucket, updateCommand)
|
||||
}
|
||||
return readAndUpdate(cmd.OutOrStdout(), args[0], updateData)
|
||||
}
|
52
cmd/read.go
Normal file
52
cmd/read.go
Normal file
@ -0,0 +1,52 @@
|
||||
package cmd
|
||||
|
||||
import (
|
||||
errors "github.com/pkg/errors"
|
||||
"github.com/spf13/cobra"
|
||||
)
|
||||
|
||||
func createReadCmd() *cobra.Command {
|
||||
var cmdRead = &cobra.Command{
|
||||
Use: "read [yaml_file] [path_expression]",
|
||||
Aliases: []string{"r"},
|
||||
Short: "yq r [--printMode/-p pv] sample.yaml 'b.e(name==fr*).value'",
|
||||
Example: `
|
||||
yq read things.yaml 'a.b.c'
|
||||
yq r - 'a.b.c' # reads from stdin
|
||||
yq r things.yaml 'a.*.c'
|
||||
yq r things.yaml 'a.**.c' # deep splat
|
||||
yq r things.yaml 'a.(child.subchild==co*).c'
|
||||
yq r -d1 things.yaml 'a.array[0].blah'
|
||||
yq r things.yaml 'a.array[*].blah'
|
||||
yq r -- things.yaml '--key-starting-with-dashes.blah'
|
||||
`,
|
||||
Long: "Outputs the value of the given path in the yaml file to STDOUT",
|
||||
RunE: readProperty,
|
||||
}
|
||||
cmdRead.PersistentFlags().StringVarP(&docIndex, "doc", "d", "0", "process document index number (0 based, * for all documents)")
|
||||
cmdRead.PersistentFlags().StringVarP(&printMode, "printMode", "p", "v", "print mode (v (values, default), p (paths), pv (path and value pairs)")
|
||||
return cmdRead
|
||||
}
|
||||
|
||||
func readProperty(cmd *cobra.Command, args []string) error {
|
||||
var path = ""
|
||||
|
||||
if len(args) < 1 {
|
||||
return errors.New("Must provide filename")
|
||||
} else if len(args) > 1 {
|
||||
path = args[1]
|
||||
}
|
||||
|
||||
var updateAll, docIndexInt, errorParsingDocIndex = parseDocumentIndex()
|
||||
if errorParsingDocIndex != nil {
|
||||
return errorParsingDocIndex
|
||||
}
|
||||
|
||||
matchingNodes, errorReadingStream := readYamlFile(args[0], path, updateAll, docIndexInt)
|
||||
|
||||
if errorReadingStream != nil {
|
||||
return errorReadingStream
|
||||
}
|
||||
|
||||
return printResults(matchingNodes, cmd)
|
||||
}
|
56
cmd/root.go
Normal file
56
cmd/root.go
Normal file
@ -0,0 +1,56 @@
|
||||
package cmd
|
||||
|
||||
import (
|
||||
"os"
|
||||
|
||||
"github.com/spf13/cobra"
|
||||
logging "gopkg.in/op/go-logging.v1"
|
||||
)
|
||||
|
||||
func New() *cobra.Command {
|
||||
var rootCmd = &cobra.Command{
|
||||
Use: "yq",
|
||||
Short: "yq is a lightweight and portable command-line YAML processor.",
|
||||
Long: `yq is a lightweight and portable command-line YAML processor. It aims to be the jq or sed of yaml files.`,
|
||||
RunE: func(cmd *cobra.Command, args []string) error {
|
||||
if version {
|
||||
cmd.Print(GetVersionDisplay())
|
||||
return nil
|
||||
}
|
||||
cmd.Println(cmd.UsageString())
|
||||
|
||||
return nil
|
||||
},
|
||||
PersistentPreRun: func(cmd *cobra.Command, args []string) {
|
||||
var format = logging.MustStringFormatter(
|
||||
`%{color}%{time:15:04:05} %{shortfunc} [%{level:.4s}]%{color:reset} %{message}`,
|
||||
)
|
||||
var backend = logging.AddModuleLevel(
|
||||
logging.NewBackendFormatter(logging.NewLogBackend(os.Stderr, "", 0), format))
|
||||
|
||||
if verbose {
|
||||
backend.SetLevel(logging.DEBUG, "")
|
||||
} else {
|
||||
backend.SetLevel(logging.ERROR, "")
|
||||
}
|
||||
|
||||
logging.SetBackend(backend)
|
||||
},
|
||||
}
|
||||
|
||||
rootCmd.PersistentFlags().BoolVarP(&verbose, "verbose", "v", false, "verbose mode")
|
||||
rootCmd.PersistentFlags().BoolVarP(&outputToJSON, "tojson", "j", false, "output as json")
|
||||
rootCmd.Flags().BoolVarP(&version, "version", "V", false, "Print version information and quit")
|
||||
|
||||
rootCmd.AddCommand(
|
||||
createReadCmd(),
|
||||
createWriteCmd(),
|
||||
createPrefixCmd(),
|
||||
createDeleteCmd(),
|
||||
createNewCmd(),
|
||||
createMergeCmd(),
|
||||
)
|
||||
rootCmd.SetOutput(os.Stdout)
|
||||
|
||||
return rootCmd
|
||||
}
|
373
cmd/utils.go
Normal file
373
cmd/utils.go
Normal file
@ -0,0 +1,373 @@
|
||||
package cmd
|
||||
|
||||
import (
|
||||
"bufio"
|
||||
"fmt"
|
||||
"io"
|
||||
"io/ioutil"
|
||||
"os"
|
||||
"strconv"
|
||||
|
||||
"github.com/mikefarah/yq/v3/pkg/yqlib"
|
||||
errors "github.com/pkg/errors"
|
||||
"github.com/spf13/cobra"
|
||||
yaml "gopkg.in/yaml.v3"
|
||||
)
|
||||
|
||||
func readYamlFile(filename string, path string, updateAll bool, docIndexInt int) ([]*yqlib.NodeContext, error) {
|
||||
var matchingNodes []*yqlib.NodeContext
|
||||
|
||||
var currentIndex = 0
|
||||
var errorReadingStream = readStream(filename, func(decoder *yaml.Decoder) error {
|
||||
for {
|
||||
var dataBucket yaml.Node
|
||||
errorReading := decoder.Decode(&dataBucket)
|
||||
|
||||
if errorReading == io.EOF {
|
||||
return handleEOF(updateAll, docIndexInt, currentIndex)
|
||||
}
|
||||
var errorParsing error
|
||||
matchingNodes, errorParsing = appendDocument(matchingNodes, dataBucket, path, updateAll, docIndexInt, currentIndex)
|
||||
if errorParsing != nil {
|
||||
return errorParsing
|
||||
}
|
||||
currentIndex = currentIndex + 1
|
||||
}
|
||||
})
|
||||
return matchingNodes, errorReadingStream
|
||||
}
|
||||
|
||||
func handleEOF(updateAll bool, docIndexInt int, currentIndex int) error {
|
||||
log.Debugf("done %v / %v", currentIndex, docIndexInt)
|
||||
if !updateAll && currentIndex <= docIndexInt {
|
||||
return fmt.Errorf("Could not process document index %v as there are only %v document(s)", docIndex, currentIndex)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func appendDocument(originalMatchingNodes []*yqlib.NodeContext, dataBucket yaml.Node, path string, updateAll bool, docIndexInt int, currentIndex int) ([]*yqlib.NodeContext, error) {
|
||||
log.Debugf("processing document %v - requested index %v", currentIndex, docIndexInt)
|
||||
yqlib.DebugNode(&dataBucket)
|
||||
if !updateAll && currentIndex != docIndexInt {
|
||||
return originalMatchingNodes, nil
|
||||
}
|
||||
log.Debugf("reading %v in document %v", path, currentIndex)
|
||||
matchingNodes, errorParsing := lib.Get(&dataBucket, path)
|
||||
if errorParsing != nil {
|
||||
return nil, errors.Wrapf(errorParsing, "Error reading path in document index %v", currentIndex)
|
||||
}
|
||||
return append(originalMatchingNodes, matchingNodes...), nil
|
||||
}
|
||||
|
||||
func printValue(node *yaml.Node, cmd *cobra.Command) error {
|
||||
if node.Kind == yaml.ScalarNode {
|
||||
cmd.Print(node.Value)
|
||||
return nil
|
||||
}
|
||||
|
||||
bufferedWriter := bufio.NewWriter(cmd.OutOrStdout())
|
||||
defer safelyFlush(bufferedWriter)
|
||||
|
||||
var encoder yqlib.Encoder
|
||||
if outputToJSON {
|
||||
encoder = yqlib.NewJsonEncoder(bufferedWriter)
|
||||
} else {
|
||||
encoder = yqlib.NewYamlEncoder(bufferedWriter)
|
||||
}
|
||||
if err := encoder.Encode(node); err != nil {
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func printResults(matchingNodes []*yqlib.NodeContext, cmd *cobra.Command) error {
|
||||
if len(matchingNodes) == 0 {
|
||||
log.Debug("no matching results, nothing to print")
|
||||
return nil
|
||||
}
|
||||
|
||||
for index, mappedDoc := range matchingNodes {
|
||||
switch printMode {
|
||||
case "p":
|
||||
cmd.Print(lib.PathStackToString(mappedDoc.PathStack))
|
||||
if index < len(matchingNodes)-1 {
|
||||
cmd.Print("\n")
|
||||
}
|
||||
case "pv", "vp":
|
||||
// put it into a node and print that.
|
||||
var parentNode = yaml.Node{Kind: yaml.MappingNode}
|
||||
parentNode.Content = make([]*yaml.Node, 2)
|
||||
parentNode.Content[0] = &yaml.Node{Kind: yaml.ScalarNode, Value: lib.PathStackToString(mappedDoc.PathStack)}
|
||||
parentNode.Content[1] = mappedDoc.Node
|
||||
if err := printValue(&parentNode, cmd); err != nil {
|
||||
return err
|
||||
}
|
||||
default:
|
||||
if err := printValue(mappedDoc.Node, cmd); err != nil {
|
||||
return err
|
||||
}
|
||||
// Printing our Scalars does not print a new line at the end
|
||||
// we only want to do that if there are more values (so users can easily script extraction of values in the yaml)
|
||||
if index < len(matchingNodes)-1 && mappedDoc.Node.Kind == yaml.ScalarNode {
|
||||
cmd.Print("\n")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func parseDocumentIndex() (bool, int, error) {
|
||||
if docIndex == "*" {
|
||||
return true, -1, nil
|
||||
}
|
||||
docIndexInt64, err := strconv.ParseInt(docIndex, 10, 32)
|
||||
if err != nil {
|
||||
return false, -1, errors.Wrapf(err, "Document index %v is not a integer or *", docIndex)
|
||||
}
|
||||
return false, int(docIndexInt64), nil
|
||||
}
|
||||
|
||||
type updateDataFn func(dataBucket *yaml.Node, currentIndex int) error
|
||||
|
||||
func mapYamlDecoder(updateData updateDataFn, encoder yqlib.Encoder) yamlDecoderFn {
|
||||
return func(decoder *yaml.Decoder) error {
|
||||
var dataBucket yaml.Node
|
||||
var errorReading error
|
||||
var errorWriting error
|
||||
var errorUpdating error
|
||||
var currentIndex = 0
|
||||
|
||||
var updateAll, docIndexInt, errorParsingDocIndex = parseDocumentIndex()
|
||||
if errorParsingDocIndex != nil {
|
||||
return errorParsingDocIndex
|
||||
}
|
||||
|
||||
for {
|
||||
log.Debugf("Read doc %v", currentIndex)
|
||||
errorReading = decoder.Decode(&dataBucket)
|
||||
|
||||
if errorReading == io.EOF {
|
||||
if !updateAll && currentIndex <= docIndexInt {
|
||||
return fmt.Errorf("asked to process document index %v but there are only %v document(s)", docIndex, currentIndex)
|
||||
}
|
||||
return nil
|
||||
} else if errorReading != nil {
|
||||
return errors.Wrapf(errorReading, "Error reading document at index %v, %v", currentIndex, errorReading)
|
||||
}
|
||||
errorUpdating = updateData(&dataBucket, currentIndex)
|
||||
if errorUpdating != nil {
|
||||
return errors.Wrapf(errorUpdating, "Error updating document at index %v", currentIndex)
|
||||
}
|
||||
|
||||
errorWriting = encoder.Encode(&dataBucket)
|
||||
|
||||
if errorWriting != nil {
|
||||
return errors.Wrapf(errorWriting, "Error writing document at index %v, %v", currentIndex, errorWriting)
|
||||
}
|
||||
currentIndex = currentIndex + 1
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func prefixDocument(updateAll bool, docIndexInt int, currentIndex int, dataBucket *yaml.Node, updateCommand yqlib.UpdateCommand) error {
|
||||
if updateAll || currentIndex == docIndexInt {
|
||||
log.Debugf("Prefixing document %v", currentIndex)
|
||||
yqlib.DebugNode(dataBucket)
|
||||
updateCommand.Value = dataBucket.Content[0]
|
||||
dataBucket.Content = make([]*yaml.Node, 1)
|
||||
|
||||
newNode := lib.New(updateCommand.Path)
|
||||
dataBucket.Content[0] = &newNode
|
||||
|
||||
errorUpdating := lib.Update(dataBucket, updateCommand, true)
|
||||
if errorUpdating != nil {
|
||||
return errorUpdating
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func updateDoc(inputFile string, updateCommands []yqlib.UpdateCommand, writer io.Writer) error {
|
||||
var updateAll, docIndexInt, errorParsingDocIndex = parseDocumentIndex()
|
||||
if errorParsingDocIndex != nil {
|
||||
return errorParsingDocIndex
|
||||
}
|
||||
|
||||
var updateData = func(dataBucket *yaml.Node, currentIndex int) error {
|
||||
if updateAll || currentIndex == docIndexInt {
|
||||
log.Debugf("Updating doc %v", currentIndex)
|
||||
for _, updateCommand := range updateCommands {
|
||||
log.Debugf("Processing update to Path %v", updateCommand.Path)
|
||||
errorUpdating := lib.Update(dataBucket, updateCommand, autoCreateFlag)
|
||||
if errorUpdating != nil {
|
||||
return errorUpdating
|
||||
}
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
return readAndUpdate(writer, inputFile, updateData)
|
||||
}
|
||||
|
||||
func readAndUpdate(stdOut io.Writer, inputFile string, updateData updateDataFn) error {
|
||||
var destination io.Writer
|
||||
var destinationName string
|
||||
if writeInplace {
|
||||
info, err := os.Stat(inputFile)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
tempFile, err := ioutil.TempFile("", "temp")
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
destinationName = tempFile.Name()
|
||||
err = os.Chmod(destinationName, info.Mode())
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
destination = tempFile
|
||||
defer func() {
|
||||
safelyCloseFile(tempFile)
|
||||
safelyRenameFile(tempFile.Name(), inputFile)
|
||||
}()
|
||||
} else {
|
||||
destination = stdOut
|
||||
destinationName = "Stdout"
|
||||
}
|
||||
|
||||
log.Debugf("Writing to %v from %v", destinationName, inputFile)
|
||||
|
||||
bufferedWriter := bufio.NewWriter(destination)
|
||||
defer safelyFlush(bufferedWriter)
|
||||
|
||||
var encoder yqlib.Encoder
|
||||
if outputToJSON {
|
||||
encoder = yqlib.NewJsonEncoder(bufferedWriter)
|
||||
} else {
|
||||
encoder = yqlib.NewYamlEncoder(bufferedWriter)
|
||||
}
|
||||
return readStream(inputFile, mapYamlDecoder(updateData, encoder))
|
||||
}
|
||||
|
||||
type updateCommandParsed struct {
|
||||
Command string
|
||||
Path string
|
||||
Value yaml.Node
|
||||
}
|
||||
|
||||
func readUpdateCommands(args []string, expectedArgs int, badArgsMessage string) ([]yqlib.UpdateCommand, error) {
|
||||
var updateCommands []yqlib.UpdateCommand = make([]yqlib.UpdateCommand, 0)
|
||||
if writeScript != "" {
|
||||
var parsedCommands = make([]updateCommandParsed, 0)
|
||||
|
||||
err := readData(writeScript, 0, &parsedCommands)
|
||||
|
||||
if err != nil && err != io.EOF {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
log.Debugf("Read write commands file '%v'", parsedCommands)
|
||||
for index := range parsedCommands {
|
||||
parsedCommand := parsedCommands[index]
|
||||
updateCommand := yqlib.UpdateCommand{Command: parsedCommand.Command, Path: parsedCommand.Path, Value: &parsedCommand.Value, Overwrite: true}
|
||||
updateCommands = append(updateCommands, updateCommand)
|
||||
}
|
||||
|
||||
log.Debugf("Read write commands file '%v'", updateCommands)
|
||||
} else if len(args) < expectedArgs {
|
||||
return nil, errors.New(badArgsMessage)
|
||||
} else {
|
||||
updateCommands = make([]yqlib.UpdateCommand, 1)
|
||||
log.Debug("args %v", args)
|
||||
log.Debug("path %v", args[expectedArgs-2])
|
||||
log.Debug("Value %v", args[expectedArgs-1])
|
||||
updateCommands[0] = yqlib.UpdateCommand{Command: "update", Path: args[expectedArgs-2], Value: valueParser.Parse(args[expectedArgs-1], customTag), Overwrite: true}
|
||||
}
|
||||
return updateCommands, nil
|
||||
}
|
||||
|
||||
func safelyRenameFile(from string, to string) {
|
||||
if renameError := os.Rename(from, to); renameError != nil {
|
||||
log.Debugf("Error renaming from %v to %v, attempting to copy contents", from, to)
|
||||
log.Debug(renameError.Error())
|
||||
// can't do this rename when running in docker to a file targeted in a mounted volume,
|
||||
// so gracefully degrade to copying the entire contents.
|
||||
if copyError := copyFileContents(from, to); copyError != nil {
|
||||
log.Errorf("Failed copying from %v to %v", from, to)
|
||||
log.Error(copyError.Error())
|
||||
} else {
|
||||
removeErr := os.Remove(from)
|
||||
if removeErr != nil {
|
||||
log.Errorf("failed removing original file: %s", from)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// thanks https://stackoverflow.com/questions/21060945/simple-way-to-copy-a-file-in-golang
|
||||
func copyFileContents(src, dst string) (err error) {
|
||||
in, err := os.Open(src) // nolint gosec
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
defer safelyCloseFile(in)
|
||||
out, err := os.Create(dst)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
defer safelyCloseFile(out)
|
||||
if _, err = io.Copy(out, in); err != nil {
|
||||
return err
|
||||
}
|
||||
return out.Sync()
|
||||
}
|
||||
|
||||
func safelyFlush(writer *bufio.Writer) {
|
||||
if err := writer.Flush(); err != nil {
|
||||
log.Error("Error flushing writer!")
|
||||
log.Error(err.Error())
|
||||
}
|
||||
|
||||
}
|
||||
func safelyCloseFile(file *os.File) {
|
||||
err := file.Close()
|
||||
if err != nil {
|
||||
log.Error("Error closing file!")
|
||||
log.Error(err.Error())
|
||||
}
|
||||
}
|
||||
|
||||
type yamlDecoderFn func(*yaml.Decoder) error
|
||||
|
||||
func readStream(filename string, yamlDecoder yamlDecoderFn) error {
|
||||
if filename == "" {
|
||||
return errors.New("Must provide filename")
|
||||
}
|
||||
|
||||
var stream io.Reader
|
||||
if filename == "-" {
|
||||
stream = bufio.NewReader(os.Stdin)
|
||||
} else {
|
||||
file, err := os.Open(filename) // nolint gosec
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
defer safelyCloseFile(file)
|
||||
stream = file
|
||||
}
|
||||
return yamlDecoder(yaml.NewDecoder(stream))
|
||||
}
|
||||
|
||||
func readData(filename string, indexToRead int, parsedData interface{}) error {
|
||||
return readStream(filename, func(decoder *yaml.Decoder) error {
|
||||
for currentIndex := 0; currentIndex < indexToRead; currentIndex++ {
|
||||
errorSkipping := decoder.Decode(parsedData)
|
||||
if errorSkipping != nil {
|
||||
return errors.Wrapf(errorSkipping, "Error processing document at index %v, %v", currentIndex, errorSkipping)
|
||||
}
|
||||
}
|
||||
return decoder.Decode(parsedData)
|
||||
})
|
||||
}
|
@ -1,4 +1,4 @@
|
||||
package main
|
||||
package cmd
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
@ -11,7 +11,7 @@ var (
|
||||
GitDescribe string
|
||||
|
||||
// Version is main version number that is being run at the moment.
|
||||
Version = "2.4.1"
|
||||
Version = "3.0.1"
|
||||
|
||||
// VersionPrerelease is a pre-release marker for the version. If this is "" (empty string)
|
||||
// then it means that it is a final release. Otherwise, this is a pre-release
|
@ -1,4 +1,4 @@
|
||||
package main
|
||||
package cmd
|
||||
|
||||
import "testing"
|
||||
|
57
cmd/write.go
Normal file
57
cmd/write.go
Normal file
@ -0,0 +1,57 @@
|
||||
package cmd
|
||||
|
||||
import (
|
||||
"github.com/spf13/cobra"
|
||||
)
|
||||
|
||||
func createWriteCmd() *cobra.Command {
|
||||
var cmdWrite = &cobra.Command{
|
||||
Use: "write [yaml_file] [path_expression] [value]",
|
||||
Aliases: []string{"w"},
|
||||
Short: "yq w [--inplace/-i] [--script/-s script_file] [--doc/-d index] sample.yaml 'b.e(name==fr*).value' newValue",
|
||||
Example: `
|
||||
yq write things.yaml 'a.b.c' true
|
||||
yq write things.yaml 'a.*.c' true
|
||||
yq write things.yaml 'a.**' true
|
||||
yq write things.yaml 'a.(child.subchild==co*).c' true
|
||||
yq write things.yaml 'a.b.c' --tag '!!str' true # force 'true' to be interpreted as a string instead of bool
|
||||
yq write things.yaml 'a.b.c' --tag '!!float' 3
|
||||
yq write --inplace -- things.yaml 'a.b.c' '--cat' # need to use '--' to stop processing arguments as flags
|
||||
yq w -i things.yaml 'a.b.c' cat
|
||||
yq w -i -s update_script.yaml things.yaml
|
||||
yq w things.yaml 'a.b.d[+]' foo # appends a new node to the 'd' array
|
||||
yq w --doc 2 things.yaml 'a.b.d[+]' foo # updates the 3rd document of the yaml file
|
||||
`,
|
||||
Long: `Updates the yaml file w.r.t the given path and value.
|
||||
Outputs to STDOUT unless the inplace flag is used, in which case the file is updated instead.
|
||||
|
||||
Append value to array adds the value to the end of array.
|
||||
|
||||
Update Scripts:
|
||||
Note that you can give an update script to perform more sophisticated update. Update script
|
||||
format is list of update commands (update or delete) like so:
|
||||
---
|
||||
- command: update
|
||||
path: b.c
|
||||
value:
|
||||
#great
|
||||
things: frog # wow!
|
||||
- command: delete
|
||||
path: b.d
|
||||
`,
|
||||
RunE: writeProperty,
|
||||
}
|
||||
cmdWrite.PersistentFlags().BoolVarP(&writeInplace, "inplace", "i", false, "update the yaml file inplace")
|
||||
cmdWrite.PersistentFlags().StringVarP(&writeScript, "script", "s", "", "yaml script for updating yaml")
|
||||
cmdWrite.PersistentFlags().StringVarP(&customTag, "tag", "t", "", "set yaml tag (e.g. !!int)")
|
||||
cmdWrite.PersistentFlags().StringVarP(&docIndex, "doc", "d", "0", "process document index number (0 based, * for all documents)")
|
||||
return cmdWrite
|
||||
}
|
||||
|
||||
func writeProperty(cmd *cobra.Command, args []string) error {
|
||||
var updateCommands, updateCommandsError = readUpdateCommands(args, 3, "Must provide <filename> <path_to_update> <value>")
|
||||
if updateCommandsError != nil {
|
||||
return updateCommandsError
|
||||
}
|
||||
return updateDoc(args[0], updateCommands, cmd.OutOrStdout())
|
||||
}
|
13
compare.sh
Executable file
13
compare.sh
Executable file
@ -0,0 +1,13 @@
|
||||
GREEN='\033[0;32m'
|
||||
NC='\033[0m'
|
||||
|
||||
echo "${GREEN}---Old---${NC}"
|
||||
yq $@ > /tmp/yq-old-output
|
||||
cat /tmp/yq-old-output
|
||||
|
||||
echo "${GREEN}---New---${NC}"
|
||||
./yq $@ > /tmp/yq-new-output
|
||||
cat /tmp/yq-new-output
|
||||
|
||||
echo "${GREEN}---Diff---${NC}"
|
||||
colordiff /tmp/yq-old-output /tmp/yq-new-output
|
130
docs/404.html
130
docs/404.html
@ -32,7 +32,7 @@
|
||||
<meta name="lang:search.tokenizer" content="[\s\-]+">
|
||||
|
||||
<link rel="shortcut icon" href="/assets/images/favicon.png">
|
||||
<meta name="generator" content="mkdocs-1.0.4, mkdocs-material-4.2.0">
|
||||
<meta name="generator" content="mkdocs-1.0.4, mkdocs-material-4.6.0">
|
||||
|
||||
|
||||
|
||||
@ -40,17 +40,17 @@
|
||||
|
||||
|
||||
|
||||
<link rel="stylesheet" href="/assets/stylesheets/application.750b69bd.css">
|
||||
<link rel="stylesheet" href="/assets/stylesheets/application.1b62728e.css">
|
||||
|
||||
|
||||
|
||||
|
||||
<script src="/assets/javascripts/modernizr.74668098.js"></script>
|
||||
<script src="/assets/javascripts/modernizr.268332fc.js"></script>
|
||||
|
||||
|
||||
|
||||
<link href="https://fonts.gstatic.com" rel="preconnect" crossorigin>
|
||||
<link rel="stylesheet" href="https://fonts.googleapis.com/css?family=Roboto:300,400,400i,700|Roboto+Mono">
|
||||
<link rel="stylesheet" href="https://fonts.googleapis.com/css?family=Roboto:300,400,400i,700%7CRoboto+Mono&display=fallback">
|
||||
<style>body,input{font-family:"Roboto","Helvetica Neue",Helvetica,Arial,sans-serif}code,kbd,pre{font-family:"Roboto Mono","Courier New",Courier,monospace}</style>
|
||||
|
||||
|
||||
@ -69,24 +69,7 @@
|
||||
<defs>
|
||||
|
||||
|
||||
<svg xmlns="http://www.w3.org/2000/svg" width="416" height="448"
|
||||
viewBox="0 0 416 448" id="__github">
|
||||
<path fill="currentColor" d="M160 304q0 10-3.125 20.5t-10.75 19-18.125
|
||||
8.5-18.125-8.5-10.75-19-3.125-20.5 3.125-20.5 10.75-19 18.125-8.5
|
||||
18.125 8.5 10.75 19 3.125 20.5zM320 304q0 10-3.125 20.5t-10.75
|
||||
19-18.125 8.5-18.125-8.5-10.75-19-3.125-20.5 3.125-20.5 10.75-19
|
||||
18.125-8.5 18.125 8.5 10.75 19 3.125 20.5zM360
|
||||
304q0-30-17.25-51t-46.75-21q-10.25 0-48.75 5.25-17.75 2.75-39.25
|
||||
2.75t-39.25-2.75q-38-5.25-48.75-5.25-29.5 0-46.75 21t-17.25 51q0 22 8
|
||||
38.375t20.25 25.75 30.5 15 35 7.375 37.25 1.75h42q20.5 0
|
||||
37.25-1.75t35-7.375 30.5-15 20.25-25.75 8-38.375zM416 260q0 51.75-15.25
|
||||
82.75-9.5 19.25-26.375 33.25t-35.25 21.5-42.5 11.875-42.875 5.5-41.75
|
||||
1.125q-19.5 0-35.5-0.75t-36.875-3.125-38.125-7.5-34.25-12.875-30.25-20.25-21.5-28.75q-15.5-30.75-15.5-82.75
|
||||
0-59.25 34-99-6.75-20.5-6.75-42.5 0-29 12.75-54.5 27 0 47.5 9.875t47.25
|
||||
30.875q36.75-8.75 77.25-8.75 37 0 70 8 26.25-20.5
|
||||
46.75-30.25t47.25-9.75q12.75 25.5 12.75 54.5 0 21.75-6.75 42 34 40 34
|
||||
99.5z" />
|
||||
</svg>
|
||||
<svg xmlns="http://www.w3.org/2000/svg" width="416" height="448" viewBox="0 0 416 448" id="__github"><path fill="currentColor" d="M160 304q0 10-3.125 20.5t-10.75 19T128 352t-18.125-8.5-10.75-19T96 304t3.125-20.5 10.75-19T128 256t18.125 8.5 10.75 19T160 304zm160 0q0 10-3.125 20.5t-10.75 19T288 352t-18.125-8.5-10.75-19T256 304t3.125-20.5 10.75-19T288 256t18.125 8.5 10.75 19T320 304zm40 0q0-30-17.25-51T296 232q-10.25 0-48.75 5.25Q229.5 240 208 240t-39.25-2.75Q130.75 232 120 232q-29.5 0-46.75 21T56 304q0 22 8 38.375t20.25 25.75 30.5 15 35 7.375 37.25 1.75h42q20.5 0 37.25-1.75t35-7.375 30.5-15 20.25-25.75T360 304zm56-44q0 51.75-15.25 82.75-9.5 19.25-26.375 33.25t-35.25 21.5-42.5 11.875-42.875 5.5T212 416q-19.5 0-35.5-.75t-36.875-3.125-38.125-7.5-34.25-12.875T37 371.5t-21.5-28.75Q0 312 0 260q0-59.25 34-99-6.75-20.5-6.75-42.5 0-29 12.75-54.5 27 0 47.5 9.875t47.25 30.875Q171.5 96 212 96q37 0 70 8 26.25-20.5 46.75-30.25T376 64q12.75 25.5 12.75 54.5 0 21.75-6.75 42 34 40 34 99.5z"/></svg>
|
||||
|
||||
</defs>
|
||||
</svg>
|
||||
@ -116,6 +99,8 @@
|
||||
</span>
|
||||
<span class="md-header-nav__topic">
|
||||
|
||||
|
||||
|
||||
</span>
|
||||
|
||||
</div>
|
||||
@ -180,7 +165,7 @@
|
||||
|
||||
|
||||
|
||||
<main class="md-main">
|
||||
<main class="md-main" role="main">
|
||||
<div class="md-main__inner md-grid" data-md-component="container">
|
||||
|
||||
|
||||
@ -225,92 +210,8 @@
|
||||
|
||||
|
||||
<li class="md-nav__item">
|
||||
<a href="/." title="Install" class="md-nav__link">
|
||||
Install
|
||||
</a>
|
||||
</li>
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
<li class="md-nav__item">
|
||||
<a href="/read/" title="Read" class="md-nav__link">
|
||||
Read
|
||||
</a>
|
||||
</li>
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
<li class="md-nav__item">
|
||||
<a href="/write/" title="Write/Update" class="md-nav__link">
|
||||
Write/Update
|
||||
</a>
|
||||
</li>
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
<li class="md-nav__item">
|
||||
<a href="/prefix/" title="Prefix" class="md-nav__link">
|
||||
Prefix
|
||||
</a>
|
||||
</li>
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
<li class="md-nav__item">
|
||||
<a href="/delete/" title="Delete" class="md-nav__link">
|
||||
Delete
|
||||
</a>
|
||||
</li>
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
<li class="md-nav__item">
|
||||
<a href="/create/" title="Create" class="md-nav__link">
|
||||
Create
|
||||
</a>
|
||||
</li>
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
<li class="md-nav__item">
|
||||
<a href="/convert/" title="Convert" class="md-nav__link">
|
||||
Convert
|
||||
</a>
|
||||
</li>
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
<li class="md-nav__item">
|
||||
<a href="/merge/" title="Merge" class="md-nav__link">
|
||||
Merge
|
||||
<a href="/." title="Home" class="md-nav__link">
|
||||
Home
|
||||
</a>
|
||||
</li>
|
||||
|
||||
@ -352,22 +253,13 @@
|
||||
Material for MkDocs</a>
|
||||
</div>
|
||||
|
||||
<div class="md-footer-social">
|
||||
<link rel="stylesheet" href="/assets/fonts/font-awesome.css">
|
||||
|
||||
<a href="https://github.com/mikefarah" class="md-footer-social__link fa fa-github"></a>
|
||||
|
||||
<a href="https://www.linkedin.com/in/mike-farah-b5a75b2/" class="md-footer-social__link fa fa-linkedin"></a>
|
||||
|
||||
</div>
|
||||
|
||||
</div>
|
||||
</div>
|
||||
</footer>
|
||||
|
||||
</div>
|
||||
|
||||
<script src="/assets/javascripts/application.39abc4af.js"></script>
|
||||
<script src="/assets/javascripts/application.808e90bb.js"></script>
|
||||
|
||||
<script>app.initialize({version:"1.0.4",url:{base:"/"}})</script>
|
||||
|
||||
|
@ -1,20 +1 @@
|
||||
<svg xmlns="http://www.w3.org/2000/svg" width="352" height="448"
|
||||
viewBox="0 0 352 448" id="__bitbucket">
|
||||
<path fill="currentColor" d="M203.75 214.75q2 15.75-12.625 25.25t-27.875
|
||||
1.5q-9.75-4.25-13.375-14.5t-0.125-20.5 13-14.5q9-4.5 18.125-3t16 8.875
|
||||
6.875 16.875zM231.5 209.5q-3.5-26.75-28.25-41t-49.25-3.25q-15.75
|
||||
7-25.125 22.125t-8.625 32.375q1 22.75 19.375 38.75t41.375 14q22.75-2
|
||||
38-21t12.5-42zM291.25
|
||||
74q-5-6.75-14-11.125t-14.5-5.5-17.75-3.125q-72.75-11.75-141.5 0.5-10.75
|
||||
1.75-16.5 3t-13.75 5.5-12.5 10.75q7.5 7 19 11.375t18.375 5.5 21.875
|
||||
2.875q57 7.25 112 0.25 15.75-2 22.375-3t18.125-5.375 18.75-11.625zM305.5
|
||||
332.75q-2 6.5-3.875 19.125t-3.5 21-7.125 17.5-14.5 14.125q-21.5
|
||||
12-47.375 17.875t-50.5 5.5-50.375-4.625q-11.5-2-20.375-4.5t-19.125-6.75-18.25-10.875-13-15.375q-6.25-24-14.25-73l1.5-4
|
||||
4.5-2.25q55.75 37 126.625 37t126.875-37q5.25 1.5 6 5.75t-1.25 11.25-2
|
||||
9.25zM350.75 92.5q-6.5 41.75-27.75 163.75-1.25 7.5-6.75 14t-10.875
|
||||
10-13.625 7.75q-63 31.5-152.5
|
||||
22-62-6.75-98.5-34.75-3.75-3-6.375-6.625t-4.25-8.75-2.25-8.5-1.5-9.875-1.375-8.75q-2.25-12.5-6.625-37.5t-7-40.375-5.875-36.875-5.5-39.5q0.75-6.5
|
||||
4.375-12.125t7.875-9.375 11.25-7.5 11.5-5.625 12-4.625q31.25-11.5
|
||||
78.25-16 94.75-9.25 169 12.5 38.75 11.5 53.75 30.5 4 5 4.125
|
||||
12.75t-1.375 13.5z" />
|
||||
</svg>
|
||||
<svg xmlns="http://www.w3.org/2000/svg" width="352" height="448" viewBox="0 0 352 448" id="__bitbucket"><path fill="currentColor" d="M203.75 214.75q2 15.75-12.625 25.25t-27.875 1.5q-9.75-4.25-13.375-14.5t-.125-20.5 13-14.5q9-4.5 18.125-3t16 8.875 6.875 16.875zm27.75-5.25q-3.5-26.75-28.25-41T154 165.25q-15.75 7-25.125 22.125t-8.625 32.375q1 22.75 19.375 38.75t41.375 14q22.75-2 38-21t12.5-42zM291.25 74q-5-6.75-14-11.125t-14.5-5.5T245 54.25q-72.75-11.75-141.5.5-10.75 1.75-16.5 3t-13.75 5.5T60.75 74q7.5 7 19 11.375t18.375 5.5T120 93.75Q177 101 232 94q15.75-2 22.375-3t18.125-5.375T291.25 74zm14.25 258.75q-2 6.5-3.875 19.125t-3.5 21-7.125 17.5-14.5 14.125q-21.5 12-47.375 17.875t-50.5 5.5-50.375-4.625q-11.5-2-20.375-4.5T88.75 412 70.5 401.125t-13-15.375q-6.25-24-14.25-73l1.5-4 4.5-2.25q55.75 37 126.625 37t126.875-37q5.25 1.5 6 5.75t-1.25 11.25-2 9.25zM350.75 92.5q-6.5 41.75-27.75 163.75-1.25 7.5-6.75 14t-10.875 10T291.75 288q-63 31.5-152.5 22-62-6.75-98.5-34.75-3.75-3-6.375-6.625t-4.25-8.75-2.25-8.5-1.5-9.875T25 232.75q-2.25-12.5-6.625-37.5t-7-40.375T5.5 118 0 78.5Q.75 72 4.375 66.375T12.25 57t11.25-7.5T35 43.875t12-4.625q31.25-11.5 78.25-16 94.75-9.25 169 12.5Q333 47.25 348 66.25q4 5 4.125 12.75t-1.375 13.5z"/></svg>
|
Before Width: | Height: | Size: 1.4 KiB After Width: | Height: | Size: 1.2 KiB |
@ -1,18 +1 @@
|
||||
<svg xmlns="http://www.w3.org/2000/svg" width="416" height="448"
|
||||
viewBox="0 0 416 448" id="__github">
|
||||
<path fill="currentColor" d="M160 304q0 10-3.125 20.5t-10.75 19-18.125
|
||||
8.5-18.125-8.5-10.75-19-3.125-20.5 3.125-20.5 10.75-19 18.125-8.5
|
||||
18.125 8.5 10.75 19 3.125 20.5zM320 304q0 10-3.125 20.5t-10.75
|
||||
19-18.125 8.5-18.125-8.5-10.75-19-3.125-20.5 3.125-20.5 10.75-19
|
||||
18.125-8.5 18.125 8.5 10.75 19 3.125 20.5zM360
|
||||
304q0-30-17.25-51t-46.75-21q-10.25 0-48.75 5.25-17.75 2.75-39.25
|
||||
2.75t-39.25-2.75q-38-5.25-48.75-5.25-29.5 0-46.75 21t-17.25 51q0 22 8
|
||||
38.375t20.25 25.75 30.5 15 35 7.375 37.25 1.75h42q20.5 0
|
||||
37.25-1.75t35-7.375 30.5-15 20.25-25.75 8-38.375zM416 260q0 51.75-15.25
|
||||
82.75-9.5 19.25-26.375 33.25t-35.25 21.5-42.5 11.875-42.875 5.5-41.75
|
||||
1.125q-19.5 0-35.5-0.75t-36.875-3.125-38.125-7.5-34.25-12.875-30.25-20.25-21.5-28.75q-15.5-30.75-15.5-82.75
|
||||
0-59.25 34-99-6.75-20.5-6.75-42.5 0-29 12.75-54.5 27 0 47.5 9.875t47.25
|
||||
30.875q36.75-8.75 77.25-8.75 37 0 70 8 26.25-20.5
|
||||
46.75-30.25t47.25-9.75q12.75 25.5 12.75 54.5 0 21.75-6.75 42 34 40 34
|
||||
99.5z" />
|
||||
</svg>
|
||||
<svg xmlns="http://www.w3.org/2000/svg" width="416" height="448" viewBox="0 0 416 448" id="__github"><path fill="currentColor" d="M160 304q0 10-3.125 20.5t-10.75 19T128 352t-18.125-8.5-10.75-19T96 304t3.125-20.5 10.75-19T128 256t18.125 8.5 10.75 19T160 304zm160 0q0 10-3.125 20.5t-10.75 19T288 352t-18.125-8.5-10.75-19T256 304t3.125-20.5 10.75-19T288 256t18.125 8.5 10.75 19T320 304zm40 0q0-30-17.25-51T296 232q-10.25 0-48.75 5.25Q229.5 240 208 240t-39.25-2.75Q130.75 232 120 232q-29.5 0-46.75 21T56 304q0 22 8 38.375t20.25 25.75 30.5 15 35 7.375 37.25 1.75h42q20.5 0 37.25-1.75t35-7.375 30.5-15 20.25-25.75T360 304zm56-44q0 51.75-15.25 82.75-9.5 19.25-26.375 33.25t-35.25 21.5-42.5 11.875-42.875 5.5T212 416q-19.5 0-35.5-.75t-36.875-3.125-38.125-7.5-34.25-12.875T37 371.5t-21.5-28.75Q0 312 0 260q0-59.25 34-99-6.75-20.5-6.75-42.5 0-29 12.75-54.5 27 0 47.5 9.875t47.25 30.875Q171.5 96 212 96q37 0 70 8 26.25-20.5 46.75-30.25T376 64q12.75 25.5 12.75 54.5 0 21.75-6.75 42 34 40 34 99.5z"/></svg>
|
Before Width: | Height: | Size: 1.2 KiB After Width: | Height: | Size: 993 B |
@ -1,38 +1 @@
|
||||
<svg xmlns="http://www.w3.org/2000/svg" width="500" height="500"
|
||||
viewBox="0 0 500 500" id="__gitlab">
|
||||
<g transform="translate(156.197863, 1.160267)">
|
||||
<path fill="currentColor"
|
||||
d="M93.667,473.347L93.667,473.347l90.684-279.097H2.983L93.667,
|
||||
473.347L93.667,473.347z" />
|
||||
</g>
|
||||
<g transform="translate(28.531199, 1.160800)" opacity="0.7">
|
||||
<path fill="currentColor"
|
||||
d="M221.333,473.345L130.649,194.25H3.557L221.333,473.345L221.333,
|
||||
473.345z" />
|
||||
</g>
|
||||
<g transform="translate(0.088533, 0.255867)" opacity="0.5">
|
||||
<path fill="currentColor"
|
||||
d="M32,195.155L32,195.155L4.441,279.97c-2.513,7.735,0.24,16.21,6.821,
|
||||
20.99l238.514,173.29 L32,195.155L32,195.155z" />
|
||||
</g>
|
||||
<g transform="translate(29.421866, 280.255593)">
|
||||
<path fill="currentColor"
|
||||
d="M2.667-84.844h127.092L75.14-252.942c-2.811-8.649-15.047-8.649-17.856,
|
||||
0L2.667-84.844 L2.667-84.844z" />
|
||||
</g>
|
||||
<g transform="translate(247.197860, 1.160800)" opacity="0.7">
|
||||
<path fill="currentColor"
|
||||
d="M2.667,473.345L93.351,194.25h127.092L2.667,473.345L2.667,
|
||||
473.345z" />
|
||||
</g>
|
||||
<g transform="translate(246.307061, 0.255867)" opacity="0.5">
|
||||
<path fill="currentColor"
|
||||
d="M221.334,195.155L221.334,195.155l27.559,84.815c2.514,7.735-0.24,
|
||||
16.21-6.821,20.99 L3.557,474.25L221.334,195.155L221.334,195.155z" />
|
||||
</g>
|
||||
<g transform="translate(336.973725, 280.255593)">
|
||||
<path fill="currentColor"
|
||||
d="M130.667-84.844H3.575l54.618-168.098c2.811-8.649,15.047-8.649,
|
||||
17.856,0L130.667-84.844 L130.667-84.844z" />
|
||||
</g>
|
||||
</svg>
|
||||
<svg xmlns="http://www.w3.org/2000/svg" width="500" height="500" viewBox="0 0 500 500" id="__gitlab"><path fill="currentColor" d="M93.667 473.347l90.684-279.097H2.983l90.684 279.097z" transform="translate(156.198 1.16)"/><path fill="currentColor" d="M221.333 473.345L130.649 194.25H3.557l217.776 279.095z" transform="translate(28.531 1.16)" opacity=".7"/><path fill="currentColor" d="M32 195.155L4.441 279.97a18.773 18.773 0 0 0 6.821 20.99l238.514 173.29L32 195.155z" transform="translate(.089 .256)" opacity=".5"/><path fill="currentColor" d="M2.667-84.844h127.092L75.14-252.942c-2.811-8.649-15.047-8.649-17.856 0L2.667-84.844z" transform="translate(29.422 280.256)"/><path fill="currentColor" d="M2.667 473.345L93.351 194.25h127.092L2.667 473.345z" transform="translate(247.198 1.16)" opacity=".7"/><path fill="currentColor" d="M221.334 195.155l27.559 84.815a18.772 18.772 0 0 1-6.821 20.99L3.557 474.25l217.777-279.095z" transform="translate(246.307 .256)" opacity=".5"/><path fill="currentColor" d="M130.667-84.844H3.575l54.618-168.098c2.811-8.649 15.047-8.649 17.856 0l54.618 168.098z" transform="translate(336.974 280.256)"/></svg>
|
Before Width: | Height: | Size: 1.6 KiB After Width: | Height: | Size: 1.1 KiB |
File diff suppressed because one or more lines are too long
60
docs/assets/javascripts/application.808e90bb.js
Normal file
60
docs/assets/javascripts/application.808e90bb.js
Normal file
File diff suppressed because one or more lines are too long
20
docs/assets/javascripts/lunr/lunr.ar.js
Normal file
20
docs/assets/javascripts/lunr/lunr.ar.js
Normal file
File diff suppressed because one or more lines are too long
@ -1 +1,17 @@
|
||||
/*!
|
||||
* Lunr languages, `Danish` language
|
||||
* https://github.com/MihaiValentin/lunr-languages
|
||||
*
|
||||
* Copyright 2014, Mihai Valentin
|
||||
* http://www.mozilla.org/MPL/
|
||||
*/
|
||||
/*!
|
||||
* based on
|
||||
* Snowball JavaScript Library v0.3
|
||||
* http://code.google.com/p/urim/
|
||||
* http://snowball.tartarus.org/
|
||||
*
|
||||
* Copyright 2010, Oleg Mazko
|
||||
* http://www.mozilla.org/MPL/
|
||||
*/
|
||||
!function(e,r){"function"==typeof define&&define.amd?define(r):"object"==typeof exports?module.exports=r():r()(e.lunr)}(this,function(){return function(e){if(void 0===e)throw new Error("Lunr is not present. Please include / require Lunr before this script.");if(void 0===e.stemmerSupport)throw new Error("Lunr stemmer support is not present. Please include / require Lunr stemmer support before this script.");var r,m,i;e.da=function(){this.pipeline.reset(),this.pipeline.add(e.da.trimmer,e.da.stopWordFilter,e.da.stemmer),this.searchPipeline&&(this.searchPipeline.reset(),this.searchPipeline.add(e.da.stemmer))},e.da.wordCharacters="A-Za-zªºÀ-ÖØ-öø-ʸˠ-ˤᴀ-ᴥᴬ-ᵜᵢ-ᵥᵫ-ᵷᵹ-ᶾḀ-ỿⁱⁿₐ-ₜKÅℲⅎⅠ-ↈⱠ-ⱿꜢ-ꞇꞋ-ꞭꞰ-ꞷꟷ-ꟿꬰ-ꭚꭜ-ꭤff-stA-Za-z",e.da.trimmer=e.trimmerSupport.generateTrimmer(e.da.wordCharacters),e.Pipeline.registerFunction(e.da.trimmer,"trimmer-da"),e.da.stemmer=(r=e.stemmerSupport.Among,m=e.stemmerSupport.SnowballProgram,i=new function(){var i,t,n,s=[new r("hed",-1,1),new r("ethed",0,1),new r("ered",-1,1),new r("e",-1,1),new r("erede",3,1),new r("ende",3,1),new r("erende",5,1),new r("ene",3,1),new r("erne",3,1),new r("ere",3,1),new r("en",-1,1),new r("heden",10,1),new r("eren",10,1),new r("er",-1,1),new r("heder",13,1),new r("erer",13,1),new r("s",-1,2),new r("heds",16,1),new r("es",16,1),new r("endes",18,1),new r("erendes",19,1),new r("enes",18,1),new r("ernes",18,1),new r("eres",18,1),new r("ens",16,1),new r("hedens",24,1),new r("erens",24,1),new r("ers",16,1),new r("ets",16,1),new r("erets",28,1),new r("et",-1,1),new r("eret",30,1)],o=[new r("gd",-1,-1),new r("dt",-1,-1),new r("gt",-1,-1),new r("kt",-1,-1)],a=[new r("ig",-1,1),new r("lig",0,1),new r("elig",1,1),new r("els",-1,1),new r("løst",-1,2)],d=[17,65,16,1,0,0,0,0,0,0,0,0,0,0,0,0,48,0,128],u=[239,254,42,3,0,0,0,0,0,0,0,0,0,0,0,0,16],c=new m;function l(){var e,r=c.limit-c.cursor;c.cursor>=t&&(e=c.limit_backward,c.limit_backward=t,c.ket=c.cursor,c.find_among_b(o,4)?(c.bra=c.cursor,c.limit_backward=e,c.cursor=c.limit-r,c.cursor>c.limit_backward&&(c.cursor--,c.bra=c.cursor,c.slice_del())):c.limit_backward=e)}this.setCurrent=function(e){c.setCurrent(e)},this.getCurrent=function(){return c.getCurrent()},this.stem=function(){var e,r=c.cursor;return function(){var e,r=c.cursor+3;if(t=c.limit,0<=r&&r<=c.limit){for(i=r;;){if(e=c.cursor,c.in_grouping(d,97,248)){c.cursor=e;break}if((c.cursor=e)>=c.limit)return;c.cursor++}for(;!c.out_grouping(d,97,248);){if(c.cursor>=c.limit)return;c.cursor++}(t=c.cursor)<i&&(t=i)}}(),c.limit_backward=r,c.cursor=c.limit,function(){var e,r;if(c.cursor>=t&&(r=c.limit_backward,c.limit_backward=t,c.ket=c.cursor,e=c.find_among_b(s,32),c.limit_backward=r,e))switch(c.bra=c.cursor,e){case 1:c.slice_del();break;case 2:c.in_grouping_b(u,97,229)&&c.slice_del()}}(),c.cursor=c.limit,l(),c.cursor=c.limit,function(){var e,r,i,n=c.limit-c.cursor;if(c.ket=c.cursor,c.eq_s_b(2,"st")&&(c.bra=c.cursor,c.eq_s_b(2,"ig")&&c.slice_del()),c.cursor=c.limit-n,c.cursor>=t&&(r=c.limit_backward,c.limit_backward=t,c.ket=c.cursor,e=c.find_among_b(a,5),c.limit_backward=r,e))switch(c.bra=c.cursor,e){case 1:c.slice_del(),i=c.limit-c.cursor,l(),c.cursor=c.limit-i;break;case 2:c.slice_from("løs")}}(),c.cursor=c.limit,c.cursor>=t&&(e=c.limit_backward,c.limit_backward=t,c.ket=c.cursor,c.out_grouping_b(d,97,248)?(c.bra=c.cursor,n=c.slice_to(n),c.limit_backward=e,c.eq_v_b(n)&&c.slice_del()):c.limit_backward=e),!0}},function(e){return"function"==typeof e.update?e.update(function(e){return i.setCurrent(e),i.stem(),i.getCurrent()}):(i.setCurrent(e),i.stem(),i.getCurrent())}),e.Pipeline.registerFunction(e.da.stemmer,"stemmer-da"),e.da.stopWordFilter=e.generateStopWordFilter("ad af alle alt anden at blev blive bliver da de dem den denne der deres det dette dig din disse dog du efter eller en end er et for fra ham han hans har havde have hende hendes her hos hun hvad hvis hvor i ikke ind jeg jer jo kunne man mange med meget men mig min mine mit mod ned noget nogle nu når og også om op os over på selv sig sin sine sit skal skulle som sådan thi til ud under var vi vil ville vor være været".split(" ")),e.Pipeline.registerFunction(e.da.stopWordFilter,"stopWordFilter-da")}});
|
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 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
@ -1 +1,17 @@
|
||||
/*!
|
||||
* Lunr languages, `Japanese` language
|
||||
* https://github.com/MihaiValentin/lunr-languages
|
||||
*
|
||||
* Copyright 2014, Chad Liu
|
||||
* http://www.mozilla.org/MPL/
|
||||
*/
|
||||
/*!
|
||||
* based on
|
||||
* Snowball JavaScript Library v0.3
|
||||
* http://code.google.com/p/urim/
|
||||
* http://snowball.tartarus.org/
|
||||
*
|
||||
* Copyright 2010, Oleg Mazko
|
||||
* http://www.mozilla.org/MPL/
|
||||
*/
|
||||
!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-Za-zA-Z0-90-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")}});
|
@ -1 +1 @@
|
||||
!function(e,i){"function"==typeof define&&define.amd?define(i):"object"==typeof exports?module.exports=i():i()(e.lunr)}(this,function(){return function(o){o.multiLanguage=function(){for(var e=Array.prototype.slice.call(arguments),i=e.join("-"),t="",r=[],n=[],s=0;s<e.length;++s)"en"==e[s]?(t+="\\w",r.unshift(o.stopWordFilter),r.push(o.stemmer),n.push(o.stemmer)):(t+=o[e[s]].wordCharacters,r.unshift(o[e[s]].stopWordFilter),r.push(o[e[s]].stemmer),n.push(o[e[s]].stemmer));var p=o.trimmerSupport.generateTrimmer(t);return o.Pipeline.registerFunction(p,"lunr-multi-trimmer-"+i),r.unshift(p),function(){this.pipeline.reset(),this.pipeline.add.apply(this.pipeline,r),this.searchPipeline&&(this.searchPipeline.reset(),this.searchPipeline.add.apply(this.searchPipeline,n))}}}});
|
||||
!function(e,t){"function"==typeof define&&define.amd?define(t):"object"==typeof exports?module.exports=t():t()(e.lunr)}(this,function(){return function(o){o.multiLanguage=function(){for(var e=Array.prototype.slice.call(arguments),t=e.join("-"),i="",r=[],n=[],s=0;s<e.length;++s)"en"==e[s]?(i+="\\w",r.unshift(o.stopWordFilter),r.push(o.stemmer),n.push(o.stemmer)):(i+=o[e[s]].wordCharacters,o[e[s]].stopWordFilter&&r.unshift(o[e[s]].stopWordFilter),o[e[s]].stemmer&&(r.push(o[e[s]].stemmer),n.push(o[e[s]].stemmer)));var p=o.trimmerSupport.generateTrimmer(i);return o.Pipeline.registerFunction(p,"lunr-multi-trimmer-"+t),r.unshift(p),function(){this.pipeline.reset(),this.pipeline.add.apply(this.pipeline,r),this.searchPipeline&&(this.searchPipeline.reset(),this.searchPipeline.add.apply(this.searchPipeline,n))}}}});
|
File diff suppressed because one or more lines are too long
@ -1 +1,17 @@
|
||||
/*!
|
||||
* Lunr languages, `Norwegian` language
|
||||
* https://github.com/MihaiValentin/lunr-languages
|
||||
*
|
||||
* Copyright 2014, Mihai Valentin
|
||||
* http://www.mozilla.org/MPL/
|
||||
*/
|
||||
/*!
|
||||
* based on
|
||||
* Snowball JavaScript Library v0.3
|
||||
* http://code.google.com/p/urim/
|
||||
* http://snowball.tartarus.org/
|
||||
*
|
||||
* Copyright 2010, Oleg Mazko
|
||||
* http://www.mozilla.org/MPL/
|
||||
*/
|
||||
!function(e,r){"function"==typeof define&&define.amd?define(r):"object"==typeof exports?module.exports=r():r()(e.lunr)}(this,function(){return function(e){if(void 0===e)throw new Error("Lunr is not present. Please include / require Lunr before this script.");if(void 0===e.stemmerSupport)throw new Error("Lunr stemmer support is not present. Please include / require Lunr stemmer support before this script.");var r,n,i;e.no=function(){this.pipeline.reset(),this.pipeline.add(e.no.trimmer,e.no.stopWordFilter,e.no.stemmer),this.searchPipeline&&(this.searchPipeline.reset(),this.searchPipeline.add(e.no.stemmer))},e.no.wordCharacters="A-Za-zªºÀ-ÖØ-öø-ʸˠ-ˤᴀ-ᴥᴬ-ᵜᵢ-ᵥᵫ-ᵷᵹ-ᶾḀ-ỿⁱⁿₐ-ₜKÅℲⅎⅠ-ↈⱠ-ⱿꜢ-ꞇꞋ-ꞭꞰ-ꞷꟷ-ꟿꬰ-ꭚꭜ-ꭤff-stA-Za-z",e.no.trimmer=e.trimmerSupport.generateTrimmer(e.no.wordCharacters),e.Pipeline.registerFunction(e.no.trimmer,"trimmer-no"),e.no.stemmer=(r=e.stemmerSupport.Among,n=e.stemmerSupport.SnowballProgram,i=new function(){var o,s,a=[new r("a",-1,1),new r("e",-1,1),new r("ede",1,1),new r("ande",1,1),new r("ende",1,1),new r("ane",1,1),new r("ene",1,1),new r("hetene",6,1),new r("erte",1,3),new r("en",-1,1),new r("heten",9,1),new r("ar",-1,1),new r("er",-1,1),new r("heter",12,1),new r("s",-1,2),new r("as",14,1),new r("es",14,1),new r("edes",16,1),new r("endes",16,1),new r("enes",16,1),new r("hetenes",19,1),new r("ens",14,1),new r("hetens",21,1),new r("ers",14,1),new r("ets",14,1),new r("et",-1,1),new r("het",25,1),new r("ert",-1,3),new r("ast",-1,1)],m=[new r("dt",-1,-1),new r("vt",-1,-1)],l=[new r("leg",-1,1),new r("eleg",0,1),new r("ig",-1,1),new r("eig",2,1),new r("lig",2,1),new r("elig",4,1),new r("els",-1,1),new r("lov",-1,1),new r("elov",7,1),new r("slov",7,1),new r("hetslov",9,1)],u=[17,65,16,1,0,0,0,0,0,0,0,0,0,0,0,0,48,0,128],d=[119,125,149,1],c=new n;this.setCurrent=function(e){c.setCurrent(e)},this.getCurrent=function(){return c.getCurrent()},this.stem=function(){var e,r,n,i,t=c.cursor;return function(){var e,r=c.cursor+3;if(s=c.limit,0<=r||r<=c.limit){for(o=r;;){if(e=c.cursor,c.in_grouping(u,97,248)){c.cursor=e;break}if(e>=c.limit)return;c.cursor=e+1}for(;!c.out_grouping(u,97,248);){if(c.cursor>=c.limit)return;c.cursor++}(s=c.cursor)<o&&(s=o)}}(),c.limit_backward=t,c.cursor=c.limit,function(){var e,r,n;if(c.cursor>=s&&(r=c.limit_backward,c.limit_backward=s,c.ket=c.cursor,e=c.find_among_b(a,29),c.limit_backward=r,e))switch(c.bra=c.cursor,e){case 1:c.slice_del();break;case 2:n=c.limit-c.cursor,c.in_grouping_b(d,98,122)?c.slice_del():(c.cursor=c.limit-n,c.eq_s_b(1,"k")&&c.out_grouping_b(u,97,248)&&c.slice_del());break;case 3:c.slice_from("er")}}(),c.cursor=c.limit,r=c.limit-c.cursor,c.cursor>=s&&(e=c.limit_backward,c.limit_backward=s,c.ket=c.cursor,c.find_among_b(m,2)?(c.bra=c.cursor,c.limit_backward=e,c.cursor=c.limit-r,c.cursor>c.limit_backward&&(c.cursor--,c.bra=c.cursor,c.slice_del())):c.limit_backward=e),c.cursor=c.limit,c.cursor>=s&&(i=c.limit_backward,c.limit_backward=s,c.ket=c.cursor,(n=c.find_among_b(l,11))?(c.bra=c.cursor,c.limit_backward=i,1==n&&c.slice_del()):c.limit_backward=i),!0}},function(e){return"function"==typeof e.update?e.update(function(e){return i.setCurrent(e),i.stem(),i.getCurrent()}):(i.setCurrent(e),i.stem(),i.getCurrent())}),e.Pipeline.registerFunction(e.no.stemmer,"stemmer-no"),e.no.stopWordFilter=e.generateStopWordFilter("alle at av bare begge ble blei bli blir blitt både båe da de deg dei deim deira deires dem den denne der dere deres det dette di din disse ditt du dykk dykkar då eg ein eit eitt eller elles en enn er et ett etter for fordi fra før ha hadde han hans har hennar henne hennes her hjå ho hoe honom hoss hossen hun hva hvem hver hvilke hvilken hvis hvor hvordan hvorfor i ikke ikkje ikkje ingen ingi inkje inn inni ja jeg kan kom korleis korso kun kunne kva kvar kvarhelst kven kvi kvifor man mange me med medan meg meget mellom men mi min mine mitt mot mykje ned no noe noen noka noko nokon nokor nokre nå når og også om opp oss over på samme seg selv si si sia sidan siden sin sine sitt sjøl skal skulle slik so som som somme somt så sånn til um upp ut uten var vart varte ved vere verte vi vil ville vore vors vort vår være være vært å".split(" ")),e.Pipeline.registerFunction(e.no.stopWordFilter,"stopWordFilter-no")}});
|
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
@ -1 +1,9 @@
|
||||
/*!
|
||||
* Snowball JavaScript Library v0.3
|
||||
* http://code.google.com/p/urim/
|
||||
* http://snowball.tartarus.org/
|
||||
*
|
||||
* Copyright 2010, Oleg Mazko
|
||||
* http://www.mozilla.org/MPL/
|
||||
*/
|
||||
!function(r,t){"function"==typeof define&&define.amd?define(t):"object"==typeof exports?module.exports=t():t()(r.lunr)}(this,function(){return function(r){r.stemmerSupport={Among:function(r,t,i,s){if(this.toCharArray=function(r){for(var t=r.length,i=new Array(t),s=0;s<t;s++)i[s]=r.charCodeAt(s);return i},!r&&""!=r||!t&&0!=t||!i)throw"Bad Among initialisation: s:"+r+", substring_i: "+t+", result: "+i;this.s_size=r.length,this.s=this.toCharArray(r),this.substring_i=t,this.result=i,this.method=s},SnowballProgram:function(){var b;return{bra:0,ket:0,limit:0,cursor:0,limit_backward:0,setCurrent:function(r){b=r,this.cursor=0,this.limit=r.length,this.limit_backward=0,this.bra=this.cursor,this.ket=this.limit},getCurrent:function(){var r=b;return b=null,r},in_grouping:function(r,t,i){if(this.cursor<this.limit){var s=b.charCodeAt(this.cursor);if(s<=i&&t<=s&&r[(s-=t)>>3]&1<<(7&s))return this.cursor++,!0}return!1},in_grouping_b:function(r,t,i){if(this.cursor>this.limit_backward){var s=b.charCodeAt(this.cursor-1);if(s<=i&&t<=s&&r[(s-=t)>>3]&1<<(7&s))return this.cursor--,!0}return!1},out_grouping:function(r,t,i){if(this.cursor<this.limit){var s=b.charCodeAt(this.cursor);if(i<s||s<t)return this.cursor++,!0;if(!(r[(s-=t)>>3]&1<<(7&s)))return this.cursor++,!0}return!1},out_grouping_b:function(r,t,i){if(this.cursor>this.limit_backward){var s=b.charCodeAt(this.cursor-1);if(i<s||s<t)return this.cursor--,!0;if(!(r[(s-=t)>>3]&1<<(7&s)))return this.cursor--,!0}return!1},eq_s:function(r,t){if(this.limit-this.cursor<r)return!1;for(var i=0;i<r;i++)if(b.charCodeAt(this.cursor+i)!=t.charCodeAt(i))return!1;return this.cursor+=r,!0},eq_s_b:function(r,t){if(this.cursor-this.limit_backward<r)return!1;for(var i=0;i<r;i++)if(b.charCodeAt(this.cursor-r+i)!=t.charCodeAt(i))return!1;return this.cursor-=r,!0},find_among:function(r,t){for(var i=0,s=t,e=this.cursor,n=this.limit,u=0,o=0,h=!1;;){for(var c=i+(s-i>>1),a=0,f=u<o?u:o,l=r[c],_=f;_<l.s_size;_++){if(e+f==n){a=-1;break}if(a=b.charCodeAt(e+f)-l.s[_])break;f++}if(a<0?(s=c,o=f):(i=c,u=f),s-i<=1){if(0<i||s==i||h)break;h=!0}}for(;;){if(u>=(l=r[i]).s_size){if(this.cursor=e+l.s_size,!l.method)return l.result;var m=l.method();if(this.cursor=e+l.s_size,m)return l.result}if((i=l.substring_i)<0)return 0}},find_among_b:function(r,t){for(var i=0,s=t,e=this.cursor,n=this.limit_backward,u=0,o=0,h=!1;;){for(var c=i+(s-i>>1),a=0,f=u<o?u:o,l=(_=r[c]).s_size-1-f;0<=l;l--){if(e-f==n){a=-1;break}if(a=b.charCodeAt(e-1-f)-_.s[l])break;f++}if(a<0?(s=c,o=f):(i=c,u=f),s-i<=1){if(0<i||s==i||h)break;h=!0}}for(;;){var _;if(u>=(_=r[i]).s_size){if(this.cursor=e-_.s_size,!_.method)return _.result;var m=_.method();if(this.cursor=e-_.s_size,m)return _.result}if((i=_.substring_i)<0)return 0}},replace_s:function(r,t,i){var s=i.length-(t-r);return b=b.substring(0,r)+i+b.substring(t),this.limit+=s,this.cursor>=t?this.cursor+=s:this.cursor>r&&(this.cursor=r),s},slice_check:function(){if(this.bra<0||this.bra>this.ket||this.ket>this.limit||this.limit>b.length)throw"faulty slice operation"},slice_from:function(r){this.slice_check(),this.replace_s(this.bra,this.ket,r)},slice_del:function(){this.slice_from("")},insert:function(r,t,i){var s=this.replace_s(r,t,i);r<=this.bra&&(this.bra+=s),r<=this.ket&&(this.ket+=s)},slice_to:function(){return this.slice_check(),b.substring(this.bra,this.ket)},eq_v_b:function(r){return this.eq_s_b(r.length,r)}}}},r.trimmerSupport={generateTrimmer:function(r){var t=new RegExp("^[^"+r+"]+"),i=new RegExp("[^"+r+"]+$");return function(r){return"function"==typeof r.update?r.update(function(r){return r.replace(t,"").replace(i,"")}):r.replace(t,"").replace(i,"")}}}}});
|
@ -1 +1,17 @@
|
||||
/*!
|
||||
* Lunr languages, `Swedish` language
|
||||
* https://github.com/MihaiValentin/lunr-languages
|
||||
*
|
||||
* Copyright 2014, Mihai Valentin
|
||||
* http://www.mozilla.org/MPL/
|
||||
*/
|
||||
/*!
|
||||
* based on
|
||||
* Snowball JavaScript Library v0.3
|
||||
* http://code.google.com/p/urim/
|
||||
* http://snowball.tartarus.org/
|
||||
*
|
||||
* Copyright 2010, Oleg Mazko
|
||||
* http://www.mozilla.org/MPL/
|
||||
*/
|
||||
!function(e,r){"function"==typeof define&&define.amd?define(r):"object"==typeof exports?module.exports=r():r()(e.lunr)}(this,function(){return function(e){if(void 0===e)throw new Error("Lunr is not present. Please include / require Lunr before this script.");if(void 0===e.stemmerSupport)throw new Error("Lunr stemmer support is not present. Please include / require Lunr stemmer support before this script.");var r,l,n;e.sv=function(){this.pipeline.reset(),this.pipeline.add(e.sv.trimmer,e.sv.stopWordFilter,e.sv.stemmer),this.searchPipeline&&(this.searchPipeline.reset(),this.searchPipeline.add(e.sv.stemmer))},e.sv.wordCharacters="A-Za-zªºÀ-ÖØ-öø-ʸˠ-ˤᴀ-ᴥᴬ-ᵜᵢ-ᵥᵫ-ᵷᵹ-ᶾḀ-ỿⁱⁿₐ-ₜKÅℲⅎⅠ-ↈⱠ-ⱿꜢ-ꞇꞋ-ꞭꞰ-ꞷꟷ-ꟿꬰ-ꭚꭜ-ꭤff-stA-Za-z",e.sv.trimmer=e.trimmerSupport.generateTrimmer(e.sv.wordCharacters),e.Pipeline.registerFunction(e.sv.trimmer,"trimmer-sv"),e.sv.stemmer=(r=e.stemmerSupport.Among,l=e.stemmerSupport.SnowballProgram,n=new function(){var n,t,i=[new r("a",-1,1),new r("arna",0,1),new r("erna",0,1),new r("heterna",2,1),new r("orna",0,1),new r("ad",-1,1),new r("e",-1,1),new r("ade",6,1),new r("ande",6,1),new r("arne",6,1),new r("are",6,1),new r("aste",6,1),new r("en",-1,1),new r("anden",12,1),new r("aren",12,1),new r("heten",12,1),new r("ern",-1,1),new r("ar",-1,1),new r("er",-1,1),new r("heter",18,1),new r("or",-1,1),new r("s",-1,2),new r("as",21,1),new r("arnas",22,1),new r("ernas",22,1),new r("ornas",22,1),new r("es",21,1),new r("ades",26,1),new r("andes",26,1),new r("ens",21,1),new r("arens",29,1),new r("hetens",29,1),new r("erns",21,1),new r("at",-1,1),new r("andet",-1,1),new r("het",-1,1),new r("ast",-1,1)],s=[new r("dd",-1,-1),new r("gd",-1,-1),new r("nn",-1,-1),new r("dt",-1,-1),new r("gt",-1,-1),new r("kt",-1,-1),new r("tt",-1,-1)],a=[new r("ig",-1,1),new r("lig",0,1),new r("els",-1,1),new r("fullt",-1,3),new r("löst",-1,2)],o=[17,65,16,1,0,0,0,0,0,0,0,0,0,0,0,0,24,0,32],u=[119,127,149],m=new l;this.setCurrent=function(e){m.setCurrent(e)},this.getCurrent=function(){return m.getCurrent()},this.stem=function(){var e,r=m.cursor;return function(){var e,r=m.cursor+3;if(t=m.limit,0<=r||r<=m.limit){for(n=r;;){if(e=m.cursor,m.in_grouping(o,97,246)){m.cursor=e;break}if(m.cursor=e,m.cursor>=m.limit)return;m.cursor++}for(;!m.out_grouping(o,97,246);){if(m.cursor>=m.limit)return;m.cursor++}(t=m.cursor)<n&&(t=n)}}(),m.limit_backward=r,m.cursor=m.limit,function(){var e,r=m.limit_backward;if(m.cursor>=t&&(m.limit_backward=t,m.cursor=m.limit,m.ket=m.cursor,e=m.find_among_b(i,37),m.limit_backward=r,e))switch(m.bra=m.cursor,e){case 1:m.slice_del();break;case 2:m.in_grouping_b(u,98,121)&&m.slice_del()}}(),m.cursor=m.limit,e=m.limit_backward,m.cursor>=t&&(m.limit_backward=t,m.cursor=m.limit,m.find_among_b(s,7)&&(m.cursor=m.limit,m.ket=m.cursor,m.cursor>m.limit_backward&&(m.bra=--m.cursor,m.slice_del())),m.limit_backward=e),m.cursor=m.limit,function(){var e,r;if(m.cursor>=t){if(r=m.limit_backward,m.limit_backward=t,m.cursor=m.limit,m.ket=m.cursor,e=m.find_among_b(a,5))switch(m.bra=m.cursor,e){case 1:m.slice_del();break;case 2:m.slice_from("lös");break;case 3:m.slice_from("full")}m.limit_backward=r}}(),!0}},function(e){return"function"==typeof e.update?e.update(function(e){return n.setCurrent(e),n.stem(),n.getCurrent()}):(n.setCurrent(e),n.stem(),n.getCurrent())}),e.Pipeline.registerFunction(e.sv.stemmer,"stemmer-sv"),e.sv.stopWordFilter=e.generateStopWordFilter("alla allt att av blev bli blir blivit de dem den denna deras dess dessa det detta dig din dina ditt du där då efter ej eller en er era ert ett från för ha hade han hans har henne hennes hon honom hur här i icke ingen inom inte jag ju kan kunde man med mellan men mig min mina mitt mot mycket ni nu när någon något några och om oss på samma sedan sig sin sina sitta själv skulle som så sådan sådana sådant till under upp ut utan vad var vara varför varit varje vars vart vem vi vid vilka vilkas vilken vilket vår våra vårt än är åt över".split(" ")),e.Pipeline.registerFunction(e.sv.stopWordFilter,"stopWordFilter-sv")}});
|
@ -1 +1,17 @@
|
||||
/*!
|
||||
* Lunr languages, `Thai` language
|
||||
* https://github.com/MihaiValentin/lunr-languages
|
||||
*
|
||||
* Copyright 2017, Keerati Thiwanruk
|
||||
* http://www.mozilla.org/MPL/
|
||||
*/
|
||||
/*!
|
||||
* based on
|
||||
* Snowball JavaScript Library v0.3
|
||||
* http://code.google.com/p/urim/
|
||||
* http://snowball.tartarus.org/
|
||||
*
|
||||
* Copyright 2010, Oleg Mazko
|
||||
* http://www.mozilla.org/MPL/
|
||||
*/
|
||||
!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
17
docs/assets/javascripts/lunr/lunr.vi.js
Normal file
17
docs/assets/javascripts/lunr/lunr.vi.js
Normal file
@ -0,0 +1,17 @@
|
||||
/*!
|
||||
* Lunr languages, `Vietnamese` language
|
||||
* https://github.com/MihaiValentin/lunr-languages
|
||||
*
|
||||
* Copyright 2017, Keerati Thiwanruk
|
||||
* http://www.mozilla.org/MPL/
|
||||
*/
|
||||
/*!
|
||||
* based on
|
||||
* Snowball JavaScript Library v0.3
|
||||
* http://code.google.com/p/urim/
|
||||
* http://snowball.tartarus.org/
|
||||
*
|
||||
* Copyright 2010, Oleg Mazko
|
||||
* http://www.mozilla.org/MPL/
|
||||
*/
|
||||
!function(e,r){"function"==typeof define&&define.amd?define(r):"object"==typeof exports?module.exports=r():r()(e.lunr)}(this,function(){return function(e){if(void 0===e)throw new Error("Lunr is not present. Please include / require Lunr before this script.");if(void 0===e.stemmerSupport)throw new Error("Lunr stemmer support is not present. Please include / require Lunr stemmer support before this script.");e.vi=function(){this.pipeline.reset(),this.pipeline.add(e.vi.stopWordFilter,e.vi.trimmer)},e.vi.wordCharacters="[A-Za-ẓ̀͐́͑̉̃̓ÂâÊêÔôĂ-ăĐ-đƠ-ơƯ-ư]",e.vi.trimmer=e.trimmerSupport.generateTrimmer(e.vi.wordCharacters),e.Pipeline.registerFunction(e.vi.trimmer,"trimmer-vi"),e.vi.stopWordFilter=e.generateStopWordFilter("là cái nhưng mà".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
1
docs/assets/stylesheets/application.1b62728e.css
Normal file
1
docs/assets/stylesheets/application.1b62728e.css
Normal file
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
@ -1,533 +0,0 @@
|
||||
|
||||
|
||||
|
||||
|
||||
<!doctype html>
|
||||
<html lang="en" class="no-js">
|
||||
<head>
|
||||
|
||||
<meta charset="utf-8">
|
||||
<meta name="viewport" content="width=device-width,initial-scale=1">
|
||||
<meta http-equiv="x-ua-compatible" content="ie=edge">
|
||||
|
||||
|
||||
|
||||
|
||||
<meta name="lang:clipboard.copy" content="Copy to clipboard">
|
||||
|
||||
<meta name="lang:clipboard.copied" content="Copied to clipboard">
|
||||
|
||||
<meta name="lang:search.language" content="en">
|
||||
|
||||
<meta name="lang:search.pipeline.stopwords" content="True">
|
||||
|
||||
<meta name="lang:search.pipeline.trimmer" content="True">
|
||||
|
||||
<meta name="lang:search.result.none" content="No matching documents">
|
||||
|
||||
<meta name="lang:search.result.one" content="1 matching document">
|
||||
|
||||
<meta name="lang:search.result.other" content="# matching documents">
|
||||
|
||||
<meta name="lang:search.tokenizer" content="[\s\-]+">
|
||||
|
||||
<link rel="shortcut icon" href="../assets/images/favicon.png">
|
||||
<meta name="generator" content="mkdocs-1.0.4, mkdocs-material-4.2.0">
|
||||
|
||||
|
||||
|
||||
<title>Convert - Yq</title>
|
||||
|
||||
|
||||
|
||||
<link rel="stylesheet" href="../assets/stylesheets/application.750b69bd.css">
|
||||
|
||||
|
||||
|
||||
|
||||
<script src="../assets/javascripts/modernizr.74668098.js"></script>
|
||||
|
||||
|
||||
|
||||
<link href="https://fonts.gstatic.com" rel="preconnect" crossorigin>
|
||||
<link rel="stylesheet" href="https://fonts.googleapis.com/css?family=Roboto:300,400,400i,700|Roboto+Mono">
|
||||
<style>body,input{font-family:"Roboto","Helvetica Neue",Helvetica,Arial,sans-serif}code,kbd,pre{font-family:"Roboto Mono","Courier New",Courier,monospace}</style>
|
||||
|
||||
|
||||
<link rel="stylesheet" href="../assets/fonts/material-icons.css">
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
</head>
|
||||
|
||||
<body dir="ltr">
|
||||
|
||||
<svg class="md-svg">
|
||||
<defs>
|
||||
|
||||
|
||||
<svg xmlns="http://www.w3.org/2000/svg" width="416" height="448"
|
||||
viewBox="0 0 416 448" id="__github">
|
||||
<path fill="currentColor" d="M160 304q0 10-3.125 20.5t-10.75 19-18.125
|
||||
8.5-18.125-8.5-10.75-19-3.125-20.5 3.125-20.5 10.75-19 18.125-8.5
|
||||
18.125 8.5 10.75 19 3.125 20.5zM320 304q0 10-3.125 20.5t-10.75
|
||||
19-18.125 8.5-18.125-8.5-10.75-19-3.125-20.5 3.125-20.5 10.75-19
|
||||
18.125-8.5 18.125 8.5 10.75 19 3.125 20.5zM360
|
||||
304q0-30-17.25-51t-46.75-21q-10.25 0-48.75 5.25-17.75 2.75-39.25
|
||||
2.75t-39.25-2.75q-38-5.25-48.75-5.25-29.5 0-46.75 21t-17.25 51q0 22 8
|
||||
38.375t20.25 25.75 30.5 15 35 7.375 37.25 1.75h42q20.5 0
|
||||
37.25-1.75t35-7.375 30.5-15 20.25-25.75 8-38.375zM416 260q0 51.75-15.25
|
||||
82.75-9.5 19.25-26.375 33.25t-35.25 21.5-42.5 11.875-42.875 5.5-41.75
|
||||
1.125q-19.5 0-35.5-0.75t-36.875-3.125-38.125-7.5-34.25-12.875-30.25-20.25-21.5-28.75q-15.5-30.75-15.5-82.75
|
||||
0-59.25 34-99-6.75-20.5-6.75-42.5 0-29 12.75-54.5 27 0 47.5 9.875t47.25
|
||||
30.875q36.75-8.75 77.25-8.75 37 0 70 8 26.25-20.5
|
||||
46.75-30.25t47.25-9.75q12.75 25.5 12.75 54.5 0 21.75-6.75 42 34 40 34
|
||||
99.5z" />
|
||||
</svg>
|
||||
|
||||
</defs>
|
||||
</svg>
|
||||
<input class="md-toggle" data-md-toggle="drawer" type="checkbox" id="__drawer" autocomplete="off">
|
||||
<input class="md-toggle" data-md-toggle="search" type="checkbox" id="__search" autocomplete="off">
|
||||
<label class="md-overlay" data-md-component="overlay" for="__drawer"></label>
|
||||
|
||||
<a href="#yaml-to-json" tabindex="1" class="md-skip">
|
||||
Skip to content
|
||||
</a>
|
||||
|
||||
|
||||
<header class="md-header" data-md-component="header">
|
||||
<nav class="md-header-nav md-grid">
|
||||
<div class="md-flex">
|
||||
<div class="md-flex__cell md-flex__cell--shrink">
|
||||
<a href=".." title="Yq" class="md-header-nav__button md-logo">
|
||||
|
||||
<i class="md-icon"></i>
|
||||
|
||||
</a>
|
||||
</div>
|
||||
<div class="md-flex__cell md-flex__cell--shrink">
|
||||
<label class="md-icon md-icon--menu md-header-nav__button" for="__drawer"></label>
|
||||
</div>
|
||||
<div class="md-flex__cell md-flex__cell--stretch">
|
||||
<div class="md-flex__ellipsis md-header-nav__title" data-md-component="title">
|
||||
|
||||
<span class="md-header-nav__topic">
|
||||
Yq
|
||||
</span>
|
||||
<span class="md-header-nav__topic">
|
||||
Convert
|
||||
</span>
|
||||
|
||||
</div>
|
||||
</div>
|
||||
<div class="md-flex__cell md-flex__cell--shrink">
|
||||
|
||||
<label class="md-icon md-icon--search md-header-nav__button" for="__search"></label>
|
||||
|
||||
<div class="md-search" data-md-component="search" role="dialog">
|
||||
<label class="md-search__overlay" for="__search"></label>
|
||||
<div class="md-search__inner" role="search">
|
||||
<form class="md-search__form" name="search">
|
||||
<input type="text" class="md-search__input" name="query" placeholder="Search" autocapitalize="off" autocorrect="off" autocomplete="off" spellcheck="false" data-md-component="query" data-md-state="active">
|
||||
<label class="md-icon md-search__icon" for="__search"></label>
|
||||
<button type="reset" class="md-icon md-search__icon" data-md-component="reset" tabindex="-1">
|
||||

|
||||
</button>
|
||||
</form>
|
||||
<div class="md-search__output">
|
||||
<div class="md-search__scrollwrap" data-md-scrollfix>
|
||||
<div class="md-search-result" data-md-component="result">
|
||||
<div class="md-search-result__meta">
|
||||
Type to start searching
|
||||
</div>
|
||||
<ol class="md-search-result__list"></ol>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
</div>
|
||||
|
||||
<div class="md-flex__cell md-flex__cell--shrink">
|
||||
<div class="md-header-nav__source">
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
<a href="https://github.com/mikefarah/yq/" title="Go to repository" class="md-source" data-md-source="github">
|
||||
|
||||
<div class="md-source__icon">
|
||||
<svg viewBox="0 0 24 24" width="24" height="24">
|
||||
<use xlink:href="#__github" width="24" height="24"></use>
|
||||
</svg>
|
||||
</div>
|
||||
|
||||
<div class="md-source__repository">
|
||||
mikefarah/yq
|
||||
</div>
|
||||
</a>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
</div>
|
||||
</nav>
|
||||
</header>
|
||||
|
||||
<div class="md-container">
|
||||
|
||||
|
||||
|
||||
|
||||
<main class="md-main">
|
||||
<div class="md-main__inner md-grid" data-md-component="container">
|
||||
|
||||
|
||||
<div class="md-sidebar md-sidebar--primary" data-md-component="navigation">
|
||||
<div class="md-sidebar__scrollwrap">
|
||||
<div class="md-sidebar__inner">
|
||||
<nav class="md-nav md-nav--primary" data-md-level="0">
|
||||
<label class="md-nav__title md-nav__title--site" for="__drawer">
|
||||
<a href=".." title="Yq" class="md-nav__button md-logo">
|
||||
|
||||
<i class="md-icon"></i>
|
||||
|
||||
</a>
|
||||
Yq
|
||||
</label>
|
||||
|
||||
<div class="md-nav__source">
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
<a href="https://github.com/mikefarah/yq/" title="Go to repository" class="md-source" data-md-source="github">
|
||||
|
||||
<div class="md-source__icon">
|
||||
<svg viewBox="0 0 24 24" width="24" height="24">
|
||||
<use xlink:href="#__github" width="24" height="24"></use>
|
||||
</svg>
|
||||
</div>
|
||||
|
||||
<div class="md-source__repository">
|
||||
mikefarah/yq
|
||||
</div>
|
||||
</a>
|
||||
</div>
|
||||
|
||||
<ul class="md-nav__list" data-md-scrollfix>
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
<li class="md-nav__item">
|
||||
<a href=".." title="Install" class="md-nav__link">
|
||||
Install
|
||||
</a>
|
||||
</li>
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
<li class="md-nav__item">
|
||||
<a href="../read/" title="Read" class="md-nav__link">
|
||||
Read
|
||||
</a>
|
||||
</li>
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
<li class="md-nav__item">
|
||||
<a href="../write/" title="Write/Update" class="md-nav__link">
|
||||
Write/Update
|
||||
</a>
|
||||
</li>
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
<li class="md-nav__item">
|
||||
<a href="../prefix/" title="Prefix" class="md-nav__link">
|
||||
Prefix
|
||||
</a>
|
||||
</li>
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
<li class="md-nav__item">
|
||||
<a href="../delete/" title="Delete" class="md-nav__link">
|
||||
Delete
|
||||
</a>
|
||||
</li>
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
<li class="md-nav__item">
|
||||
<a href="../create/" title="Create" class="md-nav__link">
|
||||
Create
|
||||
</a>
|
||||
</li>
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
<li class="md-nav__item md-nav__item--active">
|
||||
|
||||
<input class="md-toggle md-nav__toggle" data-md-toggle="toc" type="checkbox" id="__toc">
|
||||
|
||||
|
||||
<label class="md-nav__link md-nav__link--active" for="__toc">
|
||||
Convert
|
||||
</label>
|
||||
|
||||
<a href="./" title="Convert" class="md-nav__link md-nav__link--active">
|
||||
Convert
|
||||
</a>
|
||||
|
||||
|
||||
<nav class="md-nav md-nav--secondary">
|
||||
|
||||
|
||||
|
||||
<label class="md-nav__title" for="__toc">Table of contents</label>
|
||||
<ul class="md-nav__list" data-md-scrollfix>
|
||||
|
||||
<li class="md-nav__item">
|
||||
<a href="#yaml-to-json" title="Yaml to Json" class="md-nav__link">
|
||||
Yaml to Json
|
||||
</a>
|
||||
|
||||
</li>
|
||||
|
||||
<li class="md-nav__item">
|
||||
<a href="#json-to-yaml" title="Json to Yaml" class="md-nav__link">
|
||||
Json to Yaml
|
||||
</a>
|
||||
|
||||
</li>
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
</ul>
|
||||
|
||||
</nav>
|
||||
|
||||
</li>
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
<li class="md-nav__item">
|
||||
<a href="../merge/" title="Merge" class="md-nav__link">
|
||||
Merge
|
||||
</a>
|
||||
</li>
|
||||
|
||||
|
||||
</ul>
|
||||
</nav>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
|
||||
<div class="md-sidebar md-sidebar--secondary" data-md-component="toc">
|
||||
<div class="md-sidebar__scrollwrap">
|
||||
<div class="md-sidebar__inner">
|
||||
|
||||
<nav class="md-nav md-nav--secondary">
|
||||
|
||||
|
||||
|
||||
<label class="md-nav__title" for="__toc">Table of contents</label>
|
||||
<ul class="md-nav__list" data-md-scrollfix>
|
||||
|
||||
<li class="md-nav__item">
|
||||
<a href="#yaml-to-json" title="Yaml to Json" class="md-nav__link">
|
||||
Yaml to Json
|
||||
</a>
|
||||
|
||||
</li>
|
||||
|
||||
<li class="md-nav__item">
|
||||
<a href="#json-to-yaml" title="Json to Yaml" class="md-nav__link">
|
||||
Json to Yaml
|
||||
</a>
|
||||
|
||||
</li>
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
</ul>
|
||||
|
||||
</nav>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
|
||||
<div class="md-content">
|
||||
<article class="md-content__inner md-typeset">
|
||||
|
||||
|
||||
<a href="https://github.com/mikefarah/yq/edit/master/docs/convert.md" title="Edit this page" class="md-icon md-content__icon"></a>
|
||||
|
||||
|
||||
<h1>Convert</h1>
|
||||
|
||||
<h3 id="yaml-to-json">Yaml to Json<a class="headerlink" href="#yaml-to-json" title="Permanent link">¶</a></h3>
|
||||
<p>To convert output to json, use the --tojson (or -j) flag. This can only be used with the read command.</p>
|
||||
<p>Given a sample.yaml file of:</p>
|
||||
<pre><code class="yaml">b:
|
||||
c: 2
|
||||
</code></pre>
|
||||
|
||||
<p>then</p>
|
||||
<pre><code class="bash">yq r -j sample.yaml b.c
|
||||
</code></pre>
|
||||
|
||||
<p>will output</p>
|
||||
<pre><code class="json">{"b":{"c":2}}
|
||||
</code></pre>
|
||||
|
||||
<h3 id="json-to-yaml">Json to Yaml<a class="headerlink" href="#json-to-yaml" title="Permanent link">¶</a></h3>
|
||||
<p>To read in json, just pass in a json file instead of yaml, it will just work :)</p>
|
||||
<p>e.g given a json file</p>
|
||||
<pre><code class="json">{"a":"Easy! as one two three","b":{"c":2,"d":[3,4]}}
|
||||
</code></pre>
|
||||
|
||||
<p>then</p>
|
||||
<pre><code class="bash">yq r sample.json
|
||||
</code></pre>
|
||||
|
||||
<p>will output</p>
|
||||
<pre><code class="yaml">a: Easy! as one two three
|
||||
b:
|
||||
c: 2
|
||||
d:
|
||||
- 3
|
||||
- 4
|
||||
</code></pre>
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
</article>
|
||||
</div>
|
||||
</div>
|
||||
</main>
|
||||
|
||||
|
||||
<footer class="md-footer">
|
||||
|
||||
<div class="md-footer-nav">
|
||||
<nav class="md-footer-nav__inner md-grid">
|
||||
|
||||
<a href="../create/" title="Create" class="md-flex md-footer-nav__link md-footer-nav__link--prev" rel="prev">
|
||||
<div class="md-flex__cell md-flex__cell--shrink">
|
||||
<i class="md-icon md-icon--arrow-back md-footer-nav__button"></i>
|
||||
</div>
|
||||
<div class="md-flex__cell md-flex__cell--stretch md-footer-nav__title">
|
||||
<span class="md-flex__ellipsis">
|
||||
<span class="md-footer-nav__direction">
|
||||
Previous
|
||||
</span>
|
||||
Create
|
||||
</span>
|
||||
</div>
|
||||
</a>
|
||||
|
||||
|
||||
<a href="../merge/" title="Merge" class="md-flex md-footer-nav__link md-footer-nav__link--next" rel="next">
|
||||
<div class="md-flex__cell md-flex__cell--stretch md-footer-nav__title">
|
||||
<span class="md-flex__ellipsis">
|
||||
<span class="md-footer-nav__direction">
|
||||
Next
|
||||
</span>
|
||||
Merge
|
||||
</span>
|
||||
</div>
|
||||
<div class="md-flex__cell md-flex__cell--shrink">
|
||||
<i class="md-icon md-icon--arrow-forward md-footer-nav__button"></i>
|
||||
</div>
|
||||
</a>
|
||||
|
||||
</nav>
|
||||
</div>
|
||||
|
||||
<div class="md-footer-meta md-typeset">
|
||||
<div class="md-footer-meta__inner md-grid">
|
||||
<div class="md-footer-copyright">
|
||||
|
||||
powered by
|
||||
<a href="https://www.mkdocs.org">MkDocs</a>
|
||||
and
|
||||
<a href="https://squidfunk.github.io/mkdocs-material/">
|
||||
Material for MkDocs</a>
|
||||
</div>
|
||||
|
||||
<div class="md-footer-social">
|
||||
<link rel="stylesheet" href="../assets/fonts/font-awesome.css">
|
||||
|
||||
<a href="https://github.com/mikefarah" class="md-footer-social__link fa fa-github"></a>
|
||||
|
||||
<a href="https://www.linkedin.com/in/mike-farah-b5a75b2/" class="md-footer-social__link fa fa-linkedin"></a>
|
||||
|
||||
</div>
|
||||
|
||||
</div>
|
||||
</div>
|
||||
</footer>
|
||||
|
||||
</div>
|
||||
|
||||
<script src="../assets/javascripts/application.39abc4af.js"></script>
|
||||
|
||||
<script>app.initialize({version:"1.0.4",url:{base:".."}})</script>
|
||||
|
||||
|
||||
</body>
|
||||
</html>
|
@ -1,586 +0,0 @@
|
||||
|
||||
|
||||
|
||||
|
||||
<!doctype html>
|
||||
<html lang="en" class="no-js">
|
||||
<head>
|
||||
|
||||
<meta charset="utf-8">
|
||||
<meta name="viewport" content="width=device-width,initial-scale=1">
|
||||
<meta http-equiv="x-ua-compatible" content="ie=edge">
|
||||
|
||||
|
||||
|
||||
|
||||
<meta name="lang:clipboard.copy" content="Copy to clipboard">
|
||||
|
||||
<meta name="lang:clipboard.copied" content="Copied to clipboard">
|
||||
|
||||
<meta name="lang:search.language" content="en">
|
||||
|
||||
<meta name="lang:search.pipeline.stopwords" content="True">
|
||||
|
||||
<meta name="lang:search.pipeline.trimmer" content="True">
|
||||
|
||||
<meta name="lang:search.result.none" content="No matching documents">
|
||||
|
||||
<meta name="lang:search.result.one" content="1 matching document">
|
||||
|
||||
<meta name="lang:search.result.other" content="# matching documents">
|
||||
|
||||
<meta name="lang:search.tokenizer" content="[\s\-]+">
|
||||
|
||||
<link rel="shortcut icon" href="../assets/images/favicon.png">
|
||||
<meta name="generator" content="mkdocs-1.0.4, mkdocs-material-4.2.0">
|
||||
|
||||
|
||||
|
||||
<title>Create - Yq</title>
|
||||
|
||||
|
||||
|
||||
<link rel="stylesheet" href="../assets/stylesheets/application.750b69bd.css">
|
||||
|
||||
|
||||
|
||||
|
||||
<script src="../assets/javascripts/modernizr.74668098.js"></script>
|
||||
|
||||
|
||||
|
||||
<link href="https://fonts.gstatic.com" rel="preconnect" crossorigin>
|
||||
<link rel="stylesheet" href="https://fonts.googleapis.com/css?family=Roboto:300,400,400i,700|Roboto+Mono">
|
||||
<style>body,input{font-family:"Roboto","Helvetica Neue",Helvetica,Arial,sans-serif}code,kbd,pre{font-family:"Roboto Mono","Courier New",Courier,monospace}</style>
|
||||
|
||||
|
||||
<link rel="stylesheet" href="../assets/fonts/material-icons.css">
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
</head>
|
||||
|
||||
<body dir="ltr">
|
||||
|
||||
<svg class="md-svg">
|
||||
<defs>
|
||||
|
||||
|
||||
<svg xmlns="http://www.w3.org/2000/svg" width="416" height="448"
|
||||
viewBox="0 0 416 448" id="__github">
|
||||
<path fill="currentColor" d="M160 304q0 10-3.125 20.5t-10.75 19-18.125
|
||||
8.5-18.125-8.5-10.75-19-3.125-20.5 3.125-20.5 10.75-19 18.125-8.5
|
||||
18.125 8.5 10.75 19 3.125 20.5zM320 304q0 10-3.125 20.5t-10.75
|
||||
19-18.125 8.5-18.125-8.5-10.75-19-3.125-20.5 3.125-20.5 10.75-19
|
||||
18.125-8.5 18.125 8.5 10.75 19 3.125 20.5zM360
|
||||
304q0-30-17.25-51t-46.75-21q-10.25 0-48.75 5.25-17.75 2.75-39.25
|
||||
2.75t-39.25-2.75q-38-5.25-48.75-5.25-29.5 0-46.75 21t-17.25 51q0 22 8
|
||||
38.375t20.25 25.75 30.5 15 35 7.375 37.25 1.75h42q20.5 0
|
||||
37.25-1.75t35-7.375 30.5-15 20.25-25.75 8-38.375zM416 260q0 51.75-15.25
|
||||
82.75-9.5 19.25-26.375 33.25t-35.25 21.5-42.5 11.875-42.875 5.5-41.75
|
||||
1.125q-19.5 0-35.5-0.75t-36.875-3.125-38.125-7.5-34.25-12.875-30.25-20.25-21.5-28.75q-15.5-30.75-15.5-82.75
|
||||
0-59.25 34-99-6.75-20.5-6.75-42.5 0-29 12.75-54.5 27 0 47.5 9.875t47.25
|
||||
30.875q36.75-8.75 77.25-8.75 37 0 70 8 26.25-20.5
|
||||
46.75-30.25t47.25-9.75q12.75 25.5 12.75 54.5 0 21.75-6.75 42 34 40 34
|
||||
99.5z" />
|
||||
</svg>
|
||||
|
||||
</defs>
|
||||
</svg>
|
||||
<input class="md-toggle" data-md-toggle="drawer" type="checkbox" id="__drawer" autocomplete="off">
|
||||
<input class="md-toggle" data-md-toggle="search" type="checkbox" id="__search" autocomplete="off">
|
||||
<label class="md-overlay" data-md-component="overlay" for="__drawer"></label>
|
||||
|
||||
<a href="#creating-a-simple-yaml-file" tabindex="1" class="md-skip">
|
||||
Skip to content
|
||||
</a>
|
||||
|
||||
|
||||
<header class="md-header" data-md-component="header">
|
||||
<nav class="md-header-nav md-grid">
|
||||
<div class="md-flex">
|
||||
<div class="md-flex__cell md-flex__cell--shrink">
|
||||
<a href=".." title="Yq" class="md-header-nav__button md-logo">
|
||||
|
||||
<i class="md-icon"></i>
|
||||
|
||||
</a>
|
||||
</div>
|
||||
<div class="md-flex__cell md-flex__cell--shrink">
|
||||
<label class="md-icon md-icon--menu md-header-nav__button" for="__drawer"></label>
|
||||
</div>
|
||||
<div class="md-flex__cell md-flex__cell--stretch">
|
||||
<div class="md-flex__ellipsis md-header-nav__title" data-md-component="title">
|
||||
|
||||
<span class="md-header-nav__topic">
|
||||
Yq
|
||||
</span>
|
||||
<span class="md-header-nav__topic">
|
||||
Create
|
||||
</span>
|
||||
|
||||
</div>
|
||||
</div>
|
||||
<div class="md-flex__cell md-flex__cell--shrink">
|
||||
|
||||
<label class="md-icon md-icon--search md-header-nav__button" for="__search"></label>
|
||||
|
||||
<div class="md-search" data-md-component="search" role="dialog">
|
||||
<label class="md-search__overlay" for="__search"></label>
|
||||
<div class="md-search__inner" role="search">
|
||||
<form class="md-search__form" name="search">
|
||||
<input type="text" class="md-search__input" name="query" placeholder="Search" autocapitalize="off" autocorrect="off" autocomplete="off" spellcheck="false" data-md-component="query" data-md-state="active">
|
||||
<label class="md-icon md-search__icon" for="__search"></label>
|
||||
<button type="reset" class="md-icon md-search__icon" data-md-component="reset" tabindex="-1">
|
||||

|
||||
</button>
|
||||
</form>
|
||||
<div class="md-search__output">
|
||||
<div class="md-search__scrollwrap" data-md-scrollfix>
|
||||
<div class="md-search-result" data-md-component="result">
|
||||
<div class="md-search-result__meta">
|
||||
Type to start searching
|
||||
</div>
|
||||
<ol class="md-search-result__list"></ol>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
</div>
|
||||
|
||||
<div class="md-flex__cell md-flex__cell--shrink">
|
||||
<div class="md-header-nav__source">
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
<a href="https://github.com/mikefarah/yq/" title="Go to repository" class="md-source" data-md-source="github">
|
||||
|
||||
<div class="md-source__icon">
|
||||
<svg viewBox="0 0 24 24" width="24" height="24">
|
||||
<use xlink:href="#__github" width="24" height="24"></use>
|
||||
</svg>
|
||||
</div>
|
||||
|
||||
<div class="md-source__repository">
|
||||
mikefarah/yq
|
||||
</div>
|
||||
</a>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
</div>
|
||||
</nav>
|
||||
</header>
|
||||
|
||||
<div class="md-container">
|
||||
|
||||
|
||||
|
||||
|
||||
<main class="md-main">
|
||||
<div class="md-main__inner md-grid" data-md-component="container">
|
||||
|
||||
|
||||
<div class="md-sidebar md-sidebar--primary" data-md-component="navigation">
|
||||
<div class="md-sidebar__scrollwrap">
|
||||
<div class="md-sidebar__inner">
|
||||
<nav class="md-nav md-nav--primary" data-md-level="0">
|
||||
<label class="md-nav__title md-nav__title--site" for="__drawer">
|
||||
<a href=".." title="Yq" class="md-nav__button md-logo">
|
||||
|
||||
<i class="md-icon"></i>
|
||||
|
||||
</a>
|
||||
Yq
|
||||
</label>
|
||||
|
||||
<div class="md-nav__source">
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
<a href="https://github.com/mikefarah/yq/" title="Go to repository" class="md-source" data-md-source="github">
|
||||
|
||||
<div class="md-source__icon">
|
||||
<svg viewBox="0 0 24 24" width="24" height="24">
|
||||
<use xlink:href="#__github" width="24" height="24"></use>
|
||||
</svg>
|
||||
</div>
|
||||
|
||||
<div class="md-source__repository">
|
||||
mikefarah/yq
|
||||
</div>
|
||||
</a>
|
||||
</div>
|
||||
|
||||
<ul class="md-nav__list" data-md-scrollfix>
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
<li class="md-nav__item">
|
||||
<a href=".." title="Install" class="md-nav__link">
|
||||
Install
|
||||
</a>
|
||||
</li>
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
<li class="md-nav__item">
|
||||
<a href="../read/" title="Read" class="md-nav__link">
|
||||
Read
|
||||
</a>
|
||||
</li>
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
<li class="md-nav__item">
|
||||
<a href="../write/" title="Write/Update" class="md-nav__link">
|
||||
Write/Update
|
||||
</a>
|
||||
</li>
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
<li class="md-nav__item">
|
||||
<a href="../prefix/" title="Prefix" class="md-nav__link">
|
||||
Prefix
|
||||
</a>
|
||||
</li>
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
<li class="md-nav__item">
|
||||
<a href="../delete/" title="Delete" class="md-nav__link">
|
||||
Delete
|
||||
</a>
|
||||
</li>
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
<li class="md-nav__item md-nav__item--active">
|
||||
|
||||
<input class="md-toggle md-nav__toggle" data-md-toggle="toc" type="checkbox" id="__toc">
|
||||
|
||||
|
||||
<label class="md-nav__link md-nav__link--active" for="__toc">
|
||||
Create
|
||||
</label>
|
||||
|
||||
<a href="./" title="Create" class="md-nav__link md-nav__link--active">
|
||||
Create
|
||||
</a>
|
||||
|
||||
|
||||
<nav class="md-nav md-nav--secondary">
|
||||
|
||||
|
||||
|
||||
<label class="md-nav__title" for="__toc">Table of contents</label>
|
||||
<ul class="md-nav__list" data-md-scrollfix>
|
||||
|
||||
<li class="md-nav__item">
|
||||
<a href="#creating-a-simple-yaml-file" title="Creating a simple yaml file" class="md-nav__link">
|
||||
Creating a simple yaml file
|
||||
</a>
|
||||
|
||||
</li>
|
||||
|
||||
<li class="md-nav__item">
|
||||
<a href="#creating-using-a-create-script" title="Creating using a create script" class="md-nav__link">
|
||||
Creating using a create script
|
||||
</a>
|
||||
|
||||
</li>
|
||||
|
||||
<li class="md-nav__item">
|
||||
<a href="#keys-with-dots" title="Keys with dots" class="md-nav__link">
|
||||
Keys with dots
|
||||
</a>
|
||||
|
||||
</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>
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
</ul>
|
||||
|
||||
</nav>
|
||||
|
||||
</li>
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
<li class="md-nav__item">
|
||||
<a href="../convert/" title="Convert" class="md-nav__link">
|
||||
Convert
|
||||
</a>
|
||||
</li>
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
<li class="md-nav__item">
|
||||
<a href="../merge/" title="Merge" class="md-nav__link">
|
||||
Merge
|
||||
</a>
|
||||
</li>
|
||||
|
||||
|
||||
</ul>
|
||||
</nav>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
|
||||
<div class="md-sidebar md-sidebar--secondary" data-md-component="toc">
|
||||
<div class="md-sidebar__scrollwrap">
|
||||
<div class="md-sidebar__inner">
|
||||
|
||||
<nav class="md-nav md-nav--secondary">
|
||||
|
||||
|
||||
|
||||
<label class="md-nav__title" for="__toc">Table of contents</label>
|
||||
<ul class="md-nav__list" data-md-scrollfix>
|
||||
|
||||
<li class="md-nav__item">
|
||||
<a href="#creating-a-simple-yaml-file" title="Creating a simple yaml file" class="md-nav__link">
|
||||
Creating a simple yaml file
|
||||
</a>
|
||||
|
||||
</li>
|
||||
|
||||
<li class="md-nav__item">
|
||||
<a href="#creating-using-a-create-script" title="Creating using a create script" class="md-nav__link">
|
||||
Creating using a create script
|
||||
</a>
|
||||
|
||||
</li>
|
||||
|
||||
<li class="md-nav__item">
|
||||
<a href="#keys-with-dots" title="Keys with dots" class="md-nav__link">
|
||||
Keys with dots
|
||||
</a>
|
||||
|
||||
</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>
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
</ul>
|
||||
|
||||
</nav>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
|
||||
<div class="md-content">
|
||||
<article class="md-content__inner md-typeset">
|
||||
|
||||
|
||||
<a href="https://github.com/mikefarah/yq/edit/master/docs/create.md" title="Edit this page" class="md-icon md-content__icon"></a>
|
||||
|
||||
|
||||
<h1>Create</h1>
|
||||
|
||||
<p>Yaml files can be created using the 'new' command. This works in the same way as the write command, but you don't pass in an existing Yaml file. Currently this does not support creating multiple documents in a single yaml file.</p>
|
||||
<pre><code>yq n <path> <new value>
|
||||
</code></pre>
|
||||
|
||||
<h3 id="creating-a-simple-yaml-file">Creating a simple yaml file<a class="headerlink" href="#creating-a-simple-yaml-file" title="Permanent link">¶</a></h3>
|
||||
<pre><code class="bash">yq n b.c cat
|
||||
</code></pre>
|
||||
|
||||
<p>will output:</p>
|
||||
<pre><code class="yaml">b:
|
||||
c: cat
|
||||
</code></pre>
|
||||
|
||||
<h3 id="creating-using-a-create-script">Creating using a create script<a class="headerlink" href="#creating-using-a-create-script" title="Permanent link">¶</a></h3>
|
||||
<p>Create scripts follow the same format as the update scripts.</p>
|
||||
<p>Given a script create_instructions.yaml of:</p>
|
||||
<pre><code class="yaml">b.c: 3
|
||||
b.e[+].name: Howdy Partner
|
||||
</code></pre>
|
||||
|
||||
<p>then</p>
|
||||
<pre><code class="bash">yq n -s create_instructions.yaml
|
||||
</code></pre>
|
||||
|
||||
<p>will output:</p>
|
||||
<pre><code class="yaml">b:
|
||||
c: 3
|
||||
e:
|
||||
- name: Howdy Partner
|
||||
</code></pre>
|
||||
|
||||
<p>You can also pipe the instructions in:</p>
|
||||
<pre><code class="bash">cat create_instructions.yaml | yq n -s -
|
||||
</code></pre>
|
||||
|
||||
<h3 id="keys-with-dots">Keys with dots<a class="headerlink" href="#keys-with-dots" title="Permanent link">¶</a></h3>
|
||||
<p>When specifying a key that has a dot use key lookup indicator.</p>
|
||||
<pre><code class="yaml">b:
|
||||
foo.bar: 7
|
||||
</code></pre>
|
||||
|
||||
<pre><code class="bash">yaml r sample.yaml 'b[foo.bar]'
|
||||
</code></pre>
|
||||
|
||||
<pre><code class="bash">yaml w sample.yaml 'b[foo.bar]' 9
|
||||
</code></pre>
|
||||
|
||||
<p>Any valid yaml key can be specified as part of a key lookup.</p>
|
||||
<p>Note that the path is in quotes to avoid the square brackets being interpreted by your shell.</p>
|
||||
<h3 id="keys-and-values-with-leading-dashes">Keys (and values) with leading dashes<a class="headerlink" href="#keys-and-values-with-leading-dashes" title="Permanent link">¶</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>
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
</article>
|
||||
</div>
|
||||
</div>
|
||||
</main>
|
||||
|
||||
|
||||
<footer class="md-footer">
|
||||
|
||||
<div class="md-footer-nav">
|
||||
<nav class="md-footer-nav__inner md-grid">
|
||||
|
||||
<a href="../delete/" title="Delete" class="md-flex md-footer-nav__link md-footer-nav__link--prev" rel="prev">
|
||||
<div class="md-flex__cell md-flex__cell--shrink">
|
||||
<i class="md-icon md-icon--arrow-back md-footer-nav__button"></i>
|
||||
</div>
|
||||
<div class="md-flex__cell md-flex__cell--stretch md-footer-nav__title">
|
||||
<span class="md-flex__ellipsis">
|
||||
<span class="md-footer-nav__direction">
|
||||
Previous
|
||||
</span>
|
||||
Delete
|
||||
</span>
|
||||
</div>
|
||||
</a>
|
||||
|
||||
|
||||
<a href="../convert/" title="Convert" class="md-flex md-footer-nav__link md-footer-nav__link--next" rel="next">
|
||||
<div class="md-flex__cell md-flex__cell--stretch md-footer-nav__title">
|
||||
<span class="md-flex__ellipsis">
|
||||
<span class="md-footer-nav__direction">
|
||||
Next
|
||||
</span>
|
||||
Convert
|
||||
</span>
|
||||
</div>
|
||||
<div class="md-flex__cell md-flex__cell--shrink">
|
||||
<i class="md-icon md-icon--arrow-forward md-footer-nav__button"></i>
|
||||
</div>
|
||||
</a>
|
||||
|
||||
</nav>
|
||||
</div>
|
||||
|
||||
<div class="md-footer-meta md-typeset">
|
||||
<div class="md-footer-meta__inner md-grid">
|
||||
<div class="md-footer-copyright">
|
||||
|
||||
powered by
|
||||
<a href="https://www.mkdocs.org">MkDocs</a>
|
||||
and
|
||||
<a href="https://squidfunk.github.io/mkdocs-material/">
|
||||
Material for MkDocs</a>
|
||||
</div>
|
||||
|
||||
<div class="md-footer-social">
|
||||
<link rel="stylesheet" href="../assets/fonts/font-awesome.css">
|
||||
|
||||
<a href="https://github.com/mikefarah" class="md-footer-social__link fa fa-github"></a>
|
||||
|
||||
<a href="https://www.linkedin.com/in/mike-farah-b5a75b2/" class="md-footer-social__link fa fa-linkedin"></a>
|
||||
|
||||
</div>
|
||||
|
||||
</div>
|
||||
</div>
|
||||
</footer>
|
||||
|
||||
</div>
|
||||
|
||||
<script src="../assets/javascripts/application.39abc4af.js"></script>
|
||||
|
||||
<script>app.initialize({version:"1.0.4",url:{base:".."}})</script>
|
||||
|
||||
|
||||
</body>
|
||||
</html>
|
@ -1,833 +0,0 @@
|
||||
|
||||
|
||||
|
||||
|
||||
<!doctype html>
|
||||
<html lang="en" class="no-js">
|
||||
<head>
|
||||
|
||||
<meta charset="utf-8">
|
||||
<meta name="viewport" content="width=device-width,initial-scale=1">
|
||||
<meta http-equiv="x-ua-compatible" content="ie=edge">
|
||||
|
||||
|
||||
|
||||
|
||||
<meta name="lang:clipboard.copy" content="Copy to clipboard">
|
||||
|
||||
<meta name="lang:clipboard.copied" content="Copied to clipboard">
|
||||
|
||||
<meta name="lang:search.language" content="en">
|
||||
|
||||
<meta name="lang:search.pipeline.stopwords" content="True">
|
||||
|
||||
<meta name="lang:search.pipeline.trimmer" content="True">
|
||||
|
||||
<meta name="lang:search.result.none" content="No matching documents">
|
||||
|
||||
<meta name="lang:search.result.one" content="1 matching document">
|
||||
|
||||
<meta name="lang:search.result.other" content="# matching documents">
|
||||
|
||||
<meta name="lang:search.tokenizer" content="[\s\-]+">
|
||||
|
||||
<link rel="shortcut icon" href="../assets/images/favicon.png">
|
||||
<meta name="generator" content="mkdocs-1.0.4, mkdocs-material-4.2.0">
|
||||
|
||||
|
||||
|
||||
<title>Delete - Yq</title>
|
||||
|
||||
|
||||
|
||||
<link rel="stylesheet" href="../assets/stylesheets/application.750b69bd.css">
|
||||
|
||||
|
||||
|
||||
|
||||
<script src="../assets/javascripts/modernizr.74668098.js"></script>
|
||||
|
||||
|
||||
|
||||
<link href="https://fonts.gstatic.com" rel="preconnect" crossorigin>
|
||||
<link rel="stylesheet" href="https://fonts.googleapis.com/css?family=Roboto:300,400,400i,700|Roboto+Mono">
|
||||
<style>body,input{font-family:"Roboto","Helvetica Neue",Helvetica,Arial,sans-serif}code,kbd,pre{font-family:"Roboto Mono","Courier New",Courier,monospace}</style>
|
||||
|
||||
|
||||
<link rel="stylesheet" href="../assets/fonts/material-icons.css">
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
</head>
|
||||
|
||||
<body dir="ltr">
|
||||
|
||||
<svg class="md-svg">
|
||||
<defs>
|
||||
|
||||
|
||||
<svg xmlns="http://www.w3.org/2000/svg" width="416" height="448"
|
||||
viewBox="0 0 416 448" id="__github">
|
||||
<path fill="currentColor" d="M160 304q0 10-3.125 20.5t-10.75 19-18.125
|
||||
8.5-18.125-8.5-10.75-19-3.125-20.5 3.125-20.5 10.75-19 18.125-8.5
|
||||
18.125 8.5 10.75 19 3.125 20.5zM320 304q0 10-3.125 20.5t-10.75
|
||||
19-18.125 8.5-18.125-8.5-10.75-19-3.125-20.5 3.125-20.5 10.75-19
|
||||
18.125-8.5 18.125 8.5 10.75 19 3.125 20.5zM360
|
||||
304q0-30-17.25-51t-46.75-21q-10.25 0-48.75 5.25-17.75 2.75-39.25
|
||||
2.75t-39.25-2.75q-38-5.25-48.75-5.25-29.5 0-46.75 21t-17.25 51q0 22 8
|
||||
38.375t20.25 25.75 30.5 15 35 7.375 37.25 1.75h42q20.5 0
|
||||
37.25-1.75t35-7.375 30.5-15 20.25-25.75 8-38.375zM416 260q0 51.75-15.25
|
||||
82.75-9.5 19.25-26.375 33.25t-35.25 21.5-42.5 11.875-42.875 5.5-41.75
|
||||
1.125q-19.5 0-35.5-0.75t-36.875-3.125-38.125-7.5-34.25-12.875-30.25-20.25-21.5-28.75q-15.5-30.75-15.5-82.75
|
||||
0-59.25 34-99-6.75-20.5-6.75-42.5 0-29 12.75-54.5 27 0 47.5 9.875t47.25
|
||||
30.875q36.75-8.75 77.25-8.75 37 0 70 8 26.25-20.5
|
||||
46.75-30.25t47.25-9.75q12.75 25.5 12.75 54.5 0 21.75-6.75 42 34 40 34
|
||||
99.5z" />
|
||||
</svg>
|
||||
|
||||
</defs>
|
||||
</svg>
|
||||
<input class="md-toggle" data-md-toggle="drawer" type="checkbox" id="__drawer" autocomplete="off">
|
||||
<input class="md-toggle" data-md-toggle="search" type="checkbox" id="__search" autocomplete="off">
|
||||
<label class="md-overlay" data-md-component="overlay" for="__drawer"></label>
|
||||
|
||||
<a href="#to-stdout" tabindex="1" class="md-skip">
|
||||
Skip to content
|
||||
</a>
|
||||
|
||||
|
||||
<header class="md-header" data-md-component="header">
|
||||
<nav class="md-header-nav md-grid">
|
||||
<div class="md-flex">
|
||||
<div class="md-flex__cell md-flex__cell--shrink">
|
||||
<a href=".." title="Yq" class="md-header-nav__button md-logo">
|
||||
|
||||
<i class="md-icon"></i>
|
||||
|
||||
</a>
|
||||
</div>
|
||||
<div class="md-flex__cell md-flex__cell--shrink">
|
||||
<label class="md-icon md-icon--menu md-header-nav__button" for="__drawer"></label>
|
||||
</div>
|
||||
<div class="md-flex__cell md-flex__cell--stretch">
|
||||
<div class="md-flex__ellipsis md-header-nav__title" data-md-component="title">
|
||||
|
||||
<span class="md-header-nav__topic">
|
||||
Yq
|
||||
</span>
|
||||
<span class="md-header-nav__topic">
|
||||
Delete
|
||||
</span>
|
||||
|
||||
</div>
|
||||
</div>
|
||||
<div class="md-flex__cell md-flex__cell--shrink">
|
||||
|
||||
<label class="md-icon md-icon--search md-header-nav__button" for="__search"></label>
|
||||
|
||||
<div class="md-search" data-md-component="search" role="dialog">
|
||||
<label class="md-search__overlay" for="__search"></label>
|
||||
<div class="md-search__inner" role="search">
|
||||
<form class="md-search__form" name="search">
|
||||
<input type="text" class="md-search__input" name="query" placeholder="Search" autocapitalize="off" autocorrect="off" autocomplete="off" spellcheck="false" data-md-component="query" data-md-state="active">
|
||||
<label class="md-icon md-search__icon" for="__search"></label>
|
||||
<button type="reset" class="md-icon md-search__icon" data-md-component="reset" tabindex="-1">
|
||||

|
||||
</button>
|
||||
</form>
|
||||
<div class="md-search__output">
|
||||
<div class="md-search__scrollwrap" data-md-scrollfix>
|
||||
<div class="md-search-result" data-md-component="result">
|
||||
<div class="md-search-result__meta">
|
||||
Type to start searching
|
||||
</div>
|
||||
<ol class="md-search-result__list"></ol>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
</div>
|
||||
|
||||
<div class="md-flex__cell md-flex__cell--shrink">
|
||||
<div class="md-header-nav__source">
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
<a href="https://github.com/mikefarah/yq/" title="Go to repository" class="md-source" data-md-source="github">
|
||||
|
||||
<div class="md-source__icon">
|
||||
<svg viewBox="0 0 24 24" width="24" height="24">
|
||||
<use xlink:href="#__github" width="24" height="24"></use>
|
||||
</svg>
|
||||
</div>
|
||||
|
||||
<div class="md-source__repository">
|
||||
mikefarah/yq
|
||||
</div>
|
||||
</a>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
</div>
|
||||
</nav>
|
||||
</header>
|
||||
|
||||
<div class="md-container">
|
||||
|
||||
|
||||
|
||||
|
||||
<main class="md-main">
|
||||
<div class="md-main__inner md-grid" data-md-component="container">
|
||||
|
||||
|
||||
<div class="md-sidebar md-sidebar--primary" data-md-component="navigation">
|
||||
<div class="md-sidebar__scrollwrap">
|
||||
<div class="md-sidebar__inner">
|
||||
<nav class="md-nav md-nav--primary" data-md-level="0">
|
||||
<label class="md-nav__title md-nav__title--site" for="__drawer">
|
||||
<a href=".." title="Yq" class="md-nav__button md-logo">
|
||||
|
||||
<i class="md-icon"></i>
|
||||
|
||||
</a>
|
||||
Yq
|
||||
</label>
|
||||
|
||||
<div class="md-nav__source">
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
<a href="https://github.com/mikefarah/yq/" title="Go to repository" class="md-source" data-md-source="github">
|
||||
|
||||
<div class="md-source__icon">
|
||||
<svg viewBox="0 0 24 24" width="24" height="24">
|
||||
<use xlink:href="#__github" width="24" height="24"></use>
|
||||
</svg>
|
||||
</div>
|
||||
|
||||
<div class="md-source__repository">
|
||||
mikefarah/yq
|
||||
</div>
|
||||
</a>
|
||||
</div>
|
||||
|
||||
<ul class="md-nav__list" data-md-scrollfix>
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
<li class="md-nav__item">
|
||||
<a href=".." title="Install" class="md-nav__link">
|
||||
Install
|
||||
</a>
|
||||
</li>
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
<li class="md-nav__item">
|
||||
<a href="../read/" title="Read" class="md-nav__link">
|
||||
Read
|
||||
</a>
|
||||
</li>
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
<li class="md-nav__item">
|
||||
<a href="../write/" title="Write/Update" class="md-nav__link">
|
||||
Write/Update
|
||||
</a>
|
||||
</li>
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
<li class="md-nav__item">
|
||||
<a href="../prefix/" title="Prefix" class="md-nav__link">
|
||||
Prefix
|
||||
</a>
|
||||
</li>
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
<li class="md-nav__item md-nav__item--active">
|
||||
|
||||
<input class="md-toggle md-nav__toggle" data-md-toggle="toc" type="checkbox" id="__toc">
|
||||
|
||||
|
||||
<label class="md-nav__link md-nav__link--active" for="__toc">
|
||||
Delete
|
||||
</label>
|
||||
|
||||
<a href="./" title="Delete" class="md-nav__link md-nav__link--active">
|
||||
Delete
|
||||
</a>
|
||||
|
||||
|
||||
<nav class="md-nav md-nav--secondary">
|
||||
|
||||
|
||||
|
||||
<label class="md-nav__title" for="__toc">Table of contents</label>
|
||||
<ul class="md-nav__list" data-md-scrollfix>
|
||||
|
||||
<li class="md-nav__item">
|
||||
<a href="#to-stdout" title="To Stdout" class="md-nav__link">
|
||||
To Stdout
|
||||
</a>
|
||||
|
||||
</li>
|
||||
|
||||
<li class="md-nav__item">
|
||||
<a href="#from-stdin" title="From STDIN" class="md-nav__link">
|
||||
From STDIN
|
||||
</a>
|
||||
|
||||
</li>
|
||||
|
||||
<li class="md-nav__item">
|
||||
<a href="#deleting-array-elements" title="Deleting array elements" class="md-nav__link">
|
||||
Deleting array elements
|
||||
</a>
|
||||
|
||||
</li>
|
||||
|
||||
<li class="md-nav__item">
|
||||
<a href="#deleting-nodes-in-place" title="Deleting nodes in-place" class="md-nav__link">
|
||||
Deleting nodes in-place
|
||||
</a>
|
||||
|
||||
</li>
|
||||
|
||||
<li class="md-nav__item">
|
||||
<a href="#splat" title="Splat" class="md-nav__link">
|
||||
Splat
|
||||
</a>
|
||||
|
||||
</li>
|
||||
|
||||
<li class="md-nav__item">
|
||||
<a href="#prefix-splat" title="Prefix Splat" class="md-nav__link">
|
||||
Prefix Splat
|
||||
</a>
|
||||
|
||||
</li>
|
||||
|
||||
<li class="md-nav__item">
|
||||
<a href="#array-splat" title="Array Splat" class="md-nav__link">
|
||||
Array Splat
|
||||
</a>
|
||||
|
||||
</li>
|
||||
|
||||
<li class="md-nav__item">
|
||||
<a href="#multiple-documents-delete-from-single-document" title="Multiple Documents - delete from single document" class="md-nav__link">
|
||||
Multiple Documents - delete from single document
|
||||
</a>
|
||||
|
||||
</li>
|
||||
|
||||
<li class="md-nav__item">
|
||||
<a href="#multiple-documents-delete-from-all-documents" title="Multiple Documents - delete from all documents" class="md-nav__link">
|
||||
Multiple Documents - delete from all documents
|
||||
</a>
|
||||
|
||||
</li>
|
||||
|
||||
<li class="md-nav__item">
|
||||
<a href="#keys-with-dots" title="Keys with dots" class="md-nav__link">
|
||||
Keys with dots
|
||||
</a>
|
||||
|
||||
</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>
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
</ul>
|
||||
|
||||
</nav>
|
||||
|
||||
</li>
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
<li class="md-nav__item">
|
||||
<a href="../create/" title="Create" class="md-nav__link">
|
||||
Create
|
||||
</a>
|
||||
</li>
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
<li class="md-nav__item">
|
||||
<a href="../convert/" title="Convert" class="md-nav__link">
|
||||
Convert
|
||||
</a>
|
||||
</li>
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
<li class="md-nav__item">
|
||||
<a href="../merge/" title="Merge" class="md-nav__link">
|
||||
Merge
|
||||
</a>
|
||||
</li>
|
||||
|
||||
|
||||
</ul>
|
||||
</nav>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
|
||||
<div class="md-sidebar md-sidebar--secondary" data-md-component="toc">
|
||||
<div class="md-sidebar__scrollwrap">
|
||||
<div class="md-sidebar__inner">
|
||||
|
||||
<nav class="md-nav md-nav--secondary">
|
||||
|
||||
|
||||
|
||||
<label class="md-nav__title" for="__toc">Table of contents</label>
|
||||
<ul class="md-nav__list" data-md-scrollfix>
|
||||
|
||||
<li class="md-nav__item">
|
||||
<a href="#to-stdout" title="To Stdout" class="md-nav__link">
|
||||
To Stdout
|
||||
</a>
|
||||
|
||||
</li>
|
||||
|
||||
<li class="md-nav__item">
|
||||
<a href="#from-stdin" title="From STDIN" class="md-nav__link">
|
||||
From STDIN
|
||||
</a>
|
||||
|
||||
</li>
|
||||
|
||||
<li class="md-nav__item">
|
||||
<a href="#deleting-array-elements" title="Deleting array elements" class="md-nav__link">
|
||||
Deleting array elements
|
||||
</a>
|
||||
|
||||
</li>
|
||||
|
||||
<li class="md-nav__item">
|
||||
<a href="#deleting-nodes-in-place" title="Deleting nodes in-place" class="md-nav__link">
|
||||
Deleting nodes in-place
|
||||
</a>
|
||||
|
||||
</li>
|
||||
|
||||
<li class="md-nav__item">
|
||||
<a href="#splat" title="Splat" class="md-nav__link">
|
||||
Splat
|
||||
</a>
|
||||
|
||||
</li>
|
||||
|
||||
<li class="md-nav__item">
|
||||
<a href="#prefix-splat" title="Prefix Splat" class="md-nav__link">
|
||||
Prefix Splat
|
||||
</a>
|
||||
|
||||
</li>
|
||||
|
||||
<li class="md-nav__item">
|
||||
<a href="#array-splat" title="Array Splat" class="md-nav__link">
|
||||
Array Splat
|
||||
</a>
|
||||
|
||||
</li>
|
||||
|
||||
<li class="md-nav__item">
|
||||
<a href="#multiple-documents-delete-from-single-document" title="Multiple Documents - delete from single document" class="md-nav__link">
|
||||
Multiple Documents - delete from single document
|
||||
</a>
|
||||
|
||||
</li>
|
||||
|
||||
<li class="md-nav__item">
|
||||
<a href="#multiple-documents-delete-from-all-documents" title="Multiple Documents - delete from all documents" class="md-nav__link">
|
||||
Multiple Documents - delete from all documents
|
||||
</a>
|
||||
|
||||
</li>
|
||||
|
||||
<li class="md-nav__item">
|
||||
<a href="#keys-with-dots" title="Keys with dots" class="md-nav__link">
|
||||
Keys with dots
|
||||
</a>
|
||||
|
||||
</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>
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
</ul>
|
||||
|
||||
</nav>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
|
||||
<div class="md-content">
|
||||
<article class="md-content__inner md-typeset">
|
||||
|
||||
|
||||
<a href="https://github.com/mikefarah/yq/edit/master/docs/delete.md" title="Edit this page" class="md-icon md-content__icon"></a>
|
||||
|
||||
|
||||
<h1>Delete</h1>
|
||||
|
||||
<pre><code>yq d <yaml_file> <path_to_delete>
|
||||
</code></pre>
|
||||
|
||||
<h3 id="to-stdout">To Stdout<a class="headerlink" href="#to-stdout" title="Permanent link">¶</a></h3>
|
||||
<p>Given a sample.yaml file of:</p>
|
||||
<pre><code class="yaml">b:
|
||||
c: 2
|
||||
apples: green
|
||||
</code></pre>
|
||||
|
||||
<p>then</p>
|
||||
<pre><code class="bash">yq d sample.yaml b.c
|
||||
</code></pre>
|
||||
|
||||
<p>will output:</p>
|
||||
<pre><code class="yaml">b:
|
||||
apples: green
|
||||
</code></pre>
|
||||
|
||||
<h3 id="from-stdin">From STDIN<a class="headerlink" href="#from-stdin" title="Permanent link">¶</a></h3>
|
||||
<pre><code class="bash">cat sample.yaml | yq d - b.c
|
||||
</code></pre>
|
||||
|
||||
<h3 id="deleting-array-elements">Deleting array elements<a class="headerlink" href="#deleting-array-elements" title="Permanent link">¶</a></h3>
|
||||
<p>Given a sample.yaml file of:</p>
|
||||
<pre><code class="yaml">b:
|
||||
c:
|
||||
- 1
|
||||
- 2
|
||||
- 3
|
||||
</code></pre>
|
||||
|
||||
<p>then</p>
|
||||
<pre><code class="bash">yq d sample.yaml 'b.c[1]'
|
||||
</code></pre>
|
||||
|
||||
<p>will output:</p>
|
||||
<pre><code class="yaml">b:
|
||||
c:
|
||||
- 1
|
||||
- 3
|
||||
</code></pre>
|
||||
|
||||
<h3 id="deleting-nodes-in-place">Deleting nodes in-place<a class="headerlink" href="#deleting-nodes-in-place" title="Permanent link">¶</a></h3>
|
||||
<p>Given a sample.yaml file of:</p>
|
||||
<pre><code class="yaml">b:
|
||||
c: 2
|
||||
apples: green
|
||||
</code></pre>
|
||||
|
||||
<p>then</p>
|
||||
<pre><code class="bash">yq d -i sample.yaml b.c
|
||||
</code></pre>
|
||||
|
||||
<p>will update the sample.yaml file so that the 'c' node is deleted</p>
|
||||
<h3 id="splat">Splat<a class="headerlink" href="#splat" title="Permanent link">¶</a></h3>
|
||||
<p>Given a sample.yaml file of:</p>
|
||||
<pre><code class="yaml">---
|
||||
bob:
|
||||
item1:
|
||||
cats: bananas
|
||||
dogs: woof
|
||||
item2:
|
||||
cats: apples
|
||||
dogs: woof2
|
||||
thing:
|
||||
cats: oranges
|
||||
dogs: woof3
|
||||
</code></pre>
|
||||
|
||||
<p>then</p>
|
||||
<pre><code class="bash">yq d sample.yaml bob.*.cats
|
||||
</code></pre>
|
||||
|
||||
<p>will output:</p>
|
||||
<pre><code class="yaml">---
|
||||
bob:
|
||||
item1:
|
||||
dogs: woof
|
||||
item2:
|
||||
dogs: woof2
|
||||
thing:
|
||||
dogs: woof3
|
||||
</code></pre>
|
||||
|
||||
<h3 id="prefix-splat">Prefix Splat<a class="headerlink" href="#prefix-splat" title="Permanent link">¶</a></h3>
|
||||
<p>Given a sample.yaml file of:</p>
|
||||
<pre><code class="yaml">---
|
||||
bob:
|
||||
item1:
|
||||
cats: bananas
|
||||
dogs: woof
|
||||
item2:
|
||||
cats: apples
|
||||
dogs: woof2
|
||||
thing:
|
||||
cats: oranges
|
||||
dogs: woof3
|
||||
</code></pre>
|
||||
|
||||
<p>then</p>
|
||||
<pre><code class="bash">yq d sample.yaml bob.item*.cats
|
||||
</code></pre>
|
||||
|
||||
<p>will output:</p>
|
||||
<pre><code class="yaml">---
|
||||
bob:
|
||||
item1:
|
||||
dogs: woof
|
||||
item2:
|
||||
dogs: woof2
|
||||
thing:
|
||||
cats: oranges
|
||||
dogs: woof3
|
||||
</code></pre>
|
||||
|
||||
<h3 id="array-splat">Array Splat<a class="headerlink" href="#array-splat" title="Permanent link">¶</a></h3>
|
||||
<p>Given a sample.yaml file of:</p>
|
||||
<pre><code class="yaml">---
|
||||
bob:
|
||||
- cats: bananas
|
||||
dogs: woof
|
||||
- cats: apples
|
||||
dogs: woof2
|
||||
- cats: oranges
|
||||
dogs: woof3
|
||||
</code></pre>
|
||||
|
||||
<p>then</p>
|
||||
<pre><code class="bash">yq d sample.yaml bob.[*].cats
|
||||
</code></pre>
|
||||
|
||||
<p>will output:</p>
|
||||
<pre><code class="yaml">---
|
||||
bob:
|
||||
- dogs: woof
|
||||
- dogs: woof2
|
||||
- dogs: woof3
|
||||
</code></pre>
|
||||
|
||||
<h3 id="multiple-documents-delete-from-single-document">Multiple Documents - delete from single document<a class="headerlink" href="#multiple-documents-delete-from-single-document" title="Permanent link">¶</a></h3>
|
||||
<p>Given a sample.yaml file of:</p>
|
||||
<pre><code class="yaml">something: else
|
||||
field: leaveMe
|
||||
---
|
||||
b:
|
||||
c: 2
|
||||
field: deleteMe
|
||||
</code></pre>
|
||||
|
||||
<p>then</p>
|
||||
<pre><code class="bash">yq w -d1 sample.yaml field
|
||||
</code></pre>
|
||||
|
||||
<p>will output:</p>
|
||||
<pre><code class="yaml">something: else
|
||||
field: leaveMe
|
||||
---
|
||||
b:
|
||||
c: 2
|
||||
</code></pre>
|
||||
|
||||
<h3 id="multiple-documents-delete-from-all-documents">Multiple Documents - delete from all documents<a class="headerlink" href="#multiple-documents-delete-from-all-documents" title="Permanent link">¶</a></h3>
|
||||
<p>Given a sample.yaml file of:</p>
|
||||
<pre><code class="yaml">something: else
|
||||
field: deleteMe
|
||||
---
|
||||
b:
|
||||
c: 2
|
||||
field: deleteMeToo
|
||||
</code></pre>
|
||||
|
||||
<p>then</p>
|
||||
<pre><code class="bash">yq w -d'*' sample.yaml field
|
||||
</code></pre>
|
||||
|
||||
<p>will output:</p>
|
||||
<pre><code class="yaml">something: else
|
||||
---
|
||||
b:
|
||||
c: 2
|
||||
</code></pre>
|
||||
|
||||
<p>Note that '*' is in quotes to avoid being interpreted by your shell.</p>
|
||||
<h3 id="keys-with-dots">Keys with dots<a class="headerlink" href="#keys-with-dots" title="Permanent link">¶</a></h3>
|
||||
<p>When specifying a key that has a dot use key lookup indicator.</p>
|
||||
<pre><code class="yaml">b:
|
||||
foo.bar: 7
|
||||
</code></pre>
|
||||
|
||||
<pre><code class="bash">yaml r sample.yaml 'b[foo.bar]'
|
||||
</code></pre>
|
||||
|
||||
<pre><code class="bash">yaml w sample.yaml 'b[foo.bar]' 9
|
||||
</code></pre>
|
||||
|
||||
<p>Any valid yaml key can be specified as part of a key lookup.</p>
|
||||
<p>Note that the path is in quotes to avoid the square brackets being interpreted by your shell.</p>
|
||||
<h3 id="keys-and-values-with-leading-dashes">Keys (and values) with leading dashes<a class="headerlink" href="#keys-and-values-with-leading-dashes" title="Permanent link">¶</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>
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
</article>
|
||||
</div>
|
||||
</div>
|
||||
</main>
|
||||
|
||||
|
||||
<footer class="md-footer">
|
||||
|
||||
<div class="md-footer-nav">
|
||||
<nav class="md-footer-nav__inner md-grid">
|
||||
|
||||
<a href="../prefix/" title="Prefix" class="md-flex md-footer-nav__link md-footer-nav__link--prev" rel="prev">
|
||||
<div class="md-flex__cell md-flex__cell--shrink">
|
||||
<i class="md-icon md-icon--arrow-back md-footer-nav__button"></i>
|
||||
</div>
|
||||
<div class="md-flex__cell md-flex__cell--stretch md-footer-nav__title">
|
||||
<span class="md-flex__ellipsis">
|
||||
<span class="md-footer-nav__direction">
|
||||
Previous
|
||||
</span>
|
||||
Prefix
|
||||
</span>
|
||||
</div>
|
||||
</a>
|
||||
|
||||
|
||||
<a href="../create/" title="Create" class="md-flex md-footer-nav__link md-footer-nav__link--next" rel="next">
|
||||
<div class="md-flex__cell md-flex__cell--stretch md-footer-nav__title">
|
||||
<span class="md-flex__ellipsis">
|
||||
<span class="md-footer-nav__direction">
|
||||
Next
|
||||
</span>
|
||||
Create
|
||||
</span>
|
||||
</div>
|
||||
<div class="md-flex__cell md-flex__cell--shrink">
|
||||
<i class="md-icon md-icon--arrow-forward md-footer-nav__button"></i>
|
||||
</div>
|
||||
</a>
|
||||
|
||||
</nav>
|
||||
</div>
|
||||
|
||||
<div class="md-footer-meta md-typeset">
|
||||
<div class="md-footer-meta__inner md-grid">
|
||||
<div class="md-footer-copyright">
|
||||
|
||||
powered by
|
||||
<a href="https://www.mkdocs.org">MkDocs</a>
|
||||
and
|
||||
<a href="https://squidfunk.github.io/mkdocs-material/">
|
||||
Material for MkDocs</a>
|
||||
</div>
|
||||
|
||||
<div class="md-footer-social">
|
||||
<link rel="stylesheet" href="../assets/fonts/font-awesome.css">
|
||||
|
||||
<a href="https://github.com/mikefarah" class="md-footer-social__link fa fa-github"></a>
|
||||
|
||||
<a href="https://www.linkedin.com/in/mike-farah-b5a75b2/" class="md-footer-social__link fa fa-linkedin"></a>
|
||||
|
||||
</div>
|
||||
|
||||
</div>
|
||||
</div>
|
||||
</footer>
|
||||
|
||||
</div>
|
||||
|
||||
<script src="../assets/javascripts/application.39abc4af.js"></script>
|
||||
|
||||
<script>app.initialize({version:"1.0.4",url:{base:".."}})</script>
|
||||
|
||||
|
||||
</body>
|
||||
</html>
|
319
docs/index.html
319
docs/index.html
@ -32,7 +32,7 @@
|
||||
<meta name="lang:search.tokenizer" content="[\s\-]+">
|
||||
|
||||
<link rel="shortcut icon" href="assets/images/favicon.png">
|
||||
<meta name="generator" content="mkdocs-1.0.4, mkdocs-material-4.2.0">
|
||||
<meta name="generator" content="mkdocs-1.0.4, mkdocs-material-4.6.0">
|
||||
|
||||
|
||||
|
||||
@ -40,17 +40,17 @@
|
||||
|
||||
|
||||
|
||||
<link rel="stylesheet" href="assets/stylesheets/application.750b69bd.css">
|
||||
<link rel="stylesheet" href="assets/stylesheets/application.1b62728e.css">
|
||||
|
||||
|
||||
|
||||
|
||||
<script src="assets/javascripts/modernizr.74668098.js"></script>
|
||||
<script src="assets/javascripts/modernizr.268332fc.js"></script>
|
||||
|
||||
|
||||
|
||||
<link href="https://fonts.gstatic.com" rel="preconnect" crossorigin>
|
||||
<link rel="stylesheet" href="https://fonts.googleapis.com/css?family=Roboto:300,400,400i,700|Roboto+Mono">
|
||||
<link rel="stylesheet" href="https://fonts.googleapis.com/css?family=Roboto:300,400,400i,700%7CRoboto+Mono&display=fallback">
|
||||
<style>body,input{font-family:"Roboto","Helvetica Neue",Helvetica,Arial,sans-serif}code,kbd,pre{font-family:"Roboto Mono","Courier New",Courier,monospace}</style>
|
||||
|
||||
|
||||
@ -69,24 +69,7 @@
|
||||
<defs>
|
||||
|
||||
|
||||
<svg xmlns="http://www.w3.org/2000/svg" width="416" height="448"
|
||||
viewBox="0 0 416 448" id="__github">
|
||||
<path fill="currentColor" d="M160 304q0 10-3.125 20.5t-10.75 19-18.125
|
||||
8.5-18.125-8.5-10.75-19-3.125-20.5 3.125-20.5 10.75-19 18.125-8.5
|
||||
18.125 8.5 10.75 19 3.125 20.5zM320 304q0 10-3.125 20.5t-10.75
|
||||
19-18.125 8.5-18.125-8.5-10.75-19-3.125-20.5 3.125-20.5 10.75-19
|
||||
18.125-8.5 18.125 8.5 10.75 19 3.125 20.5zM360
|
||||
304q0-30-17.25-51t-46.75-21q-10.25 0-48.75 5.25-17.75 2.75-39.25
|
||||
2.75t-39.25-2.75q-38-5.25-48.75-5.25-29.5 0-46.75 21t-17.25 51q0 22 8
|
||||
38.375t20.25 25.75 30.5 15 35 7.375 37.25 1.75h42q20.5 0
|
||||
37.25-1.75t35-7.375 30.5-15 20.25-25.75 8-38.375zM416 260q0 51.75-15.25
|
||||
82.75-9.5 19.25-26.375 33.25t-35.25 21.5-42.5 11.875-42.875 5.5-41.75
|
||||
1.125q-19.5 0-35.5-0.75t-36.875-3.125-38.125-7.5-34.25-12.875-30.25-20.25-21.5-28.75q-15.5-30.75-15.5-82.75
|
||||
0-59.25 34-99-6.75-20.5-6.75-42.5 0-29 12.75-54.5 27 0 47.5 9.875t47.25
|
||||
30.875q36.75-8.75 77.25-8.75 37 0 70 8 26.25-20.5
|
||||
46.75-30.25t47.25-9.75q12.75 25.5 12.75 54.5 0 21.75-6.75 42 34 40 34
|
||||
99.5z" />
|
||||
</svg>
|
||||
<svg xmlns="http://www.w3.org/2000/svg" width="416" height="448" viewBox="0 0 416 448" id="__github"><path fill="currentColor" d="M160 304q0 10-3.125 20.5t-10.75 19T128 352t-18.125-8.5-10.75-19T96 304t3.125-20.5 10.75-19T128 256t18.125 8.5 10.75 19T160 304zm160 0q0 10-3.125 20.5t-10.75 19T288 352t-18.125-8.5-10.75-19T256 304t3.125-20.5 10.75-19T288 256t18.125 8.5 10.75 19T320 304zm40 0q0-30-17.25-51T296 232q-10.25 0-48.75 5.25Q229.5 240 208 240t-39.25-2.75Q130.75 232 120 232q-29.5 0-46.75 21T56 304q0 22 8 38.375t20.25 25.75 30.5 15 35 7.375 37.25 1.75h42q20.5 0 37.25-1.75t35-7.375 30.5-15 20.25-25.75T360 304zm56-44q0 51.75-15.25 82.75-9.5 19.25-26.375 33.25t-35.25 21.5-42.5 11.875-42.875 5.5T212 416q-19.5 0-35.5-.75t-36.875-3.125-38.125-7.5-34.25-12.875T37 371.5t-21.5-28.75Q0 312 0 260q0-59.25 34-99-6.75-20.5-6.75-42.5 0-29 12.75-54.5 27 0 47.5 9.875t47.25 30.875Q171.5 96 212 96q37 0 70 8 26.25-20.5 46.75-30.25T376 64q12.75 25.5 12.75 54.5 0 21.75-6.75 42 34 40 34 99.5z"/></svg>
|
||||
|
||||
</defs>
|
||||
</svg>
|
||||
@ -94,7 +77,7 @@
|
||||
<input class="md-toggle" data-md-toggle="search" type="checkbox" id="__search" autocomplete="off">
|
||||
<label class="md-overlay" data-md-component="overlay" for="__drawer"></label>
|
||||
|
||||
<a href="#yq" tabindex="1" class="md-skip">
|
||||
<a href="#new-documentation-website" tabindex="1" class="md-skip">
|
||||
Skip to content
|
||||
</a>
|
||||
|
||||
@ -118,9 +101,7 @@
|
||||
<span class="md-header-nav__topic">
|
||||
Yq
|
||||
</span>
|
||||
<span class="md-header-nav__topic">
|
||||
Install
|
||||
</span>
|
||||
|
||||
|
||||
</div>
|
||||
</div>
|
||||
@ -128,28 +109,6 @@
|
||||
|
||||
<label class="md-icon md-icon--search md-header-nav__button" for="__search"></label>
|
||||
|
||||
<div class="md-search" data-md-component="search" role="dialog">
|
||||
<label class="md-search__overlay" for="__search"></label>
|
||||
<div class="md-search__inner" role="search">
|
||||
<form class="md-search__form" name="search">
|
||||
<input type="text" class="md-search__input" name="query" placeholder="Search" autocapitalize="off" autocorrect="off" autocomplete="off" spellcheck="false" data-md-component="query" data-md-state="active">
|
||||
<label class="md-icon md-search__icon" for="__search"></label>
|
||||
<button type="reset" class="md-icon md-search__icon" data-md-component="reset" tabindex="-1">
|
||||

|
||||
</button>
|
||||
</form>
|
||||
<div class="md-search__output">
|
||||
<div class="md-search__scrollwrap" data-md-scrollfix>
|
||||
<div class="md-search-result" data-md-component="result">
|
||||
<div class="md-search-result__meta">
|
||||
Type to start searching
|
||||
</div>
|
||||
<ol class="md-search-result__list"></ol>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
</div>
|
||||
|
||||
@ -184,248 +143,22 @@
|
||||
|
||||
|
||||
|
||||
<main class="md-main">
|
||||
<main class="md-main" role="main">
|
||||
<div class="md-main__inner md-grid" data-md-component="container">
|
||||
|
||||
|
||||
<div class="md-sidebar md-sidebar--primary" data-md-component="navigation">
|
||||
<div class="md-sidebar__scrollwrap">
|
||||
<div class="md-sidebar__inner">
|
||||
<nav class="md-nav md-nav--primary" data-md-level="0">
|
||||
<label class="md-nav__title md-nav__title--site" for="__drawer">
|
||||
<a href="." title="Yq" class="md-nav__button md-logo">
|
||||
|
||||
<i class="md-icon"></i>
|
||||
|
||||
</a>
|
||||
Yq
|
||||
</label>
|
||||
|
||||
<div class="md-nav__source">
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
<a href="https://github.com/mikefarah/yq/" title="Go to repository" class="md-source" data-md-source="github">
|
||||
|
||||
<div class="md-source__icon">
|
||||
<svg viewBox="0 0 24 24" width="24" height="24">
|
||||
<use xlink:href="#__github" width="24" height="24"></use>
|
||||
</svg>
|
||||
</div>
|
||||
|
||||
<div class="md-source__repository">
|
||||
mikefarah/yq
|
||||
</div>
|
||||
</a>
|
||||
</div>
|
||||
|
||||
<ul class="md-nav__list" data-md-scrollfix>
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
<li class="md-nav__item md-nav__item--active">
|
||||
|
||||
<input class="md-toggle md-nav__toggle" data-md-toggle="toc" type="checkbox" id="__toc">
|
||||
|
||||
|
||||
|
||||
|
||||
<label class="md-nav__link md-nav__link--active" for="__toc">
|
||||
Install
|
||||
</label>
|
||||
|
||||
<a href="." title="Install" class="md-nav__link md-nav__link--active">
|
||||
Install
|
||||
</a>
|
||||
|
||||
|
||||
<nav class="md-nav md-nav--secondary">
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
<label class="md-nav__title" for="__toc">Table of contents</label>
|
||||
<ul class="md-nav__list" data-md-scrollfix>
|
||||
|
||||
<li class="md-nav__item">
|
||||
<a href="#install" title="Install" class="md-nav__link">
|
||||
Install
|
||||
</a>
|
||||
|
||||
</li>
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
</ul>
|
||||
|
||||
</nav>
|
||||
|
||||
</li>
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
<li class="md-nav__item">
|
||||
<a href="read/" title="Read" class="md-nav__link">
|
||||
Read
|
||||
</a>
|
||||
</li>
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
<li class="md-nav__item">
|
||||
<a href="write/" title="Write/Update" class="md-nav__link">
|
||||
Write/Update
|
||||
</a>
|
||||
</li>
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
<li class="md-nav__item">
|
||||
<a href="prefix/" title="Prefix" class="md-nav__link">
|
||||
Prefix
|
||||
</a>
|
||||
</li>
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
<li class="md-nav__item">
|
||||
<a href="delete/" title="Delete" class="md-nav__link">
|
||||
Delete
|
||||
</a>
|
||||
</li>
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
<li class="md-nav__item">
|
||||
<a href="create/" title="Create" class="md-nav__link">
|
||||
Create
|
||||
</a>
|
||||
</li>
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
<li class="md-nav__item">
|
||||
<a href="convert/" title="Convert" class="md-nav__link">
|
||||
Convert
|
||||
</a>
|
||||
</li>
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
<li class="md-nav__item">
|
||||
<a href="merge/" title="Merge" class="md-nav__link">
|
||||
Merge
|
||||
</a>
|
||||
</li>
|
||||
|
||||
|
||||
</ul>
|
||||
</nav>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
|
||||
<div class="md-sidebar md-sidebar--secondary" data-md-component="toc">
|
||||
<div class="md-sidebar__scrollwrap">
|
||||
<div class="md-sidebar__inner">
|
||||
|
||||
<nav class="md-nav md-nav--secondary">
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
<label class="md-nav__title" for="__toc">Table of contents</label>
|
||||
<ul class="md-nav__list" data-md-scrollfix>
|
||||
|
||||
<li class="md-nav__item">
|
||||
<a href="#install" title="Install" class="md-nav__link">
|
||||
Install
|
||||
</a>
|
||||
|
||||
</li>
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
</ul>
|
||||
|
||||
</nav>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
|
||||
<div class="md-content">
|
||||
<article class="md-content__inner md-typeset">
|
||||
|
||||
|
||||
<a href="https://github.com/mikefarah/yq/edit/master/docs/index.md" title="Edit this page" class="md-icon md-content__icon"></a>
|
||||
|
||||
<h1>New documentation website</h1>
|
||||
|
||||
<h1 id="yq">yq<a class="headerlink" href="#yq" title="Permanent link">¶</a></h1>
|
||||
<p>yq is a lightweight and portable command-line YAML processor</p>
|
||||
<p>The aim of the project is to be the <a href="https://github.com/stedolan/jq">jq</a> or sed of yaml files.</p>
|
||||
<h2 id="install">Install<a class="headerlink" href="#install" title="Permanent link">¶</a></h2>
|
||||
<p>On MacOS:</p>
|
||||
<pre><code>brew install yq
|
||||
</code></pre>
|
||||
<p>User docs are better than ever, and have been <a href="https://mikefarah.gitbook.io/yq">moved here</a></p>
|
||||
|
||||
<p>On Ubuntu and other Linux distros supporting <code>snap</code> packages:</p>
|
||||
<pre><code>snap install yq
|
||||
</code></pre>
|
||||
|
||||
<p>On Ubuntu 16.04 or higher from Debian package:</p>
|
||||
<pre><code>sudo add-apt-repository ppa:rmescandon/yq
|
||||
sudo apt update
|
||||
sudo apt install yq -y
|
||||
</code></pre>
|
||||
|
||||
<p>or, <a href="https://github.com/mikefarah/yq/releases/latest">Download latest binary</a> or alternatively:</p>
|
||||
<pre><code>go get gopkg.in/mikefarah/yq.v2
|
||||
</code></pre>
|
||||
|
||||
<p><a href="https://github.com/mikefarah/yq">View on GitHub</a></p>
|
||||
|
||||
|
||||
|
||||
@ -443,27 +176,6 @@ sudo apt install yq -y
|
||||
|
||||
<footer class="md-footer">
|
||||
|
||||
<div class="md-footer-nav">
|
||||
<nav class="md-footer-nav__inner md-grid">
|
||||
|
||||
|
||||
<a href="read/" title="Read" class="md-flex md-footer-nav__link md-footer-nav__link--next" rel="next">
|
||||
<div class="md-flex__cell md-flex__cell--stretch md-footer-nav__title">
|
||||
<span class="md-flex__ellipsis">
|
||||
<span class="md-footer-nav__direction">
|
||||
Next
|
||||
</span>
|
||||
Read
|
||||
</span>
|
||||
</div>
|
||||
<div class="md-flex__cell md-flex__cell--shrink">
|
||||
<i class="md-icon md-icon--arrow-forward md-footer-nav__button"></i>
|
||||
</div>
|
||||
</a>
|
||||
|
||||
</nav>
|
||||
</div>
|
||||
|
||||
<div class="md-footer-meta md-typeset">
|
||||
<div class="md-footer-meta__inner md-grid">
|
||||
<div class="md-footer-copyright">
|
||||
@ -475,22 +187,13 @@ sudo apt install yq -y
|
||||
Material for MkDocs</a>
|
||||
</div>
|
||||
|
||||
<div class="md-footer-social">
|
||||
<link rel="stylesheet" href="assets/fonts/font-awesome.css">
|
||||
|
||||
<a href="https://github.com/mikefarah" class="md-footer-social__link fa fa-github"></a>
|
||||
|
||||
<a href="https://www.linkedin.com/in/mike-farah-b5a75b2/" class="md-footer-social__link fa fa-linkedin"></a>
|
||||
|
||||
</div>
|
||||
|
||||
</div>
|
||||
</div>
|
||||
</footer>
|
||||
|
||||
</div>
|
||||
|
||||
<script src="assets/javascripts/application.39abc4af.js"></script>
|
||||
<script src="assets/javascripts/application.808e90bb.js"></script>
|
||||
|
||||
<script>app.initialize({version:"1.0.4",url:{base:"."}})</script>
|
||||
|
||||
|
@ -1,730 +0,0 @@
|
||||
|
||||
|
||||
|
||||
|
||||
<!doctype html>
|
||||
<html lang="en" class="no-js">
|
||||
<head>
|
||||
|
||||
<meta charset="utf-8">
|
||||
<meta name="viewport" content="width=device-width,initial-scale=1">
|
||||
<meta http-equiv="x-ua-compatible" content="ie=edge">
|
||||
|
||||
|
||||
|
||||
|
||||
<meta name="lang:clipboard.copy" content="Copy to clipboard">
|
||||
|
||||
<meta name="lang:clipboard.copied" content="Copied to clipboard">
|
||||
|
||||
<meta name="lang:search.language" content="en">
|
||||
|
||||
<meta name="lang:search.pipeline.stopwords" content="True">
|
||||
|
||||
<meta name="lang:search.pipeline.trimmer" content="True">
|
||||
|
||||
<meta name="lang:search.result.none" content="No matching documents">
|
||||
|
||||
<meta name="lang:search.result.one" content="1 matching document">
|
||||
|
||||
<meta name="lang:search.result.other" content="# matching documents">
|
||||
|
||||
<meta name="lang:search.tokenizer" content="[\s\-]+">
|
||||
|
||||
<link rel="shortcut icon" href="../assets/images/favicon.png">
|
||||
<meta name="generator" content="mkdocs-1.0.4, mkdocs-material-4.2.0">
|
||||
|
||||
|
||||
|
||||
<title>Merge - Yq</title>
|
||||
|
||||
|
||||
|
||||
<link rel="stylesheet" href="../assets/stylesheets/application.750b69bd.css">
|
||||
|
||||
|
||||
|
||||
|
||||
<script src="../assets/javascripts/modernizr.74668098.js"></script>
|
||||
|
||||
|
||||
|
||||
<link href="https://fonts.gstatic.com" rel="preconnect" crossorigin>
|
||||
<link rel="stylesheet" href="https://fonts.googleapis.com/css?family=Roboto:300,400,400i,700|Roboto+Mono">
|
||||
<style>body,input{font-family:"Roboto","Helvetica Neue",Helvetica,Arial,sans-serif}code,kbd,pre{font-family:"Roboto Mono","Courier New",Courier,monospace}</style>
|
||||
|
||||
|
||||
<link rel="stylesheet" href="../assets/fonts/material-icons.css">
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
</head>
|
||||
|
||||
<body dir="ltr">
|
||||
|
||||
<svg class="md-svg">
|
||||
<defs>
|
||||
|
||||
|
||||
<svg xmlns="http://www.w3.org/2000/svg" width="416" height="448"
|
||||
viewBox="0 0 416 448" id="__github">
|
||||
<path fill="currentColor" d="M160 304q0 10-3.125 20.5t-10.75 19-18.125
|
||||
8.5-18.125-8.5-10.75-19-3.125-20.5 3.125-20.5 10.75-19 18.125-8.5
|
||||
18.125 8.5 10.75 19 3.125 20.5zM320 304q0 10-3.125 20.5t-10.75
|
||||
19-18.125 8.5-18.125-8.5-10.75-19-3.125-20.5 3.125-20.5 10.75-19
|
||||
18.125-8.5 18.125 8.5 10.75 19 3.125 20.5zM360
|
||||
304q0-30-17.25-51t-46.75-21q-10.25 0-48.75 5.25-17.75 2.75-39.25
|
||||
2.75t-39.25-2.75q-38-5.25-48.75-5.25-29.5 0-46.75 21t-17.25 51q0 22 8
|
||||
38.375t20.25 25.75 30.5 15 35 7.375 37.25 1.75h42q20.5 0
|
||||
37.25-1.75t35-7.375 30.5-15 20.25-25.75 8-38.375zM416 260q0 51.75-15.25
|
||||
82.75-9.5 19.25-26.375 33.25t-35.25 21.5-42.5 11.875-42.875 5.5-41.75
|
||||
1.125q-19.5 0-35.5-0.75t-36.875-3.125-38.125-7.5-34.25-12.875-30.25-20.25-21.5-28.75q-15.5-30.75-15.5-82.75
|
||||
0-59.25 34-99-6.75-20.5-6.75-42.5 0-29 12.75-54.5 27 0 47.5 9.875t47.25
|
||||
30.875q36.75-8.75 77.25-8.75 37 0 70 8 26.25-20.5
|
||||
46.75-30.25t47.25-9.75q12.75 25.5 12.75 54.5 0 21.75-6.75 42 34 40 34
|
||||
99.5z" />
|
||||
</svg>
|
||||
|
||||
</defs>
|
||||
</svg>
|
||||
<input class="md-toggle" data-md-toggle="drawer" type="checkbox" id="__drawer" autocomplete="off">
|
||||
<input class="md-toggle" data-md-toggle="search" type="checkbox" id="__search" autocomplete="off">
|
||||
<label class="md-overlay" data-md-component="overlay" for="__drawer"></label>
|
||||
|
||||
<a href="#to-stdout" tabindex="1" class="md-skip">
|
||||
Skip to content
|
||||
</a>
|
||||
|
||||
|
||||
<header class="md-header" data-md-component="header">
|
||||
<nav class="md-header-nav md-grid">
|
||||
<div class="md-flex">
|
||||
<div class="md-flex__cell md-flex__cell--shrink">
|
||||
<a href=".." title="Yq" class="md-header-nav__button md-logo">
|
||||
|
||||
<i class="md-icon"></i>
|
||||
|
||||
</a>
|
||||
</div>
|
||||
<div class="md-flex__cell md-flex__cell--shrink">
|
||||
<label class="md-icon md-icon--menu md-header-nav__button" for="__drawer"></label>
|
||||
</div>
|
||||
<div class="md-flex__cell md-flex__cell--stretch">
|
||||
<div class="md-flex__ellipsis md-header-nav__title" data-md-component="title">
|
||||
|
||||
<span class="md-header-nav__topic">
|
||||
Yq
|
||||
</span>
|
||||
<span class="md-header-nav__topic">
|
||||
Merge
|
||||
</span>
|
||||
|
||||
</div>
|
||||
</div>
|
||||
<div class="md-flex__cell md-flex__cell--shrink">
|
||||
|
||||
<label class="md-icon md-icon--search md-header-nav__button" for="__search"></label>
|
||||
|
||||
<div class="md-search" data-md-component="search" role="dialog">
|
||||
<label class="md-search__overlay" for="__search"></label>
|
||||
<div class="md-search__inner" role="search">
|
||||
<form class="md-search__form" name="search">
|
||||
<input type="text" class="md-search__input" name="query" placeholder="Search" autocapitalize="off" autocorrect="off" autocomplete="off" spellcheck="false" data-md-component="query" data-md-state="active">
|
||||
<label class="md-icon md-search__icon" for="__search"></label>
|
||||
<button type="reset" class="md-icon md-search__icon" data-md-component="reset" tabindex="-1">
|
||||

|
||||
</button>
|
||||
</form>
|
||||
<div class="md-search__output">
|
||||
<div class="md-search__scrollwrap" data-md-scrollfix>
|
||||
<div class="md-search-result" data-md-component="result">
|
||||
<div class="md-search-result__meta">
|
||||
Type to start searching
|
||||
</div>
|
||||
<ol class="md-search-result__list"></ol>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
</div>
|
||||
|
||||
<div class="md-flex__cell md-flex__cell--shrink">
|
||||
<div class="md-header-nav__source">
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
<a href="https://github.com/mikefarah/yq/" title="Go to repository" class="md-source" data-md-source="github">
|
||||
|
||||
<div class="md-source__icon">
|
||||
<svg viewBox="0 0 24 24" width="24" height="24">
|
||||
<use xlink:href="#__github" width="24" height="24"></use>
|
||||
</svg>
|
||||
</div>
|
||||
|
||||
<div class="md-source__repository">
|
||||
mikefarah/yq
|
||||
</div>
|
||||
</a>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
</div>
|
||||
</nav>
|
||||
</header>
|
||||
|
||||
<div class="md-container">
|
||||
|
||||
|
||||
|
||||
|
||||
<main class="md-main">
|
||||
<div class="md-main__inner md-grid" data-md-component="container">
|
||||
|
||||
|
||||
<div class="md-sidebar md-sidebar--primary" data-md-component="navigation">
|
||||
<div class="md-sidebar__scrollwrap">
|
||||
<div class="md-sidebar__inner">
|
||||
<nav class="md-nav md-nav--primary" data-md-level="0">
|
||||
<label class="md-nav__title md-nav__title--site" for="__drawer">
|
||||
<a href=".." title="Yq" class="md-nav__button md-logo">
|
||||
|
||||
<i class="md-icon"></i>
|
||||
|
||||
</a>
|
||||
Yq
|
||||
</label>
|
||||
|
||||
<div class="md-nav__source">
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
<a href="https://github.com/mikefarah/yq/" title="Go to repository" class="md-source" data-md-source="github">
|
||||
|
||||
<div class="md-source__icon">
|
||||
<svg viewBox="0 0 24 24" width="24" height="24">
|
||||
<use xlink:href="#__github" width="24" height="24"></use>
|
||||
</svg>
|
||||
</div>
|
||||
|
||||
<div class="md-source__repository">
|
||||
mikefarah/yq
|
||||
</div>
|
||||
</a>
|
||||
</div>
|
||||
|
||||
<ul class="md-nav__list" data-md-scrollfix>
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
<li class="md-nav__item">
|
||||
<a href=".." title="Install" class="md-nav__link">
|
||||
Install
|
||||
</a>
|
||||
</li>
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
<li class="md-nav__item">
|
||||
<a href="../read/" title="Read" class="md-nav__link">
|
||||
Read
|
||||
</a>
|
||||
</li>
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
<li class="md-nav__item">
|
||||
<a href="../write/" title="Write/Update" class="md-nav__link">
|
||||
Write/Update
|
||||
</a>
|
||||
</li>
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
<li class="md-nav__item">
|
||||
<a href="../prefix/" title="Prefix" class="md-nav__link">
|
||||
Prefix
|
||||
</a>
|
||||
</li>
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
<li class="md-nav__item">
|
||||
<a href="../delete/" title="Delete" class="md-nav__link">
|
||||
Delete
|
||||
</a>
|
||||
</li>
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
<li class="md-nav__item">
|
||||
<a href="../create/" title="Create" class="md-nav__link">
|
||||
Create
|
||||
</a>
|
||||
</li>
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
<li class="md-nav__item">
|
||||
<a href="../convert/" title="Convert" class="md-nav__link">
|
||||
Convert
|
||||
</a>
|
||||
</li>
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
<li class="md-nav__item md-nav__item--active">
|
||||
|
||||
<input class="md-toggle md-nav__toggle" data-md-toggle="toc" type="checkbox" id="__toc">
|
||||
|
||||
|
||||
<label class="md-nav__link md-nav__link--active" for="__toc">
|
||||
Merge
|
||||
</label>
|
||||
|
||||
<a href="./" title="Merge" class="md-nav__link md-nav__link--active">
|
||||
Merge
|
||||
</a>
|
||||
|
||||
|
||||
<nav class="md-nav md-nav--secondary">
|
||||
|
||||
|
||||
|
||||
<label class="md-nav__title" for="__toc">Table of contents</label>
|
||||
<ul class="md-nav__list" data-md-scrollfix>
|
||||
|
||||
<li class="md-nav__item">
|
||||
<a href="#to-stdout" title="To Stdout" class="md-nav__link">
|
||||
To Stdout
|
||||
</a>
|
||||
|
||||
</li>
|
||||
|
||||
<li class="md-nav__item">
|
||||
<a href="#updating-files-in-place" title="Updating files in-place" class="md-nav__link">
|
||||
Updating files in-place
|
||||
</a>
|
||||
|
||||
</li>
|
||||
|
||||
<li class="md-nav__item">
|
||||
<a href="#overwrite-values" title="Overwrite values" class="md-nav__link">
|
||||
Overwrite values
|
||||
</a>
|
||||
|
||||
</li>
|
||||
|
||||
<li class="md-nav__item">
|
||||
<a href="#overwrite-values-with-arrays" title="Overwrite values with arrays" class="md-nav__link">
|
||||
Overwrite values with arrays
|
||||
</a>
|
||||
|
||||
</li>
|
||||
|
||||
<li class="md-nav__item">
|
||||
<a href="#append-values-with-arrays" title="Append values with arrays" class="md-nav__link">
|
||||
Append values with arrays
|
||||
</a>
|
||||
|
||||
</li>
|
||||
|
||||
<li class="md-nav__item">
|
||||
<a href="#multiple-documents-merge-into-single-document" title="Multiple Documents - merge into single document" class="md-nav__link">
|
||||
Multiple Documents - merge into single document
|
||||
</a>
|
||||
|
||||
</li>
|
||||
|
||||
<li class="md-nav__item">
|
||||
<a href="#multiple-documents-merge-into-all-documents" title="Multiple Documents - merge into all documents" class="md-nav__link">
|
||||
Multiple Documents - merge into all documents
|
||||
</a>
|
||||
|
||||
</li>
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
</ul>
|
||||
|
||||
</nav>
|
||||
|
||||
</li>
|
||||
|
||||
|
||||
</ul>
|
||||
</nav>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
|
||||
<div class="md-sidebar md-sidebar--secondary" data-md-component="toc">
|
||||
<div class="md-sidebar__scrollwrap">
|
||||
<div class="md-sidebar__inner">
|
||||
|
||||
<nav class="md-nav md-nav--secondary">
|
||||
|
||||
|
||||
|
||||
<label class="md-nav__title" for="__toc">Table of contents</label>
|
||||
<ul class="md-nav__list" data-md-scrollfix>
|
||||
|
||||
<li class="md-nav__item">
|
||||
<a href="#to-stdout" title="To Stdout" class="md-nav__link">
|
||||
To Stdout
|
||||
</a>
|
||||
|
||||
</li>
|
||||
|
||||
<li class="md-nav__item">
|
||||
<a href="#updating-files-in-place" title="Updating files in-place" class="md-nav__link">
|
||||
Updating files in-place
|
||||
</a>
|
||||
|
||||
</li>
|
||||
|
||||
<li class="md-nav__item">
|
||||
<a href="#overwrite-values" title="Overwrite values" class="md-nav__link">
|
||||
Overwrite values
|
||||
</a>
|
||||
|
||||
</li>
|
||||
|
||||
<li class="md-nav__item">
|
||||
<a href="#overwrite-values-with-arrays" title="Overwrite values with arrays" class="md-nav__link">
|
||||
Overwrite values with arrays
|
||||
</a>
|
||||
|
||||
</li>
|
||||
|
||||
<li class="md-nav__item">
|
||||
<a href="#append-values-with-arrays" title="Append values with arrays" class="md-nav__link">
|
||||
Append values with arrays
|
||||
</a>
|
||||
|
||||
</li>
|
||||
|
||||
<li class="md-nav__item">
|
||||
<a href="#multiple-documents-merge-into-single-document" title="Multiple Documents - merge into single document" class="md-nav__link">
|
||||
Multiple Documents - merge into single document
|
||||
</a>
|
||||
|
||||
</li>
|
||||
|
||||
<li class="md-nav__item">
|
||||
<a href="#multiple-documents-merge-into-all-documents" title="Multiple Documents - merge into all documents" class="md-nav__link">
|
||||
Multiple Documents - merge into all documents
|
||||
</a>
|
||||
|
||||
</li>
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
</ul>
|
||||
|
||||
</nav>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
|
||||
<div class="md-content">
|
||||
<article class="md-content__inner md-typeset">
|
||||
|
||||
|
||||
<a href="https://github.com/mikefarah/yq/edit/master/docs/merge.md" title="Edit this page" class="md-icon md-content__icon"></a>
|
||||
|
||||
|
||||
<h1>Merge</h1>
|
||||
|
||||
<p>Yaml files can be merged using the 'merge' command. Each additional file merged with the first file will
|
||||
set values for any key not existing already or where the key has no value.</p>
|
||||
<pre><code>yq m <yaml_file> <path>...
|
||||
</code></pre>
|
||||
|
||||
<h3 id="to-stdout">To Stdout<a class="headerlink" href="#to-stdout" title="Permanent link">¶</a></h3>
|
||||
<p>Given a data1.yaml file of:</p>
|
||||
<pre><code class="yaml">a: simple
|
||||
b: [1, 2]
|
||||
</code></pre>
|
||||
|
||||
<p>and data2.yaml file of:</p>
|
||||
<pre><code class="yaml">a: other
|
||||
c:
|
||||
test: 1
|
||||
</code></pre>
|
||||
|
||||
<p>then</p>
|
||||
<pre><code class="bash">yq m data1.yaml data2.yaml
|
||||
</code></pre>
|
||||
|
||||
<p>will output:</p>
|
||||
<pre><code class="yaml">a: simple
|
||||
b: [1, 2]
|
||||
c:
|
||||
test: 1
|
||||
</code></pre>
|
||||
|
||||
<h3 id="updating-files-in-place">Updating files in-place<a class="headerlink" href="#updating-files-in-place" title="Permanent link">¶</a></h3>
|
||||
<p>Given a data1.yaml file of:</p>
|
||||
<pre><code class="yaml">a: simple
|
||||
b: [1, 2]
|
||||
</code></pre>
|
||||
|
||||
<p>and data2.yaml file of:</p>
|
||||
<pre><code class="yaml">a: other
|
||||
c:
|
||||
test: 1
|
||||
</code></pre>
|
||||
|
||||
<p>then</p>
|
||||
<pre><code class="bash">yq m -i data1.yaml data2.yaml
|
||||
</code></pre>
|
||||
|
||||
<p>will update the data1.yaml file so that the value of 'c' is 'test: 1'.</p>
|
||||
<h3 id="overwrite-values">Overwrite values<a class="headerlink" href="#overwrite-values" title="Permanent link">¶</a></h3>
|
||||
<p>Given a data1.yaml file of:</p>
|
||||
<pre><code class="yaml">a: simple
|
||||
b: [1, 2]
|
||||
</code></pre>
|
||||
|
||||
<p>and data2.yaml file of:</p>
|
||||
<pre><code class="yaml">a: other
|
||||
c:
|
||||
test: 1
|
||||
</code></pre>
|
||||
|
||||
<p>then</p>
|
||||
<pre><code class="bash">yq m -x data1.yaml data2.yaml
|
||||
</code></pre>
|
||||
|
||||
<p>will output:</p>
|
||||
<pre><code class="yaml">a: other
|
||||
b: [1, 2]
|
||||
c:
|
||||
test: 1
|
||||
</code></pre>
|
||||
|
||||
<h3 id="overwrite-values-with-arrays">Overwrite values with arrays<a class="headerlink" href="#overwrite-values-with-arrays" title="Permanent link">¶</a></h3>
|
||||
<p>Given a data1.yaml file of:</p>
|
||||
<pre><code class="yaml">a: simple
|
||||
b: [1, 2]
|
||||
</code></pre>
|
||||
|
||||
<p>and data3.yaml file of:</p>
|
||||
<pre><code class="yaml">b: [3, 4]
|
||||
c:
|
||||
test: 2
|
||||
other: true
|
||||
d: false
|
||||
</code></pre>
|
||||
|
||||
<p>then</p>
|
||||
<pre><code class="bash">yq m -x data1.yaml data3.yaml
|
||||
</code></pre>
|
||||
|
||||
<p>will output:</p>
|
||||
<pre><code class="yaml">a: simple
|
||||
b: [3, 4]
|
||||
c:
|
||||
test: 2
|
||||
other: true
|
||||
d: false
|
||||
</code></pre>
|
||||
|
||||
<p>Notice that 'b' does not result in the merging of the values within an array. </p>
|
||||
<h3 id="append-values-with-arrays">Append values with arrays<a class="headerlink" href="#append-values-with-arrays" title="Permanent link">¶</a></h3>
|
||||
<p>Given a data1.yaml file of:</p>
|
||||
<pre><code class="yaml">a: simple
|
||||
b: [1, 2]
|
||||
d: hi
|
||||
</code></pre>
|
||||
|
||||
<p>and data3.yaml file of:</p>
|
||||
<pre><code class="yaml">a: something
|
||||
b: [3, 4]
|
||||
c:
|
||||
test: 2
|
||||
other: true
|
||||
</code></pre>
|
||||
|
||||
<p>then</p>
|
||||
<pre><code class="bash">yq m -a data1.yaml data3.yaml
|
||||
</code></pre>
|
||||
|
||||
<p>will output:</p>
|
||||
<pre><code class="yaml">a: simple
|
||||
b: [1, 2, 3, 4]
|
||||
c:
|
||||
test: 2
|
||||
other: true
|
||||
d: hi
|
||||
</code></pre>
|
||||
|
||||
<p>Note that the 'b' array has concatenated the values from the second data file. Also note that other map keys are not overridden (field a).</p>
|
||||
<p>Append cannot be used with overwrite, if both flags are given then append is ignored.</p>
|
||||
<h3 id="multiple-documents-merge-into-single-document">Multiple Documents - merge into single document<a class="headerlink" href="#multiple-documents-merge-into-single-document" title="Permanent link">¶</a></h3>
|
||||
<p>Currently yq only has multi-document support for the <em>first</em> document being merged into. The remaining yaml files will have their first document selected.</p>
|
||||
<p>Given a data1.yaml file of:</p>
|
||||
<pre><code class="yaml">something: else
|
||||
---
|
||||
a: simple
|
||||
b: cat
|
||||
</code></pre>
|
||||
|
||||
<p>and data3.yaml file of:</p>
|
||||
<pre><code class="yaml">b: dog
|
||||
</code></pre>
|
||||
|
||||
<p>then</p>
|
||||
<pre><code class="bash">yq m -x -d1 data1.yaml data3.yaml
|
||||
</code></pre>
|
||||
|
||||
<p>will output:</p>
|
||||
<pre><code class="yaml">something: else
|
||||
---
|
||||
a: simple
|
||||
b: dog
|
||||
</code></pre>
|
||||
|
||||
<h3 id="multiple-documents-merge-into-all-documents">Multiple Documents - merge into all documents<a class="headerlink" href="#multiple-documents-merge-into-all-documents" title="Permanent link">¶</a></h3>
|
||||
<p>Currently yq only has multi-document support for the <em>first</em> document being merged into. The remaining yaml files will have their first document selected.</p>
|
||||
<p>Given a data1.yaml file of:</p>
|
||||
<pre><code class="yaml">something: else
|
||||
---
|
||||
a: simple
|
||||
b: cat
|
||||
</code></pre>
|
||||
|
||||
<p>and data3.yaml file of:</p>
|
||||
<pre><code class="yaml">b: dog
|
||||
</code></pre>
|
||||
|
||||
<p>then</p>
|
||||
<pre><code class="bash">yq m -x -d'*' data1.yaml data3.yaml
|
||||
</code></pre>
|
||||
|
||||
<p>will output:</p>
|
||||
<pre><code class="yaml">b: dog
|
||||
something: else
|
||||
---
|
||||
a: simple
|
||||
b: dog
|
||||
</code></pre>
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
</article>
|
||||
</div>
|
||||
</div>
|
||||
</main>
|
||||
|
||||
|
||||
<footer class="md-footer">
|
||||
|
||||
<div class="md-footer-nav">
|
||||
<nav class="md-footer-nav__inner md-grid">
|
||||
|
||||
<a href="../convert/" title="Convert" class="md-flex md-footer-nav__link md-footer-nav__link--prev" rel="prev">
|
||||
<div class="md-flex__cell md-flex__cell--shrink">
|
||||
<i class="md-icon md-icon--arrow-back md-footer-nav__button"></i>
|
||||
</div>
|
||||
<div class="md-flex__cell md-flex__cell--stretch md-footer-nav__title">
|
||||
<span class="md-flex__ellipsis">
|
||||
<span class="md-footer-nav__direction">
|
||||
Previous
|
||||
</span>
|
||||
Convert
|
||||
</span>
|
||||
</div>
|
||||
</a>
|
||||
|
||||
|
||||
</nav>
|
||||
</div>
|
||||
|
||||
<div class="md-footer-meta md-typeset">
|
||||
<div class="md-footer-meta__inner md-grid">
|
||||
<div class="md-footer-copyright">
|
||||
|
||||
powered by
|
||||
<a href="https://www.mkdocs.org">MkDocs</a>
|
||||
and
|
||||
<a href="https://squidfunk.github.io/mkdocs-material/">
|
||||
Material for MkDocs</a>
|
||||
</div>
|
||||
|
||||
<div class="md-footer-social">
|
||||
<link rel="stylesheet" href="../assets/fonts/font-awesome.css">
|
||||
|
||||
<a href="https://github.com/mikefarah" class="md-footer-social__link fa fa-github"></a>
|
||||
|
||||
<a href="https://www.linkedin.com/in/mike-farah-b5a75b2/" class="md-footer-social__link fa fa-linkedin"></a>
|
||||
|
||||
</div>
|
||||
|
||||
</div>
|
||||
</div>
|
||||
</footer>
|
||||
|
||||
</div>
|
||||
|
||||
<script src="../assets/javascripts/application.39abc4af.js"></script>
|
||||
|
||||
<script>app.initialize({version:"1.0.4",url:{base:".."}})</script>
|
||||
|
||||
|
||||
</body>
|
||||
</html>
|
@ -1,631 +0,0 @@
|
||||
|
||||
|
||||
|
||||
|
||||
<!doctype html>
|
||||
<html lang="en" class="no-js">
|
||||
<head>
|
||||
|
||||
<meta charset="utf-8">
|
||||
<meta name="viewport" content="width=device-width,initial-scale=1">
|
||||
<meta http-equiv="x-ua-compatible" content="ie=edge">
|
||||
|
||||
|
||||
|
||||
|
||||
<meta name="lang:clipboard.copy" content="Copy to clipboard">
|
||||
|
||||
<meta name="lang:clipboard.copied" content="Copied to clipboard">
|
||||
|
||||
<meta name="lang:search.language" content="en">
|
||||
|
||||
<meta name="lang:search.pipeline.stopwords" content="True">
|
||||
|
||||
<meta name="lang:search.pipeline.trimmer" content="True">
|
||||
|
||||
<meta name="lang:search.result.none" content="No matching documents">
|
||||
|
||||
<meta name="lang:search.result.one" content="1 matching document">
|
||||
|
||||
<meta name="lang:search.result.other" content="# matching documents">
|
||||
|
||||
<meta name="lang:search.tokenizer" content="[\s\-]+">
|
||||
|
||||
<link rel="shortcut icon" href="../assets/images/favicon.png">
|
||||
<meta name="generator" content="mkdocs-1.0.4, mkdocs-material-4.2.0">
|
||||
|
||||
|
||||
|
||||
<title>Prefix - Yq</title>
|
||||
|
||||
|
||||
|
||||
<link rel="stylesheet" href="../assets/stylesheets/application.750b69bd.css">
|
||||
|
||||
|
||||
|
||||
|
||||
<script src="../assets/javascripts/modernizr.74668098.js"></script>
|
||||
|
||||
|
||||
|
||||
<link href="https://fonts.gstatic.com" rel="preconnect" crossorigin>
|
||||
<link rel="stylesheet" href="https://fonts.googleapis.com/css?family=Roboto:300,400,400i,700|Roboto+Mono">
|
||||
<style>body,input{font-family:"Roboto","Helvetica Neue",Helvetica,Arial,sans-serif}code,kbd,pre{font-family:"Roboto Mono","Courier New",Courier,monospace}</style>
|
||||
|
||||
|
||||
<link rel="stylesheet" href="../assets/fonts/material-icons.css">
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
</head>
|
||||
|
||||
<body dir="ltr">
|
||||
|
||||
<svg class="md-svg">
|
||||
<defs>
|
||||
|
||||
|
||||
<svg xmlns="http://www.w3.org/2000/svg" width="416" height="448"
|
||||
viewBox="0 0 416 448" id="__github">
|
||||
<path fill="currentColor" d="M160 304q0 10-3.125 20.5t-10.75 19-18.125
|
||||
8.5-18.125-8.5-10.75-19-3.125-20.5 3.125-20.5 10.75-19 18.125-8.5
|
||||
18.125 8.5 10.75 19 3.125 20.5zM320 304q0 10-3.125 20.5t-10.75
|
||||
19-18.125 8.5-18.125-8.5-10.75-19-3.125-20.5 3.125-20.5 10.75-19
|
||||
18.125-8.5 18.125 8.5 10.75 19 3.125 20.5zM360
|
||||
304q0-30-17.25-51t-46.75-21q-10.25 0-48.75 5.25-17.75 2.75-39.25
|
||||
2.75t-39.25-2.75q-38-5.25-48.75-5.25-29.5 0-46.75 21t-17.25 51q0 22 8
|
||||
38.375t20.25 25.75 30.5 15 35 7.375 37.25 1.75h42q20.5 0
|
||||
37.25-1.75t35-7.375 30.5-15 20.25-25.75 8-38.375zM416 260q0 51.75-15.25
|
||||
82.75-9.5 19.25-26.375 33.25t-35.25 21.5-42.5 11.875-42.875 5.5-41.75
|
||||
1.125q-19.5 0-35.5-0.75t-36.875-3.125-38.125-7.5-34.25-12.875-30.25-20.25-21.5-28.75q-15.5-30.75-15.5-82.75
|
||||
0-59.25 34-99-6.75-20.5-6.75-42.5 0-29 12.75-54.5 27 0 47.5 9.875t47.25
|
||||
30.875q36.75-8.75 77.25-8.75 37 0 70 8 26.25-20.5
|
||||
46.75-30.25t47.25-9.75q12.75 25.5 12.75 54.5 0 21.75-6.75 42 34 40 34
|
||||
99.5z" />
|
||||
</svg>
|
||||
|
||||
</defs>
|
||||
</svg>
|
||||
<input class="md-toggle" data-md-toggle="drawer" type="checkbox" id="__drawer" autocomplete="off">
|
||||
<input class="md-toggle" data-md-toggle="search" type="checkbox" id="__search" autocomplete="off">
|
||||
<label class="md-overlay" data-md-component="overlay" for="__drawer"></label>
|
||||
|
||||
<a href="#to-stdout" tabindex="1" class="md-skip">
|
||||
Skip to content
|
||||
</a>
|
||||
|
||||
|
||||
<header class="md-header" data-md-component="header">
|
||||
<nav class="md-header-nav md-grid">
|
||||
<div class="md-flex">
|
||||
<div class="md-flex__cell md-flex__cell--shrink">
|
||||
<a href=".." title="Yq" class="md-header-nav__button md-logo">
|
||||
|
||||
<i class="md-icon"></i>
|
||||
|
||||
</a>
|
||||
</div>
|
||||
<div class="md-flex__cell md-flex__cell--shrink">
|
||||
<label class="md-icon md-icon--menu md-header-nav__button" for="__drawer"></label>
|
||||
</div>
|
||||
<div class="md-flex__cell md-flex__cell--stretch">
|
||||
<div class="md-flex__ellipsis md-header-nav__title" data-md-component="title">
|
||||
|
||||
<span class="md-header-nav__topic">
|
||||
Yq
|
||||
</span>
|
||||
<span class="md-header-nav__topic">
|
||||
Prefix
|
||||
</span>
|
||||
|
||||
</div>
|
||||
</div>
|
||||
<div class="md-flex__cell md-flex__cell--shrink">
|
||||
|
||||
<label class="md-icon md-icon--search md-header-nav__button" for="__search"></label>
|
||||
|
||||
<div class="md-search" data-md-component="search" role="dialog">
|
||||
<label class="md-search__overlay" for="__search"></label>
|
||||
<div class="md-search__inner" role="search">
|
||||
<form class="md-search__form" name="search">
|
||||
<input type="text" class="md-search__input" name="query" placeholder="Search" autocapitalize="off" autocorrect="off" autocomplete="off" spellcheck="false" data-md-component="query" data-md-state="active">
|
||||
<label class="md-icon md-search__icon" for="__search"></label>
|
||||
<button type="reset" class="md-icon md-search__icon" data-md-component="reset" tabindex="-1">
|
||||

|
||||
</button>
|
||||
</form>
|
||||
<div class="md-search__output">
|
||||
<div class="md-search__scrollwrap" data-md-scrollfix>
|
||||
<div class="md-search-result" data-md-component="result">
|
||||
<div class="md-search-result__meta">
|
||||
Type to start searching
|
||||
</div>
|
||||
<ol class="md-search-result__list"></ol>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
</div>
|
||||
|
||||
<div class="md-flex__cell md-flex__cell--shrink">
|
||||
<div class="md-header-nav__source">
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
<a href="https://github.com/mikefarah/yq/" title="Go to repository" class="md-source" data-md-source="github">
|
||||
|
||||
<div class="md-source__icon">
|
||||
<svg viewBox="0 0 24 24" width="24" height="24">
|
||||
<use xlink:href="#__github" width="24" height="24"></use>
|
||||
</svg>
|
||||
</div>
|
||||
|
||||
<div class="md-source__repository">
|
||||
mikefarah/yq
|
||||
</div>
|
||||
</a>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
</div>
|
||||
</nav>
|
||||
</header>
|
||||
|
||||
<div class="md-container">
|
||||
|
||||
|
||||
|
||||
|
||||
<main class="md-main">
|
||||
<div class="md-main__inner md-grid" data-md-component="container">
|
||||
|
||||
|
||||
<div class="md-sidebar md-sidebar--primary" data-md-component="navigation">
|
||||
<div class="md-sidebar__scrollwrap">
|
||||
<div class="md-sidebar__inner">
|
||||
<nav class="md-nav md-nav--primary" data-md-level="0">
|
||||
<label class="md-nav__title md-nav__title--site" for="__drawer">
|
||||
<a href=".." title="Yq" class="md-nav__button md-logo">
|
||||
|
||||
<i class="md-icon"></i>
|
||||
|
||||
</a>
|
||||
Yq
|
||||
</label>
|
||||
|
||||
<div class="md-nav__source">
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
<a href="https://github.com/mikefarah/yq/" title="Go to repository" class="md-source" data-md-source="github">
|
||||
|
||||
<div class="md-source__icon">
|
||||
<svg viewBox="0 0 24 24" width="24" height="24">
|
||||
<use xlink:href="#__github" width="24" height="24"></use>
|
||||
</svg>
|
||||
</div>
|
||||
|
||||
<div class="md-source__repository">
|
||||
mikefarah/yq
|
||||
</div>
|
||||
</a>
|
||||
</div>
|
||||
|
||||
<ul class="md-nav__list" data-md-scrollfix>
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
<li class="md-nav__item">
|
||||
<a href=".." title="Install" class="md-nav__link">
|
||||
Install
|
||||
</a>
|
||||
</li>
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
<li class="md-nav__item">
|
||||
<a href="../read/" title="Read" class="md-nav__link">
|
||||
Read
|
||||
</a>
|
||||
</li>
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
<li class="md-nav__item">
|
||||
<a href="../write/" title="Write/Update" class="md-nav__link">
|
||||
Write/Update
|
||||
</a>
|
||||
</li>
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
<li class="md-nav__item md-nav__item--active">
|
||||
|
||||
<input class="md-toggle md-nav__toggle" data-md-toggle="toc" type="checkbox" id="__toc">
|
||||
|
||||
|
||||
<label class="md-nav__link md-nav__link--active" for="__toc">
|
||||
Prefix
|
||||
</label>
|
||||
|
||||
<a href="./" title="Prefix" class="md-nav__link md-nav__link--active">
|
||||
Prefix
|
||||
</a>
|
||||
|
||||
|
||||
<nav class="md-nav md-nav--secondary">
|
||||
|
||||
|
||||
|
||||
<label class="md-nav__title" for="__toc">Table of contents</label>
|
||||
<ul class="md-nav__list" data-md-scrollfix>
|
||||
|
||||
<li class="md-nav__item">
|
||||
<a href="#to-stdout" title="To Stdout" class="md-nav__link">
|
||||
To Stdout
|
||||
</a>
|
||||
|
||||
</li>
|
||||
|
||||
<li class="md-nav__item">
|
||||
<a href="#arbitrary-depth" title="Arbitrary depth" class="md-nav__link">
|
||||
Arbitrary depth
|
||||
</a>
|
||||
|
||||
</li>
|
||||
|
||||
<li class="md-nav__item">
|
||||
<a href="#updating-files-in-place" title="Updating files in-place" class="md-nav__link">
|
||||
Updating files in-place
|
||||
</a>
|
||||
|
||||
</li>
|
||||
|
||||
<li class="md-nav__item">
|
||||
<a href="#multiple-documents-prefix-a-single-document" title="Multiple Documents - prefix a single document" class="md-nav__link">
|
||||
Multiple Documents - prefix a single document
|
||||
</a>
|
||||
|
||||
</li>
|
||||
|
||||
<li class="md-nav__item">
|
||||
<a href="#multiple-documents-prefix-all-documents" title="Multiple Documents - prefix all documents" class="md-nav__link">
|
||||
Multiple Documents - prefix all documents
|
||||
</a>
|
||||
|
||||
</li>
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
</ul>
|
||||
|
||||
</nav>
|
||||
|
||||
</li>
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
<li class="md-nav__item">
|
||||
<a href="../delete/" title="Delete" class="md-nav__link">
|
||||
Delete
|
||||
</a>
|
||||
</li>
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
<li class="md-nav__item">
|
||||
<a href="../create/" title="Create" class="md-nav__link">
|
||||
Create
|
||||
</a>
|
||||
</li>
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
<li class="md-nav__item">
|
||||
<a href="../convert/" title="Convert" class="md-nav__link">
|
||||
Convert
|
||||
</a>
|
||||
</li>
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
<li class="md-nav__item">
|
||||
<a href="../merge/" title="Merge" class="md-nav__link">
|
||||
Merge
|
||||
</a>
|
||||
</li>
|
||||
|
||||
|
||||
</ul>
|
||||
</nav>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
|
||||
<div class="md-sidebar md-sidebar--secondary" data-md-component="toc">
|
||||
<div class="md-sidebar__scrollwrap">
|
||||
<div class="md-sidebar__inner">
|
||||
|
||||
<nav class="md-nav md-nav--secondary">
|
||||
|
||||
|
||||
|
||||
<label class="md-nav__title" for="__toc">Table of contents</label>
|
||||
<ul class="md-nav__list" data-md-scrollfix>
|
||||
|
||||
<li class="md-nav__item">
|
||||
<a href="#to-stdout" title="To Stdout" class="md-nav__link">
|
||||
To Stdout
|
||||
</a>
|
||||
|
||||
</li>
|
||||
|
||||
<li class="md-nav__item">
|
||||
<a href="#arbitrary-depth" title="Arbitrary depth" class="md-nav__link">
|
||||
Arbitrary depth
|
||||
</a>
|
||||
|
||||
</li>
|
||||
|
||||
<li class="md-nav__item">
|
||||
<a href="#updating-files-in-place" title="Updating files in-place" class="md-nav__link">
|
||||
Updating files in-place
|
||||
</a>
|
||||
|
||||
</li>
|
||||
|
||||
<li class="md-nav__item">
|
||||
<a href="#multiple-documents-prefix-a-single-document" title="Multiple Documents - prefix a single document" class="md-nav__link">
|
||||
Multiple Documents - prefix a single document
|
||||
</a>
|
||||
|
||||
</li>
|
||||
|
||||
<li class="md-nav__item">
|
||||
<a href="#multiple-documents-prefix-all-documents" title="Multiple Documents - prefix all documents" class="md-nav__link">
|
||||
Multiple Documents - prefix all documents
|
||||
</a>
|
||||
|
||||
</li>
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
</ul>
|
||||
|
||||
</nav>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
|
||||
<div class="md-content">
|
||||
<article class="md-content__inner md-typeset">
|
||||
|
||||
|
||||
<a href="https://github.com/mikefarah/yq/edit/master/docs/prefix.md" title="Edit this page" class="md-icon md-content__icon"></a>
|
||||
|
||||
|
||||
<h1>Prefix</h1>
|
||||
|
||||
<p>Paths can be prefixed using the 'prefix' command.
|
||||
The complete yaml content will be nested inside the new prefix path.</p>
|
||||
<pre><code>yq p <yaml_file> <path>
|
||||
</code></pre>
|
||||
|
||||
<h3 id="to-stdout">To Stdout<a class="headerlink" href="#to-stdout" title="Permanent link">¶</a></h3>
|
||||
<p>Given a data1.yaml file of:</p>
|
||||
<pre><code class="yaml">a: simple
|
||||
b: [1, 2]
|
||||
</code></pre>
|
||||
|
||||
<p>then</p>
|
||||
<pre><code class="bash">yq p data1.yaml c
|
||||
</code></pre>
|
||||
|
||||
<p>will output:</p>
|
||||
<pre><code class="yaml">c:
|
||||
a: simple
|
||||
b: [1, 2]
|
||||
</code></pre>
|
||||
|
||||
<h3 id="arbitrary-depth">Arbitrary depth<a class="headerlink" href="#arbitrary-depth" title="Permanent link">¶</a></h3>
|
||||
<p>Given a data1.yaml file of:</p>
|
||||
<pre><code class="yaml">a:
|
||||
b: [1, 2]
|
||||
</code></pre>
|
||||
|
||||
<p>then</p>
|
||||
<pre><code class="bash">yq p data1.yaml c.d
|
||||
</code></pre>
|
||||
|
||||
<p>will output:</p>
|
||||
<pre><code class="yaml">c:
|
||||
d:
|
||||
a:
|
||||
b: [1, 2]
|
||||
</code></pre>
|
||||
|
||||
<h3 id="updating-files-in-place">Updating files in-place<a class="headerlink" href="#updating-files-in-place" title="Permanent link">¶</a></h3>
|
||||
<p>Given a data1.yaml file of:</p>
|
||||
<pre><code class="yaml">a: simple
|
||||
b: [1, 2]
|
||||
</code></pre>
|
||||
|
||||
<p>then</p>
|
||||
<pre><code class="bash">yq p -i data1.yaml c
|
||||
</code></pre>
|
||||
|
||||
<p>will update the data1.yaml file so that the path 'c' is prefixed to all other paths.</p>
|
||||
<h3 id="multiple-documents-prefix-a-single-document">Multiple Documents - prefix a single document<a class="headerlink" href="#multiple-documents-prefix-a-single-document" title="Permanent link">¶</a></h3>
|
||||
<p>Given a data1.yaml file of:</p>
|
||||
<pre><code class="yaml">something: else
|
||||
---
|
||||
a: simple
|
||||
b: cat
|
||||
</code></pre>
|
||||
|
||||
<p>then</p>
|
||||
<pre><code class="bash">yq p -d1 data1.yaml c
|
||||
</code></pre>
|
||||
|
||||
<p>will output:</p>
|
||||
<pre><code class="yaml">something: else
|
||||
---
|
||||
c:
|
||||
a: simple
|
||||
b: cat
|
||||
</code></pre>
|
||||
|
||||
<h3 id="multiple-documents-prefix-all-documents">Multiple Documents - prefix all documents<a class="headerlink" href="#multiple-documents-prefix-all-documents" title="Permanent link">¶</a></h3>
|
||||
<p>Given a data1.yaml file of:</p>
|
||||
<pre><code class="yaml">something: else
|
||||
---
|
||||
a: simple
|
||||
b: cat
|
||||
</code></pre>
|
||||
|
||||
<p>then</p>
|
||||
<pre><code class="bash">yq p -d'*' data1.yaml c
|
||||
</code></pre>
|
||||
|
||||
<p>will output:</p>
|
||||
<pre><code class="yaml">c:
|
||||
something: else
|
||||
---
|
||||
c:
|
||||
a: simple
|
||||
b: cat
|
||||
</code></pre>
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
</article>
|
||||
</div>
|
||||
</div>
|
||||
</main>
|
||||
|
||||
|
||||
<footer class="md-footer">
|
||||
|
||||
<div class="md-footer-nav">
|
||||
<nav class="md-footer-nav__inner md-grid">
|
||||
|
||||
<a href="../write/" title="Write/Update" class="md-flex md-footer-nav__link md-footer-nav__link--prev" rel="prev">
|
||||
<div class="md-flex__cell md-flex__cell--shrink">
|
||||
<i class="md-icon md-icon--arrow-back md-footer-nav__button"></i>
|
||||
</div>
|
||||
<div class="md-flex__cell md-flex__cell--stretch md-footer-nav__title">
|
||||
<span class="md-flex__ellipsis">
|
||||
<span class="md-footer-nav__direction">
|
||||
Previous
|
||||
</span>
|
||||
Write/Update
|
||||
</span>
|
||||
</div>
|
||||
</a>
|
||||
|
||||
|
||||
<a href="../delete/" title="Delete" class="md-flex md-footer-nav__link md-footer-nav__link--next" rel="next">
|
||||
<div class="md-flex__cell md-flex__cell--stretch md-footer-nav__title">
|
||||
<span class="md-flex__ellipsis">
|
||||
<span class="md-footer-nav__direction">
|
||||
Next
|
||||
</span>
|
||||
Delete
|
||||
</span>
|
||||
</div>
|
||||
<div class="md-flex__cell md-flex__cell--shrink">
|
||||
<i class="md-icon md-icon--arrow-forward md-footer-nav__button"></i>
|
||||
</div>
|
||||
</a>
|
||||
|
||||
</nav>
|
||||
</div>
|
||||
|
||||
<div class="md-footer-meta md-typeset">
|
||||
<div class="md-footer-meta__inner md-grid">
|
||||
<div class="md-footer-copyright">
|
||||
|
||||
powered by
|
||||
<a href="https://www.mkdocs.org">MkDocs</a>
|
||||
and
|
||||
<a href="https://squidfunk.github.io/mkdocs-material/">
|
||||
Material for MkDocs</a>
|
||||
</div>
|
||||
|
||||
<div class="md-footer-social">
|
||||
<link rel="stylesheet" href="../assets/fonts/font-awesome.css">
|
||||
|
||||
<a href="https://github.com/mikefarah" class="md-footer-social__link fa fa-github"></a>
|
||||
|
||||
<a href="https://www.linkedin.com/in/mike-farah-b5a75b2/" class="md-footer-social__link fa fa-linkedin"></a>
|
||||
|
||||
</div>
|
||||
|
||||
</div>
|
||||
</div>
|
||||
</footer>
|
||||
|
||||
</div>
|
||||
|
||||
<script src="../assets/javascripts/application.39abc4af.js"></script>
|
||||
|
||||
<script>app.initialize({version:"1.0.4",url:{base:".."}})</script>
|
||||
|
||||
|
||||
</body>
|
||||
</html>
|
@ -1,772 +0,0 @@
|
||||
|
||||
|
||||
|
||||
|
||||
<!doctype html>
|
||||
<html lang="en" class="no-js">
|
||||
<head>
|
||||
|
||||
<meta charset="utf-8">
|
||||
<meta name="viewport" content="width=device-width,initial-scale=1">
|
||||
<meta http-equiv="x-ua-compatible" content="ie=edge">
|
||||
|
||||
|
||||
|
||||
|
||||
<meta name="lang:clipboard.copy" content="Copy to clipboard">
|
||||
|
||||
<meta name="lang:clipboard.copied" content="Copied to clipboard">
|
||||
|
||||
<meta name="lang:search.language" content="en">
|
||||
|
||||
<meta name="lang:search.pipeline.stopwords" content="True">
|
||||
|
||||
<meta name="lang:search.pipeline.trimmer" content="True">
|
||||
|
||||
<meta name="lang:search.result.none" content="No matching documents">
|
||||
|
||||
<meta name="lang:search.result.one" content="1 matching document">
|
||||
|
||||
<meta name="lang:search.result.other" content="# matching documents">
|
||||
|
||||
<meta name="lang:search.tokenizer" content="[\s\-]+">
|
||||
|
||||
<link rel="shortcut icon" href="../assets/images/favicon.png">
|
||||
<meta name="generator" content="mkdocs-1.0.4, mkdocs-material-4.2.0">
|
||||
|
||||
|
||||
|
||||
<title>Read - Yq</title>
|
||||
|
||||
|
||||
|
||||
<link rel="stylesheet" href="../assets/stylesheets/application.750b69bd.css">
|
||||
|
||||
|
||||
|
||||
|
||||
<script src="../assets/javascripts/modernizr.74668098.js"></script>
|
||||
|
||||
|
||||
|
||||
<link href="https://fonts.gstatic.com" rel="preconnect" crossorigin>
|
||||
<link rel="stylesheet" href="https://fonts.googleapis.com/css?family=Roboto:300,400,400i,700|Roboto+Mono">
|
||||
<style>body,input{font-family:"Roboto","Helvetica Neue",Helvetica,Arial,sans-serif}code,kbd,pre{font-family:"Roboto Mono","Courier New",Courier,monospace}</style>
|
||||
|
||||
|
||||
<link rel="stylesheet" href="../assets/fonts/material-icons.css">
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
</head>
|
||||
|
||||
<body dir="ltr">
|
||||
|
||||
<svg class="md-svg">
|
||||
<defs>
|
||||
|
||||
|
||||
<svg xmlns="http://www.w3.org/2000/svg" width="416" height="448"
|
||||
viewBox="0 0 416 448" id="__github">
|
||||
<path fill="currentColor" d="M160 304q0 10-3.125 20.5t-10.75 19-18.125
|
||||
8.5-18.125-8.5-10.75-19-3.125-20.5 3.125-20.5 10.75-19 18.125-8.5
|
||||
18.125 8.5 10.75 19 3.125 20.5zM320 304q0 10-3.125 20.5t-10.75
|
||||
19-18.125 8.5-18.125-8.5-10.75-19-3.125-20.5 3.125-20.5 10.75-19
|
||||
18.125-8.5 18.125 8.5 10.75 19 3.125 20.5zM360
|
||||
304q0-30-17.25-51t-46.75-21q-10.25 0-48.75 5.25-17.75 2.75-39.25
|
||||
2.75t-39.25-2.75q-38-5.25-48.75-5.25-29.5 0-46.75 21t-17.25 51q0 22 8
|
||||
38.375t20.25 25.75 30.5 15 35 7.375 37.25 1.75h42q20.5 0
|
||||
37.25-1.75t35-7.375 30.5-15 20.25-25.75 8-38.375zM416 260q0 51.75-15.25
|
||||
82.75-9.5 19.25-26.375 33.25t-35.25 21.5-42.5 11.875-42.875 5.5-41.75
|
||||
1.125q-19.5 0-35.5-0.75t-36.875-3.125-38.125-7.5-34.25-12.875-30.25-20.25-21.5-28.75q-15.5-30.75-15.5-82.75
|
||||
0-59.25 34-99-6.75-20.5-6.75-42.5 0-29 12.75-54.5 27 0 47.5 9.875t47.25
|
||||
30.875q36.75-8.75 77.25-8.75 37 0 70 8 26.25-20.5
|
||||
46.75-30.25t47.25-9.75q12.75 25.5 12.75 54.5 0 21.75-6.75 42 34 40 34
|
||||
99.5z" />
|
||||
</svg>
|
||||
|
||||
</defs>
|
||||
</svg>
|
||||
<input class="md-toggle" data-md-toggle="drawer" type="checkbox" id="__drawer" autocomplete="off">
|
||||
<input class="md-toggle" data-md-toggle="search" type="checkbox" id="__search" autocomplete="off">
|
||||
<label class="md-overlay" data-md-component="overlay" for="__drawer"></label>
|
||||
|
||||
<a href="#basic" tabindex="1" class="md-skip">
|
||||
Skip to content
|
||||
</a>
|
||||
|
||||
|
||||
<header class="md-header" data-md-component="header">
|
||||
<nav class="md-header-nav md-grid">
|
||||
<div class="md-flex">
|
||||
<div class="md-flex__cell md-flex__cell--shrink">
|
||||
<a href=".." title="Yq" class="md-header-nav__button md-logo">
|
||||
|
||||
<i class="md-icon"></i>
|
||||
|
||||
</a>
|
||||
</div>
|
||||
<div class="md-flex__cell md-flex__cell--shrink">
|
||||
<label class="md-icon md-icon--menu md-header-nav__button" for="__drawer"></label>
|
||||
</div>
|
||||
<div class="md-flex__cell md-flex__cell--stretch">
|
||||
<div class="md-flex__ellipsis md-header-nav__title" data-md-component="title">
|
||||
|
||||
<span class="md-header-nav__topic">
|
||||
Yq
|
||||
</span>
|
||||
<span class="md-header-nav__topic">
|
||||
Read
|
||||
</span>
|
||||
|
||||
</div>
|
||||
</div>
|
||||
<div class="md-flex__cell md-flex__cell--shrink">
|
||||
|
||||
<label class="md-icon md-icon--search md-header-nav__button" for="__search"></label>
|
||||
|
||||
<div class="md-search" data-md-component="search" role="dialog">
|
||||
<label class="md-search__overlay" for="__search"></label>
|
||||
<div class="md-search__inner" role="search">
|
||||
<form class="md-search__form" name="search">
|
||||
<input type="text" class="md-search__input" name="query" placeholder="Search" autocapitalize="off" autocorrect="off" autocomplete="off" spellcheck="false" data-md-component="query" data-md-state="active">
|
||||
<label class="md-icon md-search__icon" for="__search"></label>
|
||||
<button type="reset" class="md-icon md-search__icon" data-md-component="reset" tabindex="-1">
|
||||

|
||||
</button>
|
||||
</form>
|
||||
<div class="md-search__output">
|
||||
<div class="md-search__scrollwrap" data-md-scrollfix>
|
||||
<div class="md-search-result" data-md-component="result">
|
||||
<div class="md-search-result__meta">
|
||||
Type to start searching
|
||||
</div>
|
||||
<ol class="md-search-result__list"></ol>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
</div>
|
||||
|
||||
<div class="md-flex__cell md-flex__cell--shrink">
|
||||
<div class="md-header-nav__source">
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
<a href="https://github.com/mikefarah/yq/" title="Go to repository" class="md-source" data-md-source="github">
|
||||
|
||||
<div class="md-source__icon">
|
||||
<svg viewBox="0 0 24 24" width="24" height="24">
|
||||
<use xlink:href="#__github" width="24" height="24"></use>
|
||||
</svg>
|
||||
</div>
|
||||
|
||||
<div class="md-source__repository">
|
||||
mikefarah/yq
|
||||
</div>
|
||||
</a>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
</div>
|
||||
</nav>
|
||||
</header>
|
||||
|
||||
<div class="md-container">
|
||||
|
||||
|
||||
|
||||
|
||||
<main class="md-main">
|
||||
<div class="md-main__inner md-grid" data-md-component="container">
|
||||
|
||||
|
||||
<div class="md-sidebar md-sidebar--primary" data-md-component="navigation">
|
||||
<div class="md-sidebar__scrollwrap">
|
||||
<div class="md-sidebar__inner">
|
||||
<nav class="md-nav md-nav--primary" data-md-level="0">
|
||||
<label class="md-nav__title md-nav__title--site" for="__drawer">
|
||||
<a href=".." title="Yq" class="md-nav__button md-logo">
|
||||
|
||||
<i class="md-icon"></i>
|
||||
|
||||
</a>
|
||||
Yq
|
||||
</label>
|
||||
|
||||
<div class="md-nav__source">
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
<a href="https://github.com/mikefarah/yq/" title="Go to repository" class="md-source" data-md-source="github">
|
||||
|
||||
<div class="md-source__icon">
|
||||
<svg viewBox="0 0 24 24" width="24" height="24">
|
||||
<use xlink:href="#__github" width="24" height="24"></use>
|
||||
</svg>
|
||||
</div>
|
||||
|
||||
<div class="md-source__repository">
|
||||
mikefarah/yq
|
||||
</div>
|
||||
</a>
|
||||
</div>
|
||||
|
||||
<ul class="md-nav__list" data-md-scrollfix>
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
<li class="md-nav__item">
|
||||
<a href=".." title="Install" class="md-nav__link">
|
||||
Install
|
||||
</a>
|
||||
</li>
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
<li class="md-nav__item md-nav__item--active">
|
||||
|
||||
<input class="md-toggle md-nav__toggle" data-md-toggle="toc" type="checkbox" id="__toc">
|
||||
|
||||
|
||||
<label class="md-nav__link md-nav__link--active" for="__toc">
|
||||
Read
|
||||
</label>
|
||||
|
||||
<a href="./" title="Read" class="md-nav__link md-nav__link--active">
|
||||
Read
|
||||
</a>
|
||||
|
||||
|
||||
<nav class="md-nav md-nav--secondary">
|
||||
|
||||
|
||||
|
||||
<label class="md-nav__title" for="__toc">Table of contents</label>
|
||||
<ul class="md-nav__list" data-md-scrollfix>
|
||||
|
||||
<li class="md-nav__item">
|
||||
<a href="#basic" title="Basic" class="md-nav__link">
|
||||
Basic
|
||||
</a>
|
||||
|
||||
</li>
|
||||
|
||||
<li class="md-nav__item">
|
||||
<a href="#from-stdin" title="From Stdin" class="md-nav__link">
|
||||
From Stdin
|
||||
</a>
|
||||
|
||||
</li>
|
||||
|
||||
<li class="md-nav__item">
|
||||
<a href="#splat" title="Splat" class="md-nav__link">
|
||||
Splat
|
||||
</a>
|
||||
|
||||
</li>
|
||||
|
||||
<li class="md-nav__item">
|
||||
<a href="#prefix-splat" title="Prefix Splat" class="md-nav__link">
|
||||
Prefix Splat
|
||||
</a>
|
||||
|
||||
</li>
|
||||
|
||||
<li class="md-nav__item">
|
||||
<a href="#multiple-documents-specify-a-single-document" title="Multiple Documents - specify a single document" class="md-nav__link">
|
||||
Multiple Documents - specify a single document
|
||||
</a>
|
||||
|
||||
</li>
|
||||
|
||||
<li class="md-nav__item">
|
||||
<a href="#multiple-documents-read-all-documents" title="Multiple Documents - read all documents" class="md-nav__link">
|
||||
Multiple Documents - read all documents
|
||||
</a>
|
||||
|
||||
</li>
|
||||
|
||||
<li class="md-nav__item">
|
||||
<a href="#arrays" title="Arrays" class="md-nav__link">
|
||||
Arrays
|
||||
</a>
|
||||
|
||||
</li>
|
||||
|
||||
<li class="md-nav__item">
|
||||
<a href="#array-splat" title="Array Splat" class="md-nav__link">
|
||||
Array Splat
|
||||
</a>
|
||||
|
||||
</li>
|
||||
|
||||
<li class="md-nav__item">
|
||||
<a href="#keys-with-dots" title="Keys with dots" class="md-nav__link">
|
||||
Keys with dots
|
||||
</a>
|
||||
|
||||
</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>
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
</ul>
|
||||
|
||||
</nav>
|
||||
|
||||
</li>
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
<li class="md-nav__item">
|
||||
<a href="../write/" title="Write/Update" class="md-nav__link">
|
||||
Write/Update
|
||||
</a>
|
||||
</li>
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
<li class="md-nav__item">
|
||||
<a href="../prefix/" title="Prefix" class="md-nav__link">
|
||||
Prefix
|
||||
</a>
|
||||
</li>
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
<li class="md-nav__item">
|
||||
<a href="../delete/" title="Delete" class="md-nav__link">
|
||||
Delete
|
||||
</a>
|
||||
</li>
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
<li class="md-nav__item">
|
||||
<a href="../create/" title="Create" class="md-nav__link">
|
||||
Create
|
||||
</a>
|
||||
</li>
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
<li class="md-nav__item">
|
||||
<a href="../convert/" title="Convert" class="md-nav__link">
|
||||
Convert
|
||||
</a>
|
||||
</li>
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
<li class="md-nav__item">
|
||||
<a href="../merge/" title="Merge" class="md-nav__link">
|
||||
Merge
|
||||
</a>
|
||||
</li>
|
||||
|
||||
|
||||
</ul>
|
||||
</nav>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
|
||||
<div class="md-sidebar md-sidebar--secondary" data-md-component="toc">
|
||||
<div class="md-sidebar__scrollwrap">
|
||||
<div class="md-sidebar__inner">
|
||||
|
||||
<nav class="md-nav md-nav--secondary">
|
||||
|
||||
|
||||
|
||||
<label class="md-nav__title" for="__toc">Table of contents</label>
|
||||
<ul class="md-nav__list" data-md-scrollfix>
|
||||
|
||||
<li class="md-nav__item">
|
||||
<a href="#basic" title="Basic" class="md-nav__link">
|
||||
Basic
|
||||
</a>
|
||||
|
||||
</li>
|
||||
|
||||
<li class="md-nav__item">
|
||||
<a href="#from-stdin" title="From Stdin" class="md-nav__link">
|
||||
From Stdin
|
||||
</a>
|
||||
|
||||
</li>
|
||||
|
||||
<li class="md-nav__item">
|
||||
<a href="#splat" title="Splat" class="md-nav__link">
|
||||
Splat
|
||||
</a>
|
||||
|
||||
</li>
|
||||
|
||||
<li class="md-nav__item">
|
||||
<a href="#prefix-splat" title="Prefix Splat" class="md-nav__link">
|
||||
Prefix Splat
|
||||
</a>
|
||||
|
||||
</li>
|
||||
|
||||
<li class="md-nav__item">
|
||||
<a href="#multiple-documents-specify-a-single-document" title="Multiple Documents - specify a single document" class="md-nav__link">
|
||||
Multiple Documents - specify a single document
|
||||
</a>
|
||||
|
||||
</li>
|
||||
|
||||
<li class="md-nav__item">
|
||||
<a href="#multiple-documents-read-all-documents" title="Multiple Documents - read all documents" class="md-nav__link">
|
||||
Multiple Documents - read all documents
|
||||
</a>
|
||||
|
||||
</li>
|
||||
|
||||
<li class="md-nav__item">
|
||||
<a href="#arrays" title="Arrays" class="md-nav__link">
|
||||
Arrays
|
||||
</a>
|
||||
|
||||
</li>
|
||||
|
||||
<li class="md-nav__item">
|
||||
<a href="#array-splat" title="Array Splat" class="md-nav__link">
|
||||
Array Splat
|
||||
</a>
|
||||
|
||||
</li>
|
||||
|
||||
<li class="md-nav__item">
|
||||
<a href="#keys-with-dots" title="Keys with dots" class="md-nav__link">
|
||||
Keys with dots
|
||||
</a>
|
||||
|
||||
</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>
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
</ul>
|
||||
|
||||
</nav>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
|
||||
<div class="md-content">
|
||||
<article class="md-content__inner md-typeset">
|
||||
|
||||
|
||||
<a href="https://github.com/mikefarah/yq/edit/master/docs/read.md" title="Edit this page" class="md-icon md-content__icon"></a>
|
||||
|
||||
|
||||
<h1>Read</h1>
|
||||
|
||||
<pre><code>yq r <yaml_file|json_file> <path>
|
||||
</code></pre>
|
||||
|
||||
<p>This command can take a json file as input too, and will output yaml unless specified to export as json (-j)</p>
|
||||
<h3 id="basic">Basic<a class="headerlink" href="#basic" title="Permanent link">¶</a></h3>
|
||||
<p>Given a sample.yaml file of:</p>
|
||||
<pre><code class="yaml">b:
|
||||
c: 2
|
||||
</code></pre>
|
||||
|
||||
<p>then</p>
|
||||
<pre><code class="bash">yq r sample.yaml b.c
|
||||
</code></pre>
|
||||
|
||||
<p>will output the value of '2'.</p>
|
||||
<h3 id="from-stdin">From Stdin<a class="headerlink" href="#from-stdin" title="Permanent link">¶</a></h3>
|
||||
<p>Given a sample.yaml file of:</p>
|
||||
<pre><code class="bash">cat sample.yaml | yq r - b.c
|
||||
</code></pre>
|
||||
|
||||
<p>will output the value of '2'.</p>
|
||||
<h3 id="splat">Splat<a class="headerlink" href="#splat" title="Permanent link">¶</a></h3>
|
||||
<p>Given a sample.yaml file of:</p>
|
||||
<pre><code class="yaml">---
|
||||
bob:
|
||||
item1:
|
||||
cats: bananas
|
||||
item2:
|
||||
cats: apples
|
||||
thing:
|
||||
cats: oranges
|
||||
</code></pre>
|
||||
|
||||
<p>then</p>
|
||||
<pre><code class="bash">yq r sample.yaml bob.*.cats
|
||||
</code></pre>
|
||||
|
||||
<p>will output</p>
|
||||
<pre><code class="yaml">- bananas
|
||||
- apples
|
||||
- oranges
|
||||
</code></pre>
|
||||
|
||||
<h3 id="prefix-splat">Prefix Splat<a class="headerlink" href="#prefix-splat" title="Permanent link">¶</a></h3>
|
||||
<p>Given a sample.yaml file of:</p>
|
||||
<pre><code class="yaml">---
|
||||
bob:
|
||||
item1:
|
||||
cats: bananas
|
||||
item2:
|
||||
cats: apples
|
||||
thing:
|
||||
cats: oranges
|
||||
</code></pre>
|
||||
|
||||
<p>then</p>
|
||||
<pre><code class="bash">yq r sample.yaml bob.item*.cats
|
||||
</code></pre>
|
||||
|
||||
<p>will output</p>
|
||||
<pre><code class="yaml">- bananas
|
||||
- apples
|
||||
</code></pre>
|
||||
|
||||
<h3 id="multiple-documents-specify-a-single-document">Multiple Documents - specify a single document<a class="headerlink" href="#multiple-documents-specify-a-single-document" title="Permanent link">¶</a></h3>
|
||||
<p>Given a sample.yaml file of:</p>
|
||||
<pre><code class="yaml">something: else
|
||||
---
|
||||
b:
|
||||
c: 2
|
||||
</code></pre>
|
||||
|
||||
<p>then</p>
|
||||
<pre><code class="bash">yq r -d1 sample.yaml b.c
|
||||
</code></pre>
|
||||
|
||||
<p>will output the value of '2'.</p>
|
||||
<h3 id="multiple-documents-read-all-documents">Multiple Documents - read all documents<a class="headerlink" href="#multiple-documents-read-all-documents" title="Permanent link">¶</a></h3>
|
||||
<p>Reading all documents will return the result as an array. This can be converted to json using the '-j' flag if desired.</p>
|
||||
<p>Given a sample.yaml file of:</p>
|
||||
<pre><code class="yaml">name: Fred
|
||||
age: 22
|
||||
---
|
||||
name: Stella
|
||||
age: 23
|
||||
---
|
||||
name: Android
|
||||
age: 232
|
||||
</code></pre>
|
||||
|
||||
<p>then</p>
|
||||
<pre><code class="bash">yq r -d'*' sample.yaml name
|
||||
</code></pre>
|
||||
|
||||
<p>will output:</p>
|
||||
<pre><code>- Fred
|
||||
- Stella
|
||||
- Android
|
||||
</code></pre>
|
||||
|
||||
<h3 id="arrays">Arrays<a class="headerlink" href="#arrays" title="Permanent link">¶</a></h3>
|
||||
<p>You can give an index to access a specific element:
|
||||
e.g.: given a sample file of</p>
|
||||
<pre><code class="yaml">b:
|
||||
e:
|
||||
- name: fred
|
||||
value: 3
|
||||
- name: sam
|
||||
value: 4
|
||||
</code></pre>
|
||||
|
||||
<p>then</p>
|
||||
<pre><code>yq r sample.yaml 'b.e[1].name'
|
||||
</code></pre>
|
||||
|
||||
<p>will output 'sam'</p>
|
||||
<p>Note that the path is in quotes to avoid the square brackets being interpreted by your shell.</p>
|
||||
<h3 id="array-splat">Array Splat<a class="headerlink" href="#array-splat" title="Permanent link">¶</a></h3>
|
||||
<p>e.g.: given a sample file of</p>
|
||||
<pre><code class="yaml">b:
|
||||
e:
|
||||
- name: fred
|
||||
value: 3
|
||||
- name: sam
|
||||
value: 4
|
||||
</code></pre>
|
||||
|
||||
<p>then</p>
|
||||
<pre><code>yq r sample.yaml 'b.e[*].name'
|
||||
</code></pre>
|
||||
|
||||
<p>will output:</p>
|
||||
<pre><code>- fred
|
||||
- sam
|
||||
</code></pre>
|
||||
|
||||
<p>Note that the path is in quotes to avoid the square brackets being interpreted by your shell.</p>
|
||||
<h3 id="keys-with-dots">Keys with dots<a class="headerlink" href="#keys-with-dots" title="Permanent link">¶</a></h3>
|
||||
<p>When specifying a key that has a dot use key lookup indicator.</p>
|
||||
<pre><code class="yaml">b:
|
||||
foo.bar: 7
|
||||
</code></pre>
|
||||
|
||||
<pre><code class="bash">yaml r sample.yaml 'b[foo.bar]'
|
||||
</code></pre>
|
||||
|
||||
<pre><code class="bash">yaml w sample.yaml 'b[foo.bar]' 9
|
||||
</code></pre>
|
||||
|
||||
<p>Any valid yaml key can be specified as part of a key lookup.</p>
|
||||
<p>Note that the path is in quotes to avoid the square brackets being interpreted by your shell.</p>
|
||||
<h3 id="keys-and-values-with-leading-dashes">Keys (and values) with leading dashes<a class="headerlink" href="#keys-and-values-with-leading-dashes" title="Permanent link">¶</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>
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
</article>
|
||||
</div>
|
||||
</div>
|
||||
</main>
|
||||
|
||||
|
||||
<footer class="md-footer">
|
||||
|
||||
<div class="md-footer-nav">
|
||||
<nav class="md-footer-nav__inner md-grid">
|
||||
|
||||
<a href=".." title="Install" class="md-flex md-footer-nav__link md-footer-nav__link--prev" rel="prev">
|
||||
<div class="md-flex__cell md-flex__cell--shrink">
|
||||
<i class="md-icon md-icon--arrow-back md-footer-nav__button"></i>
|
||||
</div>
|
||||
<div class="md-flex__cell md-flex__cell--stretch md-footer-nav__title">
|
||||
<span class="md-flex__ellipsis">
|
||||
<span class="md-footer-nav__direction">
|
||||
Previous
|
||||
</span>
|
||||
Install
|
||||
</span>
|
||||
</div>
|
||||
</a>
|
||||
|
||||
|
||||
<a href="../write/" title="Write/Update" class="md-flex md-footer-nav__link md-footer-nav__link--next" rel="next">
|
||||
<div class="md-flex__cell md-flex__cell--stretch md-footer-nav__title">
|
||||
<span class="md-flex__ellipsis">
|
||||
<span class="md-footer-nav__direction">
|
||||
Next
|
||||
</span>
|
||||
Write/Update
|
||||
</span>
|
||||
</div>
|
||||
<div class="md-flex__cell md-flex__cell--shrink">
|
||||
<i class="md-icon md-icon--arrow-forward md-footer-nav__button"></i>
|
||||
</div>
|
||||
</a>
|
||||
|
||||
</nav>
|
||||
</div>
|
||||
|
||||
<div class="md-footer-meta md-typeset">
|
||||
<div class="md-footer-meta__inner md-grid">
|
||||
<div class="md-footer-copyright">
|
||||
|
||||
powered by
|
||||
<a href="https://www.mkdocs.org">MkDocs</a>
|
||||
and
|
||||
<a href="https://squidfunk.github.io/mkdocs-material/">
|
||||
Material for MkDocs</a>
|
||||
</div>
|
||||
|
||||
<div class="md-footer-social">
|
||||
<link rel="stylesheet" href="../assets/fonts/font-awesome.css">
|
||||
|
||||
<a href="https://github.com/mikefarah" class="md-footer-social__link fa fa-github"></a>
|
||||
|
||||
<a href="https://www.linkedin.com/in/mike-farah-b5a75b2/" class="md-footer-social__link fa fa-linkedin"></a>
|
||||
|
||||
</div>
|
||||
|
||||
</div>
|
||||
</div>
|
||||
</footer>
|
||||
|
||||
</div>
|
||||
|
||||
<script src="../assets/javascripts/application.39abc4af.js"></script>
|
||||
|
||||
<script>app.initialize({version:"1.0.4",url:{base:".."}})</script>
|
||||
|
||||
|
||||
</body>
|
||||
</html>
|
File diff suppressed because one or more lines are too long
@ -2,42 +2,7 @@
|
||||
<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">
|
||||
<url>
|
||||
<loc>None</loc>
|
||||
<lastmod>2019-05-16</lastmod>
|
||||
<changefreq>daily</changefreq>
|
||||
</url>
|
||||
<url>
|
||||
<loc>None</loc>
|
||||
<lastmod>2019-05-16</lastmod>
|
||||
<changefreq>daily</changefreq>
|
||||
</url>
|
||||
<url>
|
||||
<loc>None</loc>
|
||||
<lastmod>2019-05-16</lastmod>
|
||||
<changefreq>daily</changefreq>
|
||||
</url>
|
||||
<url>
|
||||
<loc>None</loc>
|
||||
<lastmod>2019-05-16</lastmod>
|
||||
<changefreq>daily</changefreq>
|
||||
</url>
|
||||
<url>
|
||||
<loc>None</loc>
|
||||
<lastmod>2019-05-16</lastmod>
|
||||
<changefreq>daily</changefreq>
|
||||
</url>
|
||||
<url>
|
||||
<loc>None</loc>
|
||||
<lastmod>2019-05-16</lastmod>
|
||||
<changefreq>daily</changefreq>
|
||||
</url>
|
||||
<url>
|
||||
<loc>None</loc>
|
||||
<lastmod>2019-05-16</lastmod>
|
||||
<changefreq>daily</changefreq>
|
||||
</url>
|
||||
<url>
|
||||
<loc>None</loc>
|
||||
<lastmod>2019-05-16</lastmod>
|
||||
<lastmod>2020-01-30</lastmod>
|
||||
<changefreq>daily</changefreq>
|
||||
</url>
|
||||
</urlset>
|
Binary file not shown.
@ -1,447 +0,0 @@
|
||||
|
||||
|
||||
|
||||
|
||||
<!doctype html>
|
||||
<html lang="en" class="no-js">
|
||||
<head>
|
||||
|
||||
<meta charset="utf-8">
|
||||
<meta name="viewport" content="width=device-width,initial-scale=1">
|
||||
<meta http-equiv="x-ua-compatible" content="ie=edge">
|
||||
|
||||
|
||||
|
||||
|
||||
<meta name="lang:clipboard.copy" content="Copy to clipboard">
|
||||
|
||||
<meta name="lang:clipboard.copied" content="Copied to clipboard">
|
||||
|
||||
<meta name="lang:search.language" content="en">
|
||||
|
||||
<meta name="lang:search.pipeline.stopwords" content="True">
|
||||
|
||||
<meta name="lang:search.pipeline.trimmer" content="True">
|
||||
|
||||
<meta name="lang:search.result.none" content="No matching documents">
|
||||
|
||||
<meta name="lang:search.result.one" content="1 matching document">
|
||||
|
||||
<meta name="lang:search.result.other" content="# matching documents">
|
||||
|
||||
<meta name="lang:search.tokenizer" content="[\s\-]+">
|
||||
|
||||
<link rel="shortcut icon" href="../../assets/images/favicon.png">
|
||||
<meta name="generator" content="mkdocs-1.0.4, mkdocs-material-4.2.0">
|
||||
|
||||
|
||||
|
||||
<title>Niche - Yq</title>
|
||||
|
||||
|
||||
|
||||
<link rel="stylesheet" href="../../assets/stylesheets/application.750b69bd.css">
|
||||
|
||||
|
||||
|
||||
|
||||
<script src="../../assets/javascripts/modernizr.74668098.js"></script>
|
||||
|
||||
|
||||
|
||||
<link href="https://fonts.gstatic.com" rel="preconnect" crossorigin>
|
||||
<link rel="stylesheet" href="https://fonts.googleapis.com/css?family=Roboto:300,400,400i,700|Roboto+Mono">
|
||||
<style>body,input{font-family:"Roboto","Helvetica Neue",Helvetica,Arial,sans-serif}code,kbd,pre{font-family:"Roboto Mono","Courier New",Courier,monospace}</style>
|
||||
|
||||
|
||||
<link rel="stylesheet" href="../../assets/fonts/material-icons.css">
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
</head>
|
||||
|
||||
<body dir="ltr">
|
||||
|
||||
<svg class="md-svg">
|
||||
<defs>
|
||||
|
||||
|
||||
<svg xmlns="http://www.w3.org/2000/svg" width="416" height="448"
|
||||
viewBox="0 0 416 448" id="__github">
|
||||
<path fill="currentColor" d="M160 304q0 10-3.125 20.5t-10.75 19-18.125
|
||||
8.5-18.125-8.5-10.75-19-3.125-20.5 3.125-20.5 10.75-19 18.125-8.5
|
||||
18.125 8.5 10.75 19 3.125 20.5zM320 304q0 10-3.125 20.5t-10.75
|
||||
19-18.125 8.5-18.125-8.5-10.75-19-3.125-20.5 3.125-20.5 10.75-19
|
||||
18.125-8.5 18.125 8.5 10.75 19 3.125 20.5zM360
|
||||
304q0-30-17.25-51t-46.75-21q-10.25 0-48.75 5.25-17.75 2.75-39.25
|
||||
2.75t-39.25-2.75q-38-5.25-48.75-5.25-29.5 0-46.75 21t-17.25 51q0 22 8
|
||||
38.375t20.25 25.75 30.5 15 35 7.375 37.25 1.75h42q20.5 0
|
||||
37.25-1.75t35-7.375 30.5-15 20.25-25.75 8-38.375zM416 260q0 51.75-15.25
|
||||
82.75-9.5 19.25-26.375 33.25t-35.25 21.5-42.5 11.875-42.875 5.5-41.75
|
||||
1.125q-19.5 0-35.5-0.75t-36.875-3.125-38.125-7.5-34.25-12.875-30.25-20.25-21.5-28.75q-15.5-30.75-15.5-82.75
|
||||
0-59.25 34-99-6.75-20.5-6.75-42.5 0-29 12.75-54.5 27 0 47.5 9.875t47.25
|
||||
30.875q36.75-8.75 77.25-8.75 37 0 70 8 26.25-20.5
|
||||
46.75-30.25t47.25-9.75q12.75 25.5 12.75 54.5 0 21.75-6.75 42 34 40 34
|
||||
99.5z" />
|
||||
</svg>
|
||||
|
||||
</defs>
|
||||
</svg>
|
||||
<input class="md-toggle" data-md-toggle="drawer" type="checkbox" id="__drawer" autocomplete="off">
|
||||
<input class="md-toggle" data-md-toggle="search" type="checkbox" id="__search" autocomplete="off">
|
||||
<label class="md-overlay" data-md-component="overlay" for="__drawer"></label>
|
||||
|
||||
<a href="#keys-with-dots" tabindex="1" class="md-skip">
|
||||
Skip to content
|
||||
</a>
|
||||
|
||||
|
||||
<header class="md-header" data-md-component="header">
|
||||
<nav class="md-header-nav md-grid">
|
||||
<div class="md-flex">
|
||||
<div class="md-flex__cell md-flex__cell--shrink">
|
||||
<a href="../.." title="Yq" class="md-header-nav__button md-logo">
|
||||
|
||||
<i class="md-icon"></i>
|
||||
|
||||
</a>
|
||||
</div>
|
||||
<div class="md-flex__cell md-flex__cell--shrink">
|
||||
<label class="md-icon md-icon--menu md-header-nav__button" for="__drawer"></label>
|
||||
</div>
|
||||
<div class="md-flex__cell md-flex__cell--stretch">
|
||||
<div class="md-flex__ellipsis md-header-nav__title" data-md-component="title">
|
||||
|
||||
<span class="md-header-nav__topic">
|
||||
Yq
|
||||
</span>
|
||||
<span class="md-header-nav__topic">
|
||||
Niche
|
||||
</span>
|
||||
|
||||
</div>
|
||||
</div>
|
||||
<div class="md-flex__cell md-flex__cell--shrink">
|
||||
|
||||
<label class="md-icon md-icon--search md-header-nav__button" for="__search"></label>
|
||||
|
||||
<div class="md-search" data-md-component="search" role="dialog">
|
||||
<label class="md-search__overlay" for="__search"></label>
|
||||
<div class="md-search__inner" role="search">
|
||||
<form class="md-search__form" name="search">
|
||||
<input type="text" class="md-search__input" name="query" placeholder="Search" autocapitalize="off" autocorrect="off" autocomplete="off" spellcheck="false" data-md-component="query" data-md-state="active">
|
||||
<label class="md-icon md-search__icon" for="__search"></label>
|
||||
<button type="reset" class="md-icon md-search__icon" data-md-component="reset" tabindex="-1">
|
||||

|
||||
</button>
|
||||
</form>
|
||||
<div class="md-search__output">
|
||||
<div class="md-search__scrollwrap" data-md-scrollfix>
|
||||
<div class="md-search-result" data-md-component="result">
|
||||
<div class="md-search-result__meta">
|
||||
Type to start searching
|
||||
</div>
|
||||
<ol class="md-search-result__list"></ol>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
</div>
|
||||
|
||||
<div class="md-flex__cell md-flex__cell--shrink">
|
||||
<div class="md-header-nav__source">
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
<a href="https://github.com/mikefarah/yq/" title="Go to repository" class="md-source" data-md-source="github">
|
||||
|
||||
<div class="md-source__icon">
|
||||
<svg viewBox="0 0 24 24" width="24" height="24">
|
||||
<use xlink:href="#__github" width="24" height="24"></use>
|
||||
</svg>
|
||||
</div>
|
||||
|
||||
<div class="md-source__repository">
|
||||
mikefarah/yq
|
||||
</div>
|
||||
</a>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
</div>
|
||||
</nav>
|
||||
</header>
|
||||
|
||||
<div class="md-container">
|
||||
|
||||
|
||||
|
||||
|
||||
<main class="md-main">
|
||||
<div class="md-main__inner md-grid" data-md-component="container">
|
||||
|
||||
|
||||
<div class="md-sidebar md-sidebar--primary" data-md-component="navigation">
|
||||
<div class="md-sidebar__scrollwrap">
|
||||
<div class="md-sidebar__inner">
|
||||
<nav class="md-nav md-nav--primary" data-md-level="0">
|
||||
<label class="md-nav__title md-nav__title--site" for="__drawer">
|
||||
<a href="../.." title="Yq" class="md-nav__button md-logo">
|
||||
|
||||
<i class="md-icon"></i>
|
||||
|
||||
</a>
|
||||
Yq
|
||||
</label>
|
||||
|
||||
<div class="md-nav__source">
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
<a href="https://github.com/mikefarah/yq/" title="Go to repository" class="md-source" data-md-source="github">
|
||||
|
||||
<div class="md-source__icon">
|
||||
<svg viewBox="0 0 24 24" width="24" height="24">
|
||||
<use xlink:href="#__github" width="24" height="24"></use>
|
||||
</svg>
|
||||
</div>
|
||||
|
||||
<div class="md-source__repository">
|
||||
mikefarah/yq
|
||||
</div>
|
||||
</a>
|
||||
</div>
|
||||
|
||||
<ul class="md-nav__list" data-md-scrollfix>
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
<li class="md-nav__item">
|
||||
<a href="../.." title="Install" class="md-nav__link">
|
||||
Install
|
||||
</a>
|
||||
</li>
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
<li class="md-nav__item">
|
||||
<a href="../../read/" title="Read" class="md-nav__link">
|
||||
Read
|
||||
</a>
|
||||
</li>
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
<li class="md-nav__item">
|
||||
<a href="../../write/" title="Write/Update" class="md-nav__link">
|
||||
Write/Update
|
||||
</a>
|
||||
</li>
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
<li class="md-nav__item">
|
||||
<a href="../../prefix/" title="Prefix" class="md-nav__link">
|
||||
Prefix
|
||||
</a>
|
||||
</li>
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
<li class="md-nav__item">
|
||||
<a href="../../delete/" title="Delete" class="md-nav__link">
|
||||
Delete
|
||||
</a>
|
||||
</li>
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
<li class="md-nav__item">
|
||||
<a href="../../create/" title="Create" class="md-nav__link">
|
||||
Create
|
||||
</a>
|
||||
</li>
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
<li class="md-nav__item">
|
||||
<a href="../../convert/" title="Convert" class="md-nav__link">
|
||||
Convert
|
||||
</a>
|
||||
</li>
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
<li class="md-nav__item">
|
||||
<a href="../../merge/" title="Merge" class="md-nav__link">
|
||||
Merge
|
||||
</a>
|
||||
</li>
|
||||
|
||||
|
||||
</ul>
|
||||
</nav>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
|
||||
<div class="md-sidebar md-sidebar--secondary" data-md-component="toc">
|
||||
<div class="md-sidebar__scrollwrap">
|
||||
<div class="md-sidebar__inner">
|
||||
|
||||
<nav class="md-nav md-nav--secondary">
|
||||
|
||||
|
||||
|
||||
<label class="md-nav__title" for="__toc">Table of contents</label>
|
||||
<ul class="md-nav__list" data-md-scrollfix>
|
||||
|
||||
<li class="md-nav__item">
|
||||
<a href="#keys-with-dots" title="Keys with dots" class="md-nav__link">
|
||||
Keys with dots
|
||||
</a>
|
||||
|
||||
</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>
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
</ul>
|
||||
|
||||
</nav>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
|
||||
<div class="md-content">
|
||||
<article class="md-content__inner md-typeset">
|
||||
|
||||
|
||||
<a href="https://github.com/mikefarah/yq/edit/master/docs/snippets/niche.md" title="Edit this page" class="md-icon md-content__icon"></a>
|
||||
|
||||
|
||||
<h1>Niche</h1>
|
||||
|
||||
<h3 id="keys-with-dots">Keys with dots<a class="headerlink" href="#keys-with-dots" title="Permanent link">¶</a></h3>
|
||||
<p>When specifying a key that has a dot use key lookup indicator.</p>
|
||||
<pre><code class="yaml">b:
|
||||
foo.bar: 7
|
||||
</code></pre>
|
||||
|
||||
<pre><code class="bash">yaml r sample.yaml 'b[foo.bar]'
|
||||
</code></pre>
|
||||
|
||||
<pre><code class="bash">yaml w sample.yaml 'b[foo.bar]' 9
|
||||
</code></pre>
|
||||
|
||||
<p>Any valid yaml key can be specified as part of a key lookup.</p>
|
||||
<p>Note that the path is in quotes to avoid the square brackets being interpreted by your shell.</p>
|
||||
<h3 id="keys-and-values-with-leading-dashes">Keys (and values) with leading dashes<a class="headerlink" href="#keys-and-values-with-leading-dashes" title="Permanent link">¶</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>
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
</article>
|
||||
</div>
|
||||
</div>
|
||||
</main>
|
||||
|
||||
|
||||
<footer class="md-footer">
|
||||
|
||||
<div class="md-footer-meta md-typeset">
|
||||
<div class="md-footer-meta__inner md-grid">
|
||||
<div class="md-footer-copyright">
|
||||
|
||||
powered by
|
||||
<a href="https://www.mkdocs.org">MkDocs</a>
|
||||
and
|
||||
<a href="https://squidfunk.github.io/mkdocs-material/">
|
||||
Material for MkDocs</a>
|
||||
</div>
|
||||
|
||||
<div class="md-footer-social">
|
||||
<link rel="stylesheet" href="../../assets/fonts/font-awesome.css">
|
||||
|
||||
<a href="https://github.com/mikefarah" class="md-footer-social__link fa fa-github"></a>
|
||||
|
||||
<a href="https://www.linkedin.com/in/mike-farah-b5a75b2/" class="md-footer-social__link fa fa-linkedin"></a>
|
||||
|
||||
</div>
|
||||
|
||||
</div>
|
||||
</div>
|
||||
</footer>
|
||||
|
||||
</div>
|
||||
|
||||
<script src="../../assets/javascripts/application.39abc4af.js"></script>
|
||||
|
||||
<script>app.initialize({version:"1.0.4",url:{base:"../.."}})</script>
|
||||
|
||||
|
||||
</body>
|
||||
</html>
|
@ -1,385 +0,0 @@
|
||||
|
||||
|
||||
|
||||
|
||||
<!doctype html>
|
||||
<html lang="en" class="no-js">
|
||||
<head>
|
||||
|
||||
<meta charset="utf-8">
|
||||
<meta name="viewport" content="width=device-width,initial-scale=1">
|
||||
<meta http-equiv="x-ua-compatible" content="ie=edge">
|
||||
|
||||
|
||||
|
||||
|
||||
<meta name="lang:clipboard.copy" content="Copy to clipboard">
|
||||
|
||||
<meta name="lang:clipboard.copied" content="Copied to clipboard">
|
||||
|
||||
<meta name="lang:search.language" content="en">
|
||||
|
||||
<meta name="lang:search.pipeline.stopwords" content="True">
|
||||
|
||||
<meta name="lang:search.pipeline.trimmer" content="True">
|
||||
|
||||
<meta name="lang:search.result.none" content="No matching documents">
|
||||
|
||||
<meta name="lang:search.result.one" content="1 matching document">
|
||||
|
||||
<meta name="lang:search.result.other" content="# matching documents">
|
||||
|
||||
<meta name="lang:search.tokenizer" content="[\s\-]+">
|
||||
|
||||
<link rel="shortcut icon" href="../../assets/images/favicon.png">
|
||||
<meta name="generator" content="mkdocs-1.0.4, mkdocs-material-4.2.0">
|
||||
|
||||
|
||||
|
||||
<title>Works with json - Yq</title>
|
||||
|
||||
|
||||
|
||||
<link rel="stylesheet" href="../../assets/stylesheets/application.750b69bd.css">
|
||||
|
||||
|
||||
|
||||
|
||||
<script src="../../assets/javascripts/modernizr.74668098.js"></script>
|
||||
|
||||
|
||||
|
||||
<link href="https://fonts.gstatic.com" rel="preconnect" crossorigin>
|
||||
<link rel="stylesheet" href="https://fonts.googleapis.com/css?family=Roboto:300,400,400i,700|Roboto+Mono">
|
||||
<style>body,input{font-family:"Roboto","Helvetica Neue",Helvetica,Arial,sans-serif}code,kbd,pre{font-family:"Roboto Mono","Courier New",Courier,monospace}</style>
|
||||
|
||||
|
||||
<link rel="stylesheet" href="../../assets/fonts/material-icons.css">
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
</head>
|
||||
|
||||
<body dir="ltr">
|
||||
|
||||
<svg class="md-svg">
|
||||
<defs>
|
||||
|
||||
|
||||
<svg xmlns="http://www.w3.org/2000/svg" width="416" height="448"
|
||||
viewBox="0 0 416 448" id="__github">
|
||||
<path fill="currentColor" d="M160 304q0 10-3.125 20.5t-10.75 19-18.125
|
||||
8.5-18.125-8.5-10.75-19-3.125-20.5 3.125-20.5 10.75-19 18.125-8.5
|
||||
18.125 8.5 10.75 19 3.125 20.5zM320 304q0 10-3.125 20.5t-10.75
|
||||
19-18.125 8.5-18.125-8.5-10.75-19-3.125-20.5 3.125-20.5 10.75-19
|
||||
18.125-8.5 18.125 8.5 10.75 19 3.125 20.5zM360
|
||||
304q0-30-17.25-51t-46.75-21q-10.25 0-48.75 5.25-17.75 2.75-39.25
|
||||
2.75t-39.25-2.75q-38-5.25-48.75-5.25-29.5 0-46.75 21t-17.25 51q0 22 8
|
||||
38.375t20.25 25.75 30.5 15 35 7.375 37.25 1.75h42q20.5 0
|
||||
37.25-1.75t35-7.375 30.5-15 20.25-25.75 8-38.375zM416 260q0 51.75-15.25
|
||||
82.75-9.5 19.25-26.375 33.25t-35.25 21.5-42.5 11.875-42.875 5.5-41.75
|
||||
1.125q-19.5 0-35.5-0.75t-36.875-3.125-38.125-7.5-34.25-12.875-30.25-20.25-21.5-28.75q-15.5-30.75-15.5-82.75
|
||||
0-59.25 34-99-6.75-20.5-6.75-42.5 0-29 12.75-54.5 27 0 47.5 9.875t47.25
|
||||
30.875q36.75-8.75 77.25-8.75 37 0 70 8 26.25-20.5
|
||||
46.75-30.25t47.25-9.75q12.75 25.5 12.75 54.5 0 21.75-6.75 42 34 40 34
|
||||
99.5z" />
|
||||
</svg>
|
||||
|
||||
</defs>
|
||||
</svg>
|
||||
<input class="md-toggle" data-md-toggle="drawer" type="checkbox" id="__drawer" autocomplete="off">
|
||||
<input class="md-toggle" data-md-toggle="search" type="checkbox" id="__search" autocomplete="off">
|
||||
<label class="md-overlay" data-md-component="overlay" for="__drawer"></label>
|
||||
|
||||
|
||||
<header class="md-header" data-md-component="header">
|
||||
<nav class="md-header-nav md-grid">
|
||||
<div class="md-flex">
|
||||
<div class="md-flex__cell md-flex__cell--shrink">
|
||||
<a href="../.." title="Yq" class="md-header-nav__button md-logo">
|
||||
|
||||
<i class="md-icon"></i>
|
||||
|
||||
</a>
|
||||
</div>
|
||||
<div class="md-flex__cell md-flex__cell--shrink">
|
||||
<label class="md-icon md-icon--menu md-header-nav__button" for="__drawer"></label>
|
||||
</div>
|
||||
<div class="md-flex__cell md-flex__cell--stretch">
|
||||
<div class="md-flex__ellipsis md-header-nav__title" data-md-component="title">
|
||||
|
||||
<span class="md-header-nav__topic">
|
||||
Yq
|
||||
</span>
|
||||
<span class="md-header-nav__topic">
|
||||
Works with json
|
||||
</span>
|
||||
|
||||
</div>
|
||||
</div>
|
||||
<div class="md-flex__cell md-flex__cell--shrink">
|
||||
|
||||
<label class="md-icon md-icon--search md-header-nav__button" for="__search"></label>
|
||||
|
||||
<div class="md-search" data-md-component="search" role="dialog">
|
||||
<label class="md-search__overlay" for="__search"></label>
|
||||
<div class="md-search__inner" role="search">
|
||||
<form class="md-search__form" name="search">
|
||||
<input type="text" class="md-search__input" name="query" placeholder="Search" autocapitalize="off" autocorrect="off" autocomplete="off" spellcheck="false" data-md-component="query" data-md-state="active">
|
||||
<label class="md-icon md-search__icon" for="__search"></label>
|
||||
<button type="reset" class="md-icon md-search__icon" data-md-component="reset" tabindex="-1">
|
||||

|
||||
</button>
|
||||
</form>
|
||||
<div class="md-search__output">
|
||||
<div class="md-search__scrollwrap" data-md-scrollfix>
|
||||
<div class="md-search-result" data-md-component="result">
|
||||
<div class="md-search-result__meta">
|
||||
Type to start searching
|
||||
</div>
|
||||
<ol class="md-search-result__list"></ol>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
</div>
|
||||
|
||||
<div class="md-flex__cell md-flex__cell--shrink">
|
||||
<div class="md-header-nav__source">
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
<a href="https://github.com/mikefarah/yq/" title="Go to repository" class="md-source" data-md-source="github">
|
||||
|
||||
<div class="md-source__icon">
|
||||
<svg viewBox="0 0 24 24" width="24" height="24">
|
||||
<use xlink:href="#__github" width="24" height="24"></use>
|
||||
</svg>
|
||||
</div>
|
||||
|
||||
<div class="md-source__repository">
|
||||
mikefarah/yq
|
||||
</div>
|
||||
</a>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
</div>
|
||||
</nav>
|
||||
</header>
|
||||
|
||||
<div class="md-container">
|
||||
|
||||
|
||||
|
||||
|
||||
<main class="md-main">
|
||||
<div class="md-main__inner md-grid" data-md-component="container">
|
||||
|
||||
|
||||
<div class="md-sidebar md-sidebar--primary" data-md-component="navigation">
|
||||
<div class="md-sidebar__scrollwrap">
|
||||
<div class="md-sidebar__inner">
|
||||
<nav class="md-nav md-nav--primary" data-md-level="0">
|
||||
<label class="md-nav__title md-nav__title--site" for="__drawer">
|
||||
<a href="../.." title="Yq" class="md-nav__button md-logo">
|
||||
|
||||
<i class="md-icon"></i>
|
||||
|
||||
</a>
|
||||
Yq
|
||||
</label>
|
||||
|
||||
<div class="md-nav__source">
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
<a href="https://github.com/mikefarah/yq/" title="Go to repository" class="md-source" data-md-source="github">
|
||||
|
||||
<div class="md-source__icon">
|
||||
<svg viewBox="0 0 24 24" width="24" height="24">
|
||||
<use xlink:href="#__github" width="24" height="24"></use>
|
||||
</svg>
|
||||
</div>
|
||||
|
||||
<div class="md-source__repository">
|
||||
mikefarah/yq
|
||||
</div>
|
||||
</a>
|
||||
</div>
|
||||
|
||||
<ul class="md-nav__list" data-md-scrollfix>
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
<li class="md-nav__item">
|
||||
<a href="../.." title="Install" class="md-nav__link">
|
||||
Install
|
||||
</a>
|
||||
</li>
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
<li class="md-nav__item">
|
||||
<a href="../../read/" title="Read" class="md-nav__link">
|
||||
Read
|
||||
</a>
|
||||
</li>
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
<li class="md-nav__item">
|
||||
<a href="../../write/" title="Write/Update" class="md-nav__link">
|
||||
Write/Update
|
||||
</a>
|
||||
</li>
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
<li class="md-nav__item">
|
||||
<a href="../../prefix/" title="Prefix" class="md-nav__link">
|
||||
Prefix
|
||||
</a>
|
||||
</li>
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
<li class="md-nav__item">
|
||||
<a href="../../delete/" title="Delete" class="md-nav__link">
|
||||
Delete
|
||||
</a>
|
||||
</li>
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
<li class="md-nav__item">
|
||||
<a href="../../create/" title="Create" class="md-nav__link">
|
||||
Create
|
||||
</a>
|
||||
</li>
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
<li class="md-nav__item">
|
||||
<a href="../../convert/" title="Convert" class="md-nav__link">
|
||||
Convert
|
||||
</a>
|
||||
</li>
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
<li class="md-nav__item">
|
||||
<a href="../../merge/" title="Merge" class="md-nav__link">
|
||||
Merge
|
||||
</a>
|
||||
</li>
|
||||
|
||||
|
||||
</ul>
|
||||
</nav>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
|
||||
|
||||
<div class="md-content">
|
||||
<article class="md-content__inner md-typeset">
|
||||
|
||||
|
||||
<a href="https://github.com/mikefarah/yq/edit/master/docs/snippets/works_with_json.md" title="Edit this page" class="md-icon md-content__icon"></a>
|
||||
|
||||
|
||||
<h1>Works with json</h1>
|
||||
|
||||
<p>This command can take a json file as input too, and will output yaml unless specified to export as json (-j)</p>
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
</article>
|
||||
</div>
|
||||
</div>
|
||||
</main>
|
||||
|
||||
|
||||
<footer class="md-footer">
|
||||
|
||||
<div class="md-footer-meta md-typeset">
|
||||
<div class="md-footer-meta__inner md-grid">
|
||||
<div class="md-footer-copyright">
|
||||
|
||||
powered by
|
||||
<a href="https://www.mkdocs.org">MkDocs</a>
|
||||
and
|
||||
<a href="https://squidfunk.github.io/mkdocs-material/">
|
||||
Material for MkDocs</a>
|
||||
</div>
|
||||
|
||||
<div class="md-footer-social">
|
||||
<link rel="stylesheet" href="../../assets/fonts/font-awesome.css">
|
||||
|
||||
<a href="https://github.com/mikefarah" class="md-footer-social__link fa fa-github"></a>
|
||||
|
||||
<a href="https://www.linkedin.com/in/mike-farah-b5a75b2/" class="md-footer-social__link fa fa-linkedin"></a>
|
||||
|
||||
</div>
|
||||
|
||||
</div>
|
||||
</div>
|
||||
</footer>
|
||||
|
||||
</div>
|
||||
|
||||
<script src="../../assets/javascripts/application.39abc4af.js"></script>
|
||||
|
||||
<script>app.initialize({version:"1.0.4",url:{base:"../.."}})</script>
|
||||
|
||||
|
||||
</body>
|
||||
</html>
|
@ -1,919 +0,0 @@
|
||||
|
||||
|
||||
|
||||
|
||||
<!doctype html>
|
||||
<html lang="en" class="no-js">
|
||||
<head>
|
||||
|
||||
<meta charset="utf-8">
|
||||
<meta name="viewport" content="width=device-width,initial-scale=1">
|
||||
<meta http-equiv="x-ua-compatible" content="ie=edge">
|
||||
|
||||
|
||||
|
||||
|
||||
<meta name="lang:clipboard.copy" content="Copy to clipboard">
|
||||
|
||||
<meta name="lang:clipboard.copied" content="Copied to clipboard">
|
||||
|
||||
<meta name="lang:search.language" content="en">
|
||||
|
||||
<meta name="lang:search.pipeline.stopwords" content="True">
|
||||
|
||||
<meta name="lang:search.pipeline.trimmer" content="True">
|
||||
|
||||
<meta name="lang:search.result.none" content="No matching documents">
|
||||
|
||||
<meta name="lang:search.result.one" content="1 matching document">
|
||||
|
||||
<meta name="lang:search.result.other" content="# matching documents">
|
||||
|
||||
<meta name="lang:search.tokenizer" content="[\s\-]+">
|
||||
|
||||
<link rel="shortcut icon" href="../assets/images/favicon.png">
|
||||
<meta name="generator" content="mkdocs-1.0.4, mkdocs-material-4.2.0">
|
||||
|
||||
|
||||
|
||||
<title>Write/Update - Yq</title>
|
||||
|
||||
|
||||
|
||||
<link rel="stylesheet" href="../assets/stylesheets/application.750b69bd.css">
|
||||
|
||||
|
||||
|
||||
|
||||
<script src="../assets/javascripts/modernizr.74668098.js"></script>
|
||||
|
||||
|
||||
|
||||
<link href="https://fonts.gstatic.com" rel="preconnect" crossorigin>
|
||||
<link rel="stylesheet" href="https://fonts.googleapis.com/css?family=Roboto:300,400,400i,700|Roboto+Mono">
|
||||
<style>body,input{font-family:"Roboto","Helvetica Neue",Helvetica,Arial,sans-serif}code,kbd,pre{font-family:"Roboto Mono","Courier New",Courier,monospace}</style>
|
||||
|
||||
|
||||
<link rel="stylesheet" href="../assets/fonts/material-icons.css">
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
</head>
|
||||
|
||||
<body dir="ltr">
|
||||
|
||||
<svg class="md-svg">
|
||||
<defs>
|
||||
|
||||
|
||||
<svg xmlns="http://www.w3.org/2000/svg" width="416" height="448"
|
||||
viewBox="0 0 416 448" id="__github">
|
||||
<path fill="currentColor" d="M160 304q0 10-3.125 20.5t-10.75 19-18.125
|
||||
8.5-18.125-8.5-10.75-19-3.125-20.5 3.125-20.5 10.75-19 18.125-8.5
|
||||
18.125 8.5 10.75 19 3.125 20.5zM320 304q0 10-3.125 20.5t-10.75
|
||||
19-18.125 8.5-18.125-8.5-10.75-19-3.125-20.5 3.125-20.5 10.75-19
|
||||
18.125-8.5 18.125 8.5 10.75 19 3.125 20.5zM360
|
||||
304q0-30-17.25-51t-46.75-21q-10.25 0-48.75 5.25-17.75 2.75-39.25
|
||||
2.75t-39.25-2.75q-38-5.25-48.75-5.25-29.5 0-46.75 21t-17.25 51q0 22 8
|
||||
38.375t20.25 25.75 30.5 15 35 7.375 37.25 1.75h42q20.5 0
|
||||
37.25-1.75t35-7.375 30.5-15 20.25-25.75 8-38.375zM416 260q0 51.75-15.25
|
||||
82.75-9.5 19.25-26.375 33.25t-35.25 21.5-42.5 11.875-42.875 5.5-41.75
|
||||
1.125q-19.5 0-35.5-0.75t-36.875-3.125-38.125-7.5-34.25-12.875-30.25-20.25-21.5-28.75q-15.5-30.75-15.5-82.75
|
||||
0-59.25 34-99-6.75-20.5-6.75-42.5 0-29 12.75-54.5 27 0 47.5 9.875t47.25
|
||||
30.875q36.75-8.75 77.25-8.75 37 0 70 8 26.25-20.5
|
||||
46.75-30.25t47.25-9.75q12.75 25.5 12.75 54.5 0 21.75-6.75 42 34 40 34
|
||||
99.5z" />
|
||||
</svg>
|
||||
|
||||
</defs>
|
||||
</svg>
|
||||
<input class="md-toggle" data-md-toggle="drawer" type="checkbox" id="__drawer" autocomplete="off">
|
||||
<input class="md-toggle" data-md-toggle="search" type="checkbox" id="__search" autocomplete="off">
|
||||
<label class="md-overlay" data-md-component="overlay" for="__drawer"></label>
|
||||
|
||||
<a href="#to-stdout" tabindex="1" class="md-skip">
|
||||
Skip to content
|
||||
</a>
|
||||
|
||||
|
||||
<header class="md-header" data-md-component="header">
|
||||
<nav class="md-header-nav md-grid">
|
||||
<div class="md-flex">
|
||||
<div class="md-flex__cell md-flex__cell--shrink">
|
||||
<a href=".." title="Yq" class="md-header-nav__button md-logo">
|
||||
|
||||
<i class="md-icon"></i>
|
||||
|
||||
</a>
|
||||
</div>
|
||||
<div class="md-flex__cell md-flex__cell--shrink">
|
||||
<label class="md-icon md-icon--menu md-header-nav__button" for="__drawer"></label>
|
||||
</div>
|
||||
<div class="md-flex__cell md-flex__cell--stretch">
|
||||
<div class="md-flex__ellipsis md-header-nav__title" data-md-component="title">
|
||||
|
||||
<span class="md-header-nav__topic">
|
||||
Yq
|
||||
</span>
|
||||
<span class="md-header-nav__topic">
|
||||
Write/Update
|
||||
</span>
|
||||
|
||||
</div>
|
||||
</div>
|
||||
<div class="md-flex__cell md-flex__cell--shrink">
|
||||
|
||||
<label class="md-icon md-icon--search md-header-nav__button" for="__search"></label>
|
||||
|
||||
<div class="md-search" data-md-component="search" role="dialog">
|
||||
<label class="md-search__overlay" for="__search"></label>
|
||||
<div class="md-search__inner" role="search">
|
||||
<form class="md-search__form" name="search">
|
||||
<input type="text" class="md-search__input" name="query" placeholder="Search" autocapitalize="off" autocorrect="off" autocomplete="off" spellcheck="false" data-md-component="query" data-md-state="active">
|
||||
<label class="md-icon md-search__icon" for="__search"></label>
|
||||
<button type="reset" class="md-icon md-search__icon" data-md-component="reset" tabindex="-1">
|
||||

|
||||
</button>
|
||||
</form>
|
||||
<div class="md-search__output">
|
||||
<div class="md-search__scrollwrap" data-md-scrollfix>
|
||||
<div class="md-search-result" data-md-component="result">
|
||||
<div class="md-search-result__meta">
|
||||
Type to start searching
|
||||
</div>
|
||||
<ol class="md-search-result__list"></ol>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
</div>
|
||||
|
||||
<div class="md-flex__cell md-flex__cell--shrink">
|
||||
<div class="md-header-nav__source">
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
<a href="https://github.com/mikefarah/yq/" title="Go to repository" class="md-source" data-md-source="github">
|
||||
|
||||
<div class="md-source__icon">
|
||||
<svg viewBox="0 0 24 24" width="24" height="24">
|
||||
<use xlink:href="#__github" width="24" height="24"></use>
|
||||
</svg>
|
||||
</div>
|
||||
|
||||
<div class="md-source__repository">
|
||||
mikefarah/yq
|
||||
</div>
|
||||
</a>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
</div>
|
||||
</nav>
|
||||
</header>
|
||||
|
||||
<div class="md-container">
|
||||
|
||||
|
||||
|
||||
|
||||
<main class="md-main">
|
||||
<div class="md-main__inner md-grid" data-md-component="container">
|
||||
|
||||
|
||||
<div class="md-sidebar md-sidebar--primary" data-md-component="navigation">
|
||||
<div class="md-sidebar__scrollwrap">
|
||||
<div class="md-sidebar__inner">
|
||||
<nav class="md-nav md-nav--primary" data-md-level="0">
|
||||
<label class="md-nav__title md-nav__title--site" for="__drawer">
|
||||
<a href=".." title="Yq" class="md-nav__button md-logo">
|
||||
|
||||
<i class="md-icon"></i>
|
||||
|
||||
</a>
|
||||
Yq
|
||||
</label>
|
||||
|
||||
<div class="md-nav__source">
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
<a href="https://github.com/mikefarah/yq/" title="Go to repository" class="md-source" data-md-source="github">
|
||||
|
||||
<div class="md-source__icon">
|
||||
<svg viewBox="0 0 24 24" width="24" height="24">
|
||||
<use xlink:href="#__github" width="24" height="24"></use>
|
||||
</svg>
|
||||
</div>
|
||||
|
||||
<div class="md-source__repository">
|
||||
mikefarah/yq
|
||||
</div>
|
||||
</a>
|
||||
</div>
|
||||
|
||||
<ul class="md-nav__list" data-md-scrollfix>
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
<li class="md-nav__item">
|
||||
<a href=".." title="Install" class="md-nav__link">
|
||||
Install
|
||||
</a>
|
||||
</li>
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
<li class="md-nav__item">
|
||||
<a href="../read/" title="Read" class="md-nav__link">
|
||||
Read
|
||||
</a>
|
||||
</li>
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
<li class="md-nav__item md-nav__item--active">
|
||||
|
||||
<input class="md-toggle md-nav__toggle" data-md-toggle="toc" type="checkbox" id="__toc">
|
||||
|
||||
|
||||
<label class="md-nav__link md-nav__link--active" for="__toc">
|
||||
Write/Update
|
||||
</label>
|
||||
|
||||
<a href="./" title="Write/Update" class="md-nav__link md-nav__link--active">
|
||||
Write/Update
|
||||
</a>
|
||||
|
||||
|
||||
<nav class="md-nav md-nav--secondary">
|
||||
|
||||
|
||||
|
||||
<label class="md-nav__title" for="__toc">Table of contents</label>
|
||||
<ul class="md-nav__list" data-md-scrollfix>
|
||||
|
||||
<li class="md-nav__item">
|
||||
<a href="#to-stdout" title="To Stdout" class="md-nav__link">
|
||||
To Stdout
|
||||
</a>
|
||||
|
||||
</li>
|
||||
|
||||
<li class="md-nav__item">
|
||||
<a href="#from-stdin" title="From STDIN" class="md-nav__link">
|
||||
From STDIN
|
||||
</a>
|
||||
|
||||
</li>
|
||||
|
||||
<li class="md-nav__item">
|
||||
<a href="#adding-new-fields" title="Adding new fields" class="md-nav__link">
|
||||
Adding new fields
|
||||
</a>
|
||||
|
||||
</li>
|
||||
|
||||
<li class="md-nav__item">
|
||||
<a href="#splat" title="Splat" class="md-nav__link">
|
||||
Splat
|
||||
</a>
|
||||
|
||||
</li>
|
||||
|
||||
<li class="md-nav__item">
|
||||
<a href="#prefix-splat" title="Prefix Splat" class="md-nav__link">
|
||||
Prefix Splat
|
||||
</a>
|
||||
|
||||
</li>
|
||||
|
||||
<li class="md-nav__item">
|
||||
<a href="#array-splat" title="Array Splat" class="md-nav__link">
|
||||
Array Splat
|
||||
</a>
|
||||
|
||||
</li>
|
||||
|
||||
<li class="md-nav__item">
|
||||
<a href="#appending-value-to-an-array-field" title="Appending value to an array field" class="md-nav__link">
|
||||
Appending value to an array field
|
||||
</a>
|
||||
|
||||
</li>
|
||||
|
||||
<li class="md-nav__item">
|
||||
<a href="#multiple-documents-update-a-single-document" title="Multiple Documents - update a single document" class="md-nav__link">
|
||||
Multiple Documents - update a single document
|
||||
</a>
|
||||
|
||||
</li>
|
||||
|
||||
<li class="md-nav__item">
|
||||
<a href="#multiple-documents-update-all-documents" title="Multiple Documents - update all documents" class="md-nav__link">
|
||||
Multiple Documents - update all documents
|
||||
</a>
|
||||
|
||||
</li>
|
||||
|
||||
<li class="md-nav__item">
|
||||
<a href="#updating-files-in-place" title="Updating files in-place" class="md-nav__link">
|
||||
Updating files in-place
|
||||
</a>
|
||||
|
||||
</li>
|
||||
|
||||
<li class="md-nav__item">
|
||||
<a href="#updating-multiple-values-with-a-script" title="Updating multiple values with a script" class="md-nav__link">
|
||||
Updating multiple values with a script
|
||||
</a>
|
||||
|
||||
</li>
|
||||
|
||||
<li class="md-nav__item">
|
||||
<a href="#values-starting-with-a-hyphen-or-dash" title="Values starting with a hyphen (or dash)" class="md-nav__link">
|
||||
Values starting with a hyphen (or dash)
|
||||
</a>
|
||||
|
||||
</li>
|
||||
|
||||
<li class="md-nav__item">
|
||||
<a href="#keys-with-dots" title="Keys with dots" class="md-nav__link">
|
||||
Keys with dots
|
||||
</a>
|
||||
|
||||
</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>
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
</ul>
|
||||
|
||||
</nav>
|
||||
|
||||
</li>
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
<li class="md-nav__item">
|
||||
<a href="../prefix/" title="Prefix" class="md-nav__link">
|
||||
Prefix
|
||||
</a>
|
||||
</li>
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
<li class="md-nav__item">
|
||||
<a href="../delete/" title="Delete" class="md-nav__link">
|
||||
Delete
|
||||
</a>
|
||||
</li>
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
<li class="md-nav__item">
|
||||
<a href="../create/" title="Create" class="md-nav__link">
|
||||
Create
|
||||
</a>
|
||||
</li>
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
<li class="md-nav__item">
|
||||
<a href="../convert/" title="Convert" class="md-nav__link">
|
||||
Convert
|
||||
</a>
|
||||
</li>
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
<li class="md-nav__item">
|
||||
<a href="../merge/" title="Merge" class="md-nav__link">
|
||||
Merge
|
||||
</a>
|
||||
</li>
|
||||
|
||||
|
||||
</ul>
|
||||
</nav>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
|
||||
<div class="md-sidebar md-sidebar--secondary" data-md-component="toc">
|
||||
<div class="md-sidebar__scrollwrap">
|
||||
<div class="md-sidebar__inner">
|
||||
|
||||
<nav class="md-nav md-nav--secondary">
|
||||
|
||||
|
||||
|
||||
<label class="md-nav__title" for="__toc">Table of contents</label>
|
||||
<ul class="md-nav__list" data-md-scrollfix>
|
||||
|
||||
<li class="md-nav__item">
|
||||
<a href="#to-stdout" title="To Stdout" class="md-nav__link">
|
||||
To Stdout
|
||||
</a>
|
||||
|
||||
</li>
|
||||
|
||||
<li class="md-nav__item">
|
||||
<a href="#from-stdin" title="From STDIN" class="md-nav__link">
|
||||
From STDIN
|
||||
</a>
|
||||
|
||||
</li>
|
||||
|
||||
<li class="md-nav__item">
|
||||
<a href="#adding-new-fields" title="Adding new fields" class="md-nav__link">
|
||||
Adding new fields
|
||||
</a>
|
||||
|
||||
</li>
|
||||
|
||||
<li class="md-nav__item">
|
||||
<a href="#splat" title="Splat" class="md-nav__link">
|
||||
Splat
|
||||
</a>
|
||||
|
||||
</li>
|
||||
|
||||
<li class="md-nav__item">
|
||||
<a href="#prefix-splat" title="Prefix Splat" class="md-nav__link">
|
||||
Prefix Splat
|
||||
</a>
|
||||
|
||||
</li>
|
||||
|
||||
<li class="md-nav__item">
|
||||
<a href="#array-splat" title="Array Splat" class="md-nav__link">
|
||||
Array Splat
|
||||
</a>
|
||||
|
||||
</li>
|
||||
|
||||
<li class="md-nav__item">
|
||||
<a href="#appending-value-to-an-array-field" title="Appending value to an array field" class="md-nav__link">
|
||||
Appending value to an array field
|
||||
</a>
|
||||
|
||||
</li>
|
||||
|
||||
<li class="md-nav__item">
|
||||
<a href="#multiple-documents-update-a-single-document" title="Multiple Documents - update a single document" class="md-nav__link">
|
||||
Multiple Documents - update a single document
|
||||
</a>
|
||||
|
||||
</li>
|
||||
|
||||
<li class="md-nav__item">
|
||||
<a href="#multiple-documents-update-all-documents" title="Multiple Documents - update all documents" class="md-nav__link">
|
||||
Multiple Documents - update all documents
|
||||
</a>
|
||||
|
||||
</li>
|
||||
|
||||
<li class="md-nav__item">
|
||||
<a href="#updating-files-in-place" title="Updating files in-place" class="md-nav__link">
|
||||
Updating files in-place
|
||||
</a>
|
||||
|
||||
</li>
|
||||
|
||||
<li class="md-nav__item">
|
||||
<a href="#updating-multiple-values-with-a-script" title="Updating multiple values with a script" class="md-nav__link">
|
||||
Updating multiple values with a script
|
||||
</a>
|
||||
|
||||
</li>
|
||||
|
||||
<li class="md-nav__item">
|
||||
<a href="#values-starting-with-a-hyphen-or-dash" title="Values starting with a hyphen (or dash)" class="md-nav__link">
|
||||
Values starting with a hyphen (or dash)
|
||||
</a>
|
||||
|
||||
</li>
|
||||
|
||||
<li class="md-nav__item">
|
||||
<a href="#keys-with-dots" title="Keys with dots" class="md-nav__link">
|
||||
Keys with dots
|
||||
</a>
|
||||
|
||||
</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>
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
</ul>
|
||||
|
||||
</nav>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
|
||||
<div class="md-content">
|
||||
<article class="md-content__inner md-typeset">
|
||||
|
||||
|
||||
<a href="https://github.com/mikefarah/yq/edit/master/docs/write.md" title="Edit this page" class="md-icon md-content__icon"></a>
|
||||
|
||||
|
||||
<h1>Write/Update</h1>
|
||||
|
||||
<pre><code>yq w <yaml_file> <path> <new value>
|
||||
</code></pre>
|
||||
|
||||
<h3 id="to-stdout">To Stdout<a class="headerlink" href="#to-stdout" title="Permanent link">¶</a></h3>
|
||||
<p>Given a sample.yaml file of:</p>
|
||||
<pre><code class="yaml">b:
|
||||
c: 2
|
||||
</code></pre>
|
||||
|
||||
<p>then</p>
|
||||
<pre><code class="bash">yq w sample.yaml b.c cat
|
||||
</code></pre>
|
||||
|
||||
<p>will output:</p>
|
||||
<pre><code class="yaml">b:
|
||||
c: cat
|
||||
</code></pre>
|
||||
|
||||
<h3 id="from-stdin">From STDIN<a class="headerlink" href="#from-stdin" title="Permanent link">¶</a></h3>
|
||||
<pre><code class="bash">cat sample.yaml | yq w - b.c blah
|
||||
</code></pre>
|
||||
|
||||
<h3 id="adding-new-fields">Adding new fields<a class="headerlink" href="#adding-new-fields" title="Permanent link">¶</a></h3>
|
||||
<p>Any missing fields in the path will be created on the fly.</p>
|
||||
<p>Given a sample.yaml file of:</p>
|
||||
<pre><code class="yaml">b:
|
||||
c: 2
|
||||
</code></pre>
|
||||
|
||||
<p>then</p>
|
||||
<pre><code class="bash">yq w sample.yaml b.d[+] "new thing"
|
||||
</code></pre>
|
||||
|
||||
<p>will output:</p>
|
||||
<pre><code class="yaml">b:
|
||||
c: cat
|
||||
d:
|
||||
- new thing
|
||||
</code></pre>
|
||||
|
||||
<h3 id="splat">Splat<a class="headerlink" href="#splat" title="Permanent link">¶</a></h3>
|
||||
<p>Given a sample.yaml file of:</p>
|
||||
<pre><code class="yaml">---
|
||||
bob:
|
||||
item1:
|
||||
cats: bananas
|
||||
item2:
|
||||
cats: apples
|
||||
thing:
|
||||
cats: oranges
|
||||
</code></pre>
|
||||
|
||||
<p>then</p>
|
||||
<pre><code class="bash">yq w sample.yaml bob.*.cats meow
|
||||
</code></pre>
|
||||
|
||||
<p>will output:</p>
|
||||
<pre><code class="yaml">---
|
||||
bob:
|
||||
item1:
|
||||
cats: meow
|
||||
item2:
|
||||
cats: meow
|
||||
thing:
|
||||
cats: meow
|
||||
</code></pre>
|
||||
|
||||
<h3 id="prefix-splat">Prefix Splat<a class="headerlink" href="#prefix-splat" title="Permanent link">¶</a></h3>
|
||||
<p>Given a sample.yaml file of:</p>
|
||||
<pre><code class="yaml">---
|
||||
bob:
|
||||
item1:
|
||||
cats: bananas
|
||||
item2:
|
||||
cats: apples
|
||||
thing:
|
||||
cats: oranges
|
||||
</code></pre>
|
||||
|
||||
<p>then</p>
|
||||
<pre><code class="bash">yq w sample.yaml bob.item*.cats meow
|
||||
</code></pre>
|
||||
|
||||
<p>will output:</p>
|
||||
<pre><code class="yaml">---
|
||||
bob:
|
||||
item1:
|
||||
cats: meow
|
||||
item2:
|
||||
cats: meow
|
||||
thing:
|
||||
cats: oranges
|
||||
</code></pre>
|
||||
|
||||
<h3 id="array-splat">Array Splat<a class="headerlink" href="#array-splat" title="Permanent link">¶</a></h3>
|
||||
<p>Given a sample.yaml file of:</p>
|
||||
<pre><code class="yaml">---
|
||||
bob:
|
||||
- cats: bananas
|
||||
- cats: apples
|
||||
- cats: oranges
|
||||
</code></pre>
|
||||
|
||||
<p>then</p>
|
||||
<pre><code class="bash">yq w sample.yaml bob[*].cats meow
|
||||
</code></pre>
|
||||
|
||||
<p>will output:</p>
|
||||
<pre><code class="yaml">---
|
||||
bob:
|
||||
- cats: meow
|
||||
- cats: meow
|
||||
- cats: meow
|
||||
</code></pre>
|
||||
|
||||
<h3 id="appending-value-to-an-array-field">Appending value to an array field<a class="headerlink" href="#appending-value-to-an-array-field" title="Permanent link">¶</a></h3>
|
||||
<p>Given a sample.yaml file of:</p>
|
||||
<pre><code class="yaml">b:
|
||||
c: 2
|
||||
d:
|
||||
- new thing
|
||||
- foo thing
|
||||
</code></pre>
|
||||
|
||||
<p>then</p>
|
||||
<pre><code class="bash">yq w sample.yaml "b.d[+]" "bar thing"
|
||||
</code></pre>
|
||||
|
||||
<p>will output:</p>
|
||||
<pre><code class="yaml">b:
|
||||
c: cat
|
||||
d:
|
||||
- new thing
|
||||
- foo thing
|
||||
- bar thing
|
||||
</code></pre>
|
||||
|
||||
<p>Note that the path is in quotes to avoid the square brackets being interpreted by your shell.</p>
|
||||
<h3 id="multiple-documents-update-a-single-document">Multiple Documents - update a single document<a class="headerlink" href="#multiple-documents-update-a-single-document" title="Permanent link">¶</a></h3>
|
||||
<p>Given a sample.yaml file of:</p>
|
||||
<pre><code class="yaml">something: else
|
||||
---
|
||||
b:
|
||||
c: 2
|
||||
</code></pre>
|
||||
|
||||
<p>then</p>
|
||||
<pre><code class="bash">yq w -d1 sample.yaml b.c 5
|
||||
</code></pre>
|
||||
|
||||
<p>will output:</p>
|
||||
<pre><code class="yaml">something: else
|
||||
---
|
||||
b:
|
||||
c: 5
|
||||
</code></pre>
|
||||
|
||||
<h3 id="multiple-documents-update-all-documents">Multiple Documents - update all documents<a class="headerlink" href="#multiple-documents-update-all-documents" title="Permanent link">¶</a></h3>
|
||||
<p>Given a sample.yaml file of:</p>
|
||||
<pre><code class="yaml">something: else
|
||||
---
|
||||
b:
|
||||
c: 2
|
||||
</code></pre>
|
||||
|
||||
<p>then</p>
|
||||
<pre><code class="bash">yq w -d'*' sample.yaml b.c 5
|
||||
</code></pre>
|
||||
|
||||
<p>will output:</p>
|
||||
<pre><code class="yaml">something: else
|
||||
b:
|
||||
c: 5
|
||||
---
|
||||
b:
|
||||
c: 5
|
||||
</code></pre>
|
||||
|
||||
<p>Note that '*' is in quotes to avoid being interpreted by your shell.</p>
|
||||
<h3 id="updating-files-in-place">Updating files in-place<a class="headerlink" href="#updating-files-in-place" title="Permanent link">¶</a></h3>
|
||||
<p>Given a sample.yaml file of:</p>
|
||||
<pre><code class="yaml">b:
|
||||
c: 2
|
||||
</code></pre>
|
||||
|
||||
<p>then</p>
|
||||
<pre><code class="bash">yq w -i sample.yaml b.c cat
|
||||
</code></pre>
|
||||
|
||||
<p>will update the sample.yaml file so that the value of 'c' is cat.</p>
|
||||
<h3 id="updating-multiple-values-with-a-script">Updating multiple values with a script<a class="headerlink" href="#updating-multiple-values-with-a-script" title="Permanent link">¶</a></h3>
|
||||
<p>Given a sample.yaml file of:</p>
|
||||
<pre><code class="yaml">b:
|
||||
c: 2
|
||||
e:
|
||||
- name: Billy Bob
|
||||
</code></pre>
|
||||
|
||||
<p>and a script update_instructions.yaml of:</p>
|
||||
<pre><code class="yaml">b.c: 3
|
||||
b.e[+].name: Howdy Partner
|
||||
</code></pre>
|
||||
|
||||
<p>then</p>
|
||||
<pre><code class="bash">yq w -s update_instructions.yaml sample.yaml
|
||||
</code></pre>
|
||||
|
||||
<p>will output:</p>
|
||||
<pre><code class="yaml">b:
|
||||
c: 3
|
||||
e:
|
||||
- name: Howdy Partner
|
||||
</code></pre>
|
||||
|
||||
<p>And, of course, you can pipe the instructions in using '-':</p>
|
||||
<pre><code class="bash">cat update_instructions.yaml | yq w -s - sample.yaml
|
||||
</code></pre>
|
||||
|
||||
<h3 id="values-starting-with-a-hyphen-or-dash">Values starting with a hyphen (or dash)<a class="headerlink" href="#values-starting-with-a-hyphen-or-dash" title="Permanent link">¶</a></h3>
|
||||
<p>The flag terminator needs to be used to stop the app from attempting to parse the subsequent arguments as flags:</p>
|
||||
<pre><code>yq w -- my.path -3
|
||||
</code></pre>
|
||||
|
||||
<p>will output</p>
|
||||
<pre><code class="yaml">my:
|
||||
path: -3
|
||||
</code></pre>
|
||||
|
||||
<h3 id="keys-with-dots">Keys with dots<a class="headerlink" href="#keys-with-dots" title="Permanent link">¶</a></h3>
|
||||
<p>When specifying a key that has a dot use key lookup indicator.</p>
|
||||
<pre><code class="yaml">b:
|
||||
foo.bar: 7
|
||||
</code></pre>
|
||||
|
||||
<pre><code class="bash">yaml r sample.yaml 'b[foo.bar]'
|
||||
</code></pre>
|
||||
|
||||
<pre><code class="bash">yaml w sample.yaml 'b[foo.bar]' 9
|
||||
</code></pre>
|
||||
|
||||
<p>Any valid yaml key can be specified as part of a key lookup.</p>
|
||||
<p>Note that the path is in quotes to avoid the square brackets being interpreted by your shell.</p>
|
||||
<h3 id="keys-and-values-with-leading-dashes">Keys (and values) with leading dashes<a class="headerlink" href="#keys-and-values-with-leading-dashes" title="Permanent link">¶</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>
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
</article>
|
||||
</div>
|
||||
</div>
|
||||
</main>
|
||||
|
||||
|
||||
<footer class="md-footer">
|
||||
|
||||
<div class="md-footer-nav">
|
||||
<nav class="md-footer-nav__inner md-grid">
|
||||
|
||||
<a href="../read/" title="Read" class="md-flex md-footer-nav__link md-footer-nav__link--prev" rel="prev">
|
||||
<div class="md-flex__cell md-flex__cell--shrink">
|
||||
<i class="md-icon md-icon--arrow-back md-footer-nav__button"></i>
|
||||
</div>
|
||||
<div class="md-flex__cell md-flex__cell--stretch md-footer-nav__title">
|
||||
<span class="md-flex__ellipsis">
|
||||
<span class="md-footer-nav__direction">
|
||||
Previous
|
||||
</span>
|
||||
Read
|
||||
</span>
|
||||
</div>
|
||||
</a>
|
||||
|
||||
|
||||
<a href="../prefix/" title="Prefix" class="md-flex md-footer-nav__link md-footer-nav__link--next" rel="next">
|
||||
<div class="md-flex__cell md-flex__cell--stretch md-footer-nav__title">
|
||||
<span class="md-flex__ellipsis">
|
||||
<span class="md-footer-nav__direction">
|
||||
Next
|
||||
</span>
|
||||
Prefix
|
||||
</span>
|
||||
</div>
|
||||
<div class="md-flex__cell md-flex__cell--shrink">
|
||||
<i class="md-icon md-icon--arrow-forward md-footer-nav__button"></i>
|
||||
</div>
|
||||
</a>
|
||||
|
||||
</nav>
|
||||
</div>
|
||||
|
||||
<div class="md-footer-meta md-typeset">
|
||||
<div class="md-footer-meta__inner md-grid">
|
||||
<div class="md-footer-copyright">
|
||||
|
||||
powered by
|
||||
<a href="https://www.mkdocs.org">MkDocs</a>
|
||||
and
|
||||
<a href="https://squidfunk.github.io/mkdocs-material/">
|
||||
Material for MkDocs</a>
|
||||
</div>
|
||||
|
||||
<div class="md-footer-social">
|
||||
<link rel="stylesheet" href="../assets/fonts/font-awesome.css">
|
||||
|
||||
<a href="https://github.com/mikefarah" class="md-footer-social__link fa fa-github"></a>
|
||||
|
||||
<a href="https://www.linkedin.com/in/mike-farah-b5a75b2/" class="md-footer-social__link fa fa-linkedin"></a>
|
||||
|
||||
</div>
|
||||
|
||||
</div>
|
||||
</div>
|
||||
</footer>
|
||||
|
||||
</div>
|
||||
|
||||
<script src="../assets/javascripts/application.39abc4af.js"></script>
|
||||
|
||||
<script>app.initialize({version:"1.0.4",url:{base:".."}})</script>
|
||||
|
||||
|
||||
</body>
|
||||
</html>
|
@ -7,3 +7,5 @@
|
||||
- lala
|
||||
- land
|
||||
serial: 1
|
||||
- become: false
|
||||
gather_facts: true
|
||||
|
@ -1,2 +1,4 @@
|
||||
a: simple
|
||||
a: simple # just the best
|
||||
b: [1, 2]
|
||||
c:
|
||||
test: 1
|
||||
|
@ -1,4 +1,7 @@
|
||||
a: other
|
||||
a: other # better than the original
|
||||
b: [3, 4]
|
||||
c:
|
||||
toast: leave
|
||||
test: 1
|
||||
tell: 1
|
||||
taco: cool
|
||||
|
@ -1,2 +1,7 @@
|
||||
b.c: cat
|
||||
b.e[+].name: Mike Farah
|
||||
- command: update
|
||||
path: b.c
|
||||
value:
|
||||
#great
|
||||
things: frog # wow!
|
||||
- command: delete
|
||||
path: b.d
|
19
examples/merge-anchor.yaml
Normal file
19
examples/merge-anchor.yaml
Normal file
@ -0,0 +1,19 @@
|
||||
foo: &foo
|
||||
a: original
|
||||
thing: coolasdf
|
||||
thirsty: yep
|
||||
|
||||
bar: &bar
|
||||
b: 2
|
||||
thing: coconut
|
||||
c: oldbar
|
||||
|
||||
foobarList:
|
||||
<<: [*foo,*bar]
|
||||
c: newbar
|
||||
|
||||
foobar:
|
||||
<<: *foo
|
||||
thirty: well beyond
|
||||
thing: ice
|
||||
c: 3
|
@ -1,7 +1,7 @@
|
||||
a: Easy! as one two three
|
||||
a: true
|
||||
b:
|
||||
c: 2
|
||||
d: [3, 4]
|
||||
d: [3, 4, 5]
|
||||
e:
|
||||
- name: fred
|
||||
value: 3
|
||||
|
@ -1,9 +1,2 @@
|
||||
a: Easy! as one two three
|
||||
b:
|
||||
c: things
|
||||
d: whatever
|
||||
things:
|
||||
thing1:
|
||||
cat: 'fred'
|
||||
thing2:
|
||||
cat: 'sam'
|
||||
|
@ -1 +1,2 @@
|
||||
[4,5]
|
||||
- 4
|
||||
- 5
|
4
examples/simple-anchor.yaml
Normal file
4
examples/simple-anchor.yaml
Normal file
@ -0,0 +1,4 @@
|
||||
foo: &foo
|
||||
a: 1
|
||||
|
||||
foobar: *foo
|
8
go.mod
8
go.mod
@ -1,12 +1,12 @@
|
||||
module github.com/mikefarah/yq/v2
|
||||
module github.com/mikefarah/yq/v3
|
||||
|
||||
require (
|
||||
github.com/mikefarah/yaml/v2 v2.4.0
|
||||
github.com/pkg/errors v0.8.1
|
||||
github.com/spf13/cobra v0.0.5
|
||||
golang.org/x/tools v0.0.0-20191030203535-5e247c9ad0a0 // indirect
|
||||
gopkg.in/imdario/mergo.v0 v0.3.7
|
||||
golang.org/x/tools v0.0.0-20191213221258-04c2e8eff935 // indirect
|
||||
gopkg.in/imdario/mergo.v0 v0.3.7 // indirect
|
||||
gopkg.in/op/go-logging.v1 v1.0.0-20160211212156-b2cb9fa56473
|
||||
gopkg.in/yaml.v3 v3.0.0-20191120175047-4206685974f2
|
||||
)
|
||||
|
||||
go 1.13
|
||||
|
12
go.sum
12
go.sum
@ -10,8 +10,11 @@ github.com/hashicorp/hcl v1.0.0/go.mod h1:E5yfLk+7swimpb2L/Alb/PJmXilQ/rhwaUYs4T
|
||||
github.com/inconshreveable/mousetrap v1.0.0 h1:Z8tu5sraLXCXIcARxBp/8cbvlwVa7Z1NHg9XEKhtSvM=
|
||||
github.com/inconshreveable/mousetrap v1.0.0/go.mod h1:PxqpIevigyE2G7u3NXJIT2ANytuPF1OarO4DADm73n8=
|
||||
github.com/magiconair/properties v1.8.0/go.mod h1:PppfXfuXeibc/6YijjN8zIbojt8czPbwD3XqdrwzmxQ=
|
||||
github.com/mikefarah/yaml v2.1.0+incompatible h1:nu2cqmzk4WlWJNgnevY88faMcdrDzYGcsUjYFxEpB7Y=
|
||||
github.com/mikefarah/yaml/v2 v2.4.0 h1:eYqfooY0BnvKTJxr7+ABJs13n3dg9n347GScDaU2Lww=
|
||||
github.com/mikefarah/yaml/v2 v2.4.0/go.mod h1:ahVqZF4n1W4NqwvVnZzC4es67xsW9uR/RRf2RRxieJU=
|
||||
github.com/mikefarah/yq v2.4.0+incompatible h1:oBxbWy8R9hI3BIUUxEf0CzikWa2AgnGrGhvGQt5jgjk=
|
||||
github.com/mikefarah/yq/v2 v2.4.1 h1:tajDonaFK6WqitSZExB6fKlWQy/yCkptqxh2AXEe3N4=
|
||||
github.com/mitchellh/go-homedir v1.1.0/go.mod h1:SfyaCUpYCn1Vlf4IUYiD9fPX4A5wJrkLzIz1N1q0pr0=
|
||||
github.com/mitchellh/mapstructure v1.1.2/go.mod h1:FVVH3fgwuzCH5S8UJGiWEs2h04kUh9fWfEaFds41c1Y=
|
||||
github.com/pelletier/go-toml v1.2.0/go.mod h1:5z9KED0ma1S8pY6P1sdut58dfprrGBbd/94hg7ilaic=
|
||||
@ -32,14 +35,21 @@ github.com/ugorji/go/codec v0.0.0-20181204163529-d75b2dcb6bc8/go.mod h1:VFNgLljT
|
||||
github.com/xordataexchange/crypt v0.0.3-0.20170626215501-b2862e3d0a77/go.mod h1:aYKd//L2LvnjZzWKhF00oedf4jCCReLcmhLdhm1A27Q=
|
||||
golang.org/x/crypto v0.0.0-20181203042331-505ab145d0a9/go.mod h1:6SG95UA2DQfeDnfUPMdvaQW0Q7yPrPDi9nlGo2tz2b4=
|
||||
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
|
||||
golang.org/x/crypto v0.0.0-20191011191535-87dc89f01550/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI=
|
||||
golang.org/x/mod v0.1.1-0.20191105210325-c90efee705ee/go.mod h1:QqPTAvyqsEbceGzBzNggFXnrqF1CaUcvgkdR5Ot7KZg=
|
||||
golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg=
|
||||
golang.org/x/net v0.0.0-20190620200207-3b0461eec859/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
|
||||
golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
|
||||
golang.org/x/sys v0.0.0-20181205085412-a5c9d58dba9a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
|
||||
golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
|
||||
golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
|
||||
golang.org/x/tools v0.0.0-20191030203535-5e247c9ad0a0 h1:s5lp4ug7qHzUccgyFdjsX7OZDzHXRaePrF3B3vmUiuM=
|
||||
golang.org/x/tools v0.0.0-20191030203535-5e247c9ad0a0/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo=
|
||||
golang.org/x/tools v0.0.0-20191213221258-04c2e8eff935 h1:kJQZhwFzSwJS2BxboKjdZzWczQOZx8VuH7Y8hhuGUtM=
|
||||
golang.org/x/tools v0.0.0-20191213221258-04c2e8eff935/go.mod h1:TB2adYChydJhpapKDTa4BR/hXlZSLoq2Wpct/0txZ28=
|
||||
golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
|
||||
golang.org/x/xerrors v0.0.0-20191011141410-1b5146add898/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
|
||||
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM=
|
||||
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
|
||||
gopkg.in/imdario/mergo.v0 v0.3.7 h1:QDotlIZtaO/p+Um0ok18HRTpq5i5/SAk/qprsor+9c8=
|
||||
@ -48,3 +58,5 @@ gopkg.in/op/go-logging.v1 v1.0.0-20160211212156-b2cb9fa56473 h1:6D+BvnJ/j6e222UW
|
||||
gopkg.in/op/go-logging.v1 v1.0.0-20160211212156-b2cb9fa56473/go.mod h1:N1eN2tsCx0Ydtgjl4cqmbRCsY4/+z4cYDeqwZTk6zog=
|
||||
gopkg.in/yaml.v2 v2.2.2 h1:ZCJp+EgiOT7lHqUV2J862kp8Qj64Jo6az82+3Td9dZw=
|
||||
gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
|
||||
gopkg.in/yaml.v3 v3.0.0-20191120175047-4206685974f2 h1:XZx7nhd5GMaZpmDaEHFVafUZC7ya0fuo7cSJ3UCKYmM=
|
||||
gopkg.in/yaml.v3 v3.0.0-20191120175047-4206685974f2/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
|
||||
|
21
mkdocs.yml
21
mkdocs.yml
@ -2,27 +2,6 @@ docs_dir: mkdocs
|
||||
site_dir: docs
|
||||
site_name: Yq
|
||||
theme: 'material'
|
||||
pages:
|
||||
- Install: index.md
|
||||
- Read: read.md
|
||||
- Write/Update: write.md
|
||||
- Prefix: prefix.md
|
||||
- Delete: delete.md
|
||||
- Create: create.md
|
||||
- Convert: convert.md
|
||||
- Merge: merge.md
|
||||
repo_name: 'mikefarah/yq'
|
||||
repo_url: 'https://github.com/mikefarah/yq'
|
||||
|
||||
extra:
|
||||
social:
|
||||
- type: 'github'
|
||||
link: 'https://github.com/mikefarah'
|
||||
- type: 'linkedin'
|
||||
link: 'https://www.linkedin.com/in/mike-farah-b5a75b2/'
|
||||
|
||||
markdown_extensions:
|
||||
- markdown_include.include:
|
||||
base_path: mkdocs
|
||||
- toc:
|
||||
permalink: True
|
||||
|
@ -1,40 +0,0 @@
|
||||
### Yaml to Json
|
||||
To convert output to json, use the --tojson (or -j) flag. This can only be used with the read command.
|
||||
|
||||
Given a sample.yaml file of:
|
||||
```yaml
|
||||
b:
|
||||
c: 2
|
||||
```
|
||||
then
|
||||
```bash
|
||||
yq r -j sample.yaml b.c
|
||||
```
|
||||
|
||||
will output
|
||||
```json
|
||||
{"b":{"c":2}}
|
||||
```
|
||||
|
||||
### Json to Yaml
|
||||
To read in json, just pass in a json file instead of yaml, it will just work :)
|
||||
|
||||
e.g given a json file
|
||||
|
||||
```json
|
||||
{"a":"Easy! as one two three","b":{"c":2,"d":[3,4]}}
|
||||
```
|
||||
then
|
||||
```bash
|
||||
yq r sample.json
|
||||
```
|
||||
will output
|
||||
```yaml
|
||||
a: Easy! as one two three
|
||||
b:
|
||||
c: 2
|
||||
d:
|
||||
- 3
|
||||
- 4
|
||||
```
|
||||
|
@ -1,44 +0,0 @@
|
||||
Yaml files can be created using the 'new' command. This works in the same way as the write command, but you don't pass in an existing Yaml file. Currently this does not support creating multiple documents in a single yaml file.
|
||||
|
||||
```
|
||||
yq n <path> <new value>
|
||||
```
|
||||
|
||||
### Creating a simple yaml file
|
||||
```bash
|
||||
yq n b.c cat
|
||||
```
|
||||
will output:
|
||||
```yaml
|
||||
b:
|
||||
c: cat
|
||||
```
|
||||
|
||||
### Creating using a create script
|
||||
Create scripts follow the same format as the update scripts.
|
||||
|
||||
Given a script create_instructions.yaml of:
|
||||
```yaml
|
||||
b.c: 3
|
||||
b.e[+].name: Howdy Partner
|
||||
```
|
||||
then
|
||||
|
||||
```bash
|
||||
yq n -s create_instructions.yaml
|
||||
```
|
||||
will output:
|
||||
```yaml
|
||||
b:
|
||||
c: 3
|
||||
e:
|
||||
- name: Howdy Partner
|
||||
```
|
||||
|
||||
You can also pipe the instructions in:
|
||||
|
||||
```bash
|
||||
cat create_instructions.yaml | yq n -s -
|
||||
```
|
||||
|
||||
{!snippets/niche.md!}
|
197
mkdocs/delete.md
197
mkdocs/delete.md
@ -1,197 +0,0 @@
|
||||
```
|
||||
yq d <yaml_file> <path_to_delete>
|
||||
```
|
||||
|
||||
### To Stdout
|
||||
Given a sample.yaml file of:
|
||||
```yaml
|
||||
b:
|
||||
c: 2
|
||||
apples: green
|
||||
```
|
||||
then
|
||||
```bash
|
||||
yq d sample.yaml b.c
|
||||
```
|
||||
will output:
|
||||
```yaml
|
||||
b:
|
||||
apples: green
|
||||
```
|
||||
|
||||
### From STDIN
|
||||
```bash
|
||||
cat sample.yaml | yq d - b.c
|
||||
```
|
||||
|
||||
### Deleting array elements
|
||||
Given a sample.yaml file of:
|
||||
```yaml
|
||||
b:
|
||||
c:
|
||||
- 1
|
||||
- 2
|
||||
- 3
|
||||
```
|
||||
then
|
||||
```bash
|
||||
yq d sample.yaml 'b.c[1]'
|
||||
```
|
||||
will output:
|
||||
```yaml
|
||||
b:
|
||||
c:
|
||||
- 1
|
||||
- 3
|
||||
```
|
||||
|
||||
### Deleting nodes in-place
|
||||
Given a sample.yaml file of:
|
||||
```yaml
|
||||
b:
|
||||
c: 2
|
||||
apples: green
|
||||
```
|
||||
then
|
||||
```bash
|
||||
yq d -i sample.yaml b.c
|
||||
```
|
||||
will update the sample.yaml file so that the 'c' node is deleted
|
||||
|
||||
|
||||
### Splat
|
||||
Given a sample.yaml file of:
|
||||
```yaml
|
||||
---
|
||||
bob:
|
||||
item1:
|
||||
cats: bananas
|
||||
dogs: woof
|
||||
item2:
|
||||
cats: apples
|
||||
dogs: woof2
|
||||
thing:
|
||||
cats: oranges
|
||||
dogs: woof3
|
||||
```
|
||||
then
|
||||
```bash
|
||||
yq d sample.yaml bob.*.cats
|
||||
```
|
||||
will output:
|
||||
```yaml
|
||||
---
|
||||
bob:
|
||||
item1:
|
||||
dogs: woof
|
||||
item2:
|
||||
dogs: woof2
|
||||
thing:
|
||||
dogs: woof3
|
||||
```
|
||||
|
||||
### Prefix Splat
|
||||
Given a sample.yaml file of:
|
||||
```yaml
|
||||
---
|
||||
bob:
|
||||
item1:
|
||||
cats: bananas
|
||||
dogs: woof
|
||||
item2:
|
||||
cats: apples
|
||||
dogs: woof2
|
||||
thing:
|
||||
cats: oranges
|
||||
dogs: woof3
|
||||
```
|
||||
then
|
||||
```bash
|
||||
yq d sample.yaml bob.item*.cats
|
||||
```
|
||||
will output:
|
||||
```yaml
|
||||
---
|
||||
bob:
|
||||
item1:
|
||||
dogs: woof
|
||||
item2:
|
||||
dogs: woof2
|
||||
thing:
|
||||
cats: oranges
|
||||
dogs: woof3
|
||||
```
|
||||
|
||||
### Array Splat
|
||||
Given a sample.yaml file of:
|
||||
```yaml
|
||||
---
|
||||
bob:
|
||||
- cats: bananas
|
||||
dogs: woof
|
||||
- cats: apples
|
||||
dogs: woof2
|
||||
- cats: oranges
|
||||
dogs: woof3
|
||||
```
|
||||
then
|
||||
```bash
|
||||
yq d sample.yaml bob.[*].cats
|
||||
```
|
||||
will output:
|
||||
```yaml
|
||||
---
|
||||
bob:
|
||||
- dogs: woof
|
||||
- dogs: woof2
|
||||
- dogs: woof3
|
||||
```
|
||||
|
||||
### Multiple Documents - delete from single document
|
||||
Given a sample.yaml file of:
|
||||
```yaml
|
||||
something: else
|
||||
field: leaveMe
|
||||
---
|
||||
b:
|
||||
c: 2
|
||||
field: deleteMe
|
||||
```
|
||||
then
|
||||
```bash
|
||||
yq w -d1 sample.yaml field
|
||||
```
|
||||
will output:
|
||||
```yaml
|
||||
something: else
|
||||
field: leaveMe
|
||||
---
|
||||
b:
|
||||
c: 2
|
||||
```
|
||||
|
||||
### Multiple Documents - delete from all documents
|
||||
Given a sample.yaml file of:
|
||||
```yaml
|
||||
something: else
|
||||
field: deleteMe
|
||||
---
|
||||
b:
|
||||
c: 2
|
||||
field: deleteMeToo
|
||||
```
|
||||
then
|
||||
```bash
|
||||
yq w -d'*' sample.yaml field
|
||||
```
|
||||
will output:
|
||||
```yaml
|
||||
something: else
|
||||
---
|
||||
b:
|
||||
c: 2
|
||||
```
|
||||
|
||||
Note that '*' is in quotes to avoid being interpreted by your shell.
|
||||
|
||||
{!snippets/niche.md!}
|
@ -1,26 +0,0 @@
|
||||
# yq
|
||||
yq is a lightweight and portable command-line YAML processor
|
||||
|
||||
The aim of the project is to be the [jq](https://github.com/stedolan/jq) or sed of yaml files.
|
||||
|
||||
## Install
|
||||
On MacOS:
|
||||
```
|
||||
brew install yq
|
||||
```
|
||||
On Ubuntu and other Linux distros supporting `snap` packages:
|
||||
```
|
||||
snap install yq
|
||||
```
|
||||
On Ubuntu 16.04 or higher from Debian package:
|
||||
```
|
||||
sudo add-apt-repository ppa:rmescandon/yq
|
||||
sudo apt update
|
||||
sudo apt install yq -y
|
||||
```
|
||||
or, [Download latest binary](https://github.com/mikefarah/yq/releases/latest) or alternatively:
|
||||
```
|
||||
go get gopkg.in/mikefarah/yq.v2
|
||||
```
|
||||
|
||||
[View on GitHub](https://github.com/mikefarah/yq)
|
189
mkdocs/merge.md
189
mkdocs/merge.md
@ -1,189 +0,0 @@
|
||||
Yaml files can be merged using the 'merge' command. Each additional file merged with the first file will
|
||||
set values for any key not existing already or where the key has no value.
|
||||
|
||||
```
|
||||
yq m <yaml_file> <path>...
|
||||
```
|
||||
|
||||
|
||||
### To Stdout
|
||||
Given a data1.yaml file of:
|
||||
```yaml
|
||||
a: simple
|
||||
b: [1, 2]
|
||||
```
|
||||
and data2.yaml file of:
|
||||
```yaml
|
||||
a: other
|
||||
c:
|
||||
test: 1
|
||||
```
|
||||
then
|
||||
```bash
|
||||
yq m data1.yaml data2.yaml
|
||||
```
|
||||
will output:
|
||||
```yaml
|
||||
a: simple
|
||||
b: [1, 2]
|
||||
c:
|
||||
test: 1
|
||||
```
|
||||
|
||||
### Updating files in-place
|
||||
Given a data1.yaml file of:
|
||||
```yaml
|
||||
a: simple
|
||||
b: [1, 2]
|
||||
```
|
||||
and data2.yaml file of:
|
||||
```yaml
|
||||
a: other
|
||||
c:
|
||||
test: 1
|
||||
```
|
||||
then
|
||||
```bash
|
||||
yq m -i data1.yaml data2.yaml
|
||||
```
|
||||
will update the data1.yaml file so that the value of 'c' is 'test: 1'.
|
||||
|
||||
### Overwrite values
|
||||
Given a data1.yaml file of:
|
||||
```yaml
|
||||
a: simple
|
||||
b: [1, 2]
|
||||
```
|
||||
and data2.yaml file of:
|
||||
```yaml
|
||||
a: other
|
||||
c:
|
||||
test: 1
|
||||
```
|
||||
then
|
||||
```bash
|
||||
yq m -x data1.yaml data2.yaml
|
||||
```
|
||||
will output:
|
||||
```yaml
|
||||
a: other
|
||||
b: [1, 2]
|
||||
c:
|
||||
test: 1
|
||||
```
|
||||
|
||||
### Overwrite values with arrays
|
||||
Given a data1.yaml file of:
|
||||
```yaml
|
||||
a: simple
|
||||
b: [1, 2]
|
||||
```
|
||||
and data3.yaml file of:
|
||||
```yaml
|
||||
b: [3, 4]
|
||||
c:
|
||||
test: 2
|
||||
other: true
|
||||
d: false
|
||||
```
|
||||
then
|
||||
```bash
|
||||
yq m -x data1.yaml data3.yaml
|
||||
```
|
||||
will output:
|
||||
```yaml
|
||||
a: simple
|
||||
b: [3, 4]
|
||||
c:
|
||||
test: 2
|
||||
other: true
|
||||
d: false
|
||||
```
|
||||
|
||||
Notice that 'b' does not result in the merging of the values within an array.
|
||||
|
||||
### Append values with arrays
|
||||
Given a data1.yaml file of:
|
||||
```yaml
|
||||
a: simple
|
||||
b: [1, 2]
|
||||
d: hi
|
||||
```
|
||||
and data3.yaml file of:
|
||||
```yaml
|
||||
a: something
|
||||
b: [3, 4]
|
||||
c:
|
||||
test: 2
|
||||
other: true
|
||||
```
|
||||
then
|
||||
```bash
|
||||
yq m -a data1.yaml data3.yaml
|
||||
```
|
||||
will output:
|
||||
```yaml
|
||||
a: simple
|
||||
b: [1, 2, 3, 4]
|
||||
c:
|
||||
test: 2
|
||||
other: true
|
||||
d: hi
|
||||
```
|
||||
|
||||
Note that the 'b' array has concatenated the values from the second data file. Also note that other map keys are not overridden (field a).
|
||||
|
||||
Append cannot be used with overwrite, if both flags are given then append is ignored.
|
||||
|
||||
### Multiple Documents - merge into single document
|
||||
Currently yq only has multi-document support for the _first_ document being merged into. The remaining yaml files will have their first document selected.
|
||||
|
||||
Given a data1.yaml file of:
|
||||
```yaml
|
||||
something: else
|
||||
---
|
||||
a: simple
|
||||
b: cat
|
||||
```
|
||||
and data3.yaml file of:
|
||||
```yaml
|
||||
b: dog
|
||||
```
|
||||
then
|
||||
```bash
|
||||
yq m -x -d1 data1.yaml data3.yaml
|
||||
```
|
||||
will output:
|
||||
```yaml
|
||||
something: else
|
||||
---
|
||||
a: simple
|
||||
b: dog
|
||||
```
|
||||
|
||||
### Multiple Documents - merge into all documents
|
||||
Currently yq only has multi-document support for the _first_ document being merged into. The remaining yaml files will have their first document selected.
|
||||
|
||||
Given a data1.yaml file of:
|
||||
```yaml
|
||||
something: else
|
||||
---
|
||||
a: simple
|
||||
b: cat
|
||||
```
|
||||
and data3.yaml file of:
|
||||
```yaml
|
||||
b: dog
|
||||
```
|
||||
then
|
||||
```bash
|
||||
yq m -x -d'*' data1.yaml data3.yaml
|
||||
```
|
||||
will output:
|
||||
```yaml
|
||||
b: dog
|
||||
something: else
|
||||
---
|
||||
a: simple
|
||||
b: dog
|
||||
```
|
@ -1,96 +0,0 @@
|
||||
Paths can be prefixed using the 'prefix' command.
|
||||
The complete yaml content will be nested inside the new prefix path.
|
||||
|
||||
```
|
||||
yq p <yaml_file> <path>
|
||||
```
|
||||
|
||||
### To Stdout
|
||||
Given a data1.yaml file of:
|
||||
```yaml
|
||||
a: simple
|
||||
b: [1, 2]
|
||||
```
|
||||
then
|
||||
```bash
|
||||
yq p data1.yaml c
|
||||
```
|
||||
will output:
|
||||
```yaml
|
||||
c:
|
||||
a: simple
|
||||
b: [1, 2]
|
||||
```
|
||||
|
||||
### Arbitrary depth
|
||||
Given a data1.yaml file of:
|
||||
```yaml
|
||||
a:
|
||||
b: [1, 2]
|
||||
```
|
||||
then
|
||||
```bash
|
||||
yq p data1.yaml c.d
|
||||
```
|
||||
will output:
|
||||
```yaml
|
||||
c:
|
||||
d:
|
||||
a:
|
||||
b: [1, 2]
|
||||
```
|
||||
|
||||
### Updating files in-place
|
||||
Given a data1.yaml file of:
|
||||
```yaml
|
||||
a: simple
|
||||
b: [1, 2]
|
||||
```
|
||||
then
|
||||
```bash
|
||||
yq p -i data1.yaml c
|
||||
```
|
||||
will update the data1.yaml file so that the path 'c' is prefixed to all other paths.
|
||||
|
||||
### Multiple Documents - prefix a single document
|
||||
Given a data1.yaml file of:
|
||||
```yaml
|
||||
something: else
|
||||
---
|
||||
a: simple
|
||||
b: cat
|
||||
```
|
||||
then
|
||||
```bash
|
||||
yq p -d1 data1.yaml c
|
||||
```
|
||||
will output:
|
||||
```yaml
|
||||
something: else
|
||||
---
|
||||
c:
|
||||
a: simple
|
||||
b: cat
|
||||
```
|
||||
|
||||
### Multiple Documents - prefix all documents
|
||||
Given a data1.yaml file of:
|
||||
```yaml
|
||||
something: else
|
||||
---
|
||||
a: simple
|
||||
b: cat
|
||||
```
|
||||
then
|
||||
```bash
|
||||
yq p -d'*' data1.yaml c
|
||||
```
|
||||
will output:
|
||||
```yaml
|
||||
c:
|
||||
something: else
|
||||
---
|
||||
c:
|
||||
a: simple
|
||||
b: cat
|
||||
```
|
150
mkdocs/read.md
150
mkdocs/read.md
@ -1,150 +0,0 @@
|
||||
```
|
||||
yq r <yaml_file|json_file> <path>
|
||||
```
|
||||
|
||||
{!snippets/works_with_json.md!}
|
||||
|
||||
### Basic
|
||||
Given a sample.yaml file of:
|
||||
```yaml
|
||||
b:
|
||||
c: 2
|
||||
```
|
||||
then
|
||||
```bash
|
||||
yq r sample.yaml b.c
|
||||
```
|
||||
will output the value of '2'.
|
||||
|
||||
### From Stdin
|
||||
Given a sample.yaml file of:
|
||||
```bash
|
||||
cat sample.yaml | yq r - b.c
|
||||
```
|
||||
will output the value of '2'.
|
||||
|
||||
### Splat
|
||||
Given a sample.yaml file of:
|
||||
```yaml
|
||||
---
|
||||
bob:
|
||||
item1:
|
||||
cats: bananas
|
||||
item2:
|
||||
cats: apples
|
||||
thing:
|
||||
cats: oranges
|
||||
```
|
||||
then
|
||||
```bash
|
||||
yq r sample.yaml bob.*.cats
|
||||
```
|
||||
will output
|
||||
```yaml
|
||||
- bananas
|
||||
- apples
|
||||
- oranges
|
||||
```
|
||||
|
||||
### Prefix Splat
|
||||
Given a sample.yaml file of:
|
||||
```yaml
|
||||
---
|
||||
bob:
|
||||
item1:
|
||||
cats: bananas
|
||||
item2:
|
||||
cats: apples
|
||||
thing:
|
||||
cats: oranges
|
||||
```
|
||||
then
|
||||
```bash
|
||||
yq r sample.yaml bob.item*.cats
|
||||
```
|
||||
will output
|
||||
```yaml
|
||||
- bananas
|
||||
- apples
|
||||
```
|
||||
|
||||
### Multiple Documents - specify a single document
|
||||
Given a sample.yaml file of:
|
||||
```yaml
|
||||
something: else
|
||||
---
|
||||
b:
|
||||
c: 2
|
||||
```
|
||||
then
|
||||
```bash
|
||||
yq r -d1 sample.yaml b.c
|
||||
```
|
||||
will output the value of '2'.
|
||||
|
||||
### Multiple Documents - read all documents
|
||||
Reading all documents will return the result as an array. This can be converted to json using the '-j' flag if desired.
|
||||
|
||||
Given a sample.yaml file of:
|
||||
```yaml
|
||||
name: Fred
|
||||
age: 22
|
||||
---
|
||||
name: Stella
|
||||
age: 23
|
||||
---
|
||||
name: Android
|
||||
age: 232
|
||||
```
|
||||
then
|
||||
```bash
|
||||
yq r -d'*' sample.yaml name
|
||||
```
|
||||
will output:
|
||||
```
|
||||
- Fred
|
||||
- Stella
|
||||
- Android
|
||||
```
|
||||
|
||||
### Arrays
|
||||
You can give an index to access a specific element:
|
||||
e.g.: given a sample file of
|
||||
```yaml
|
||||
b:
|
||||
e:
|
||||
- name: fred
|
||||
value: 3
|
||||
- name: sam
|
||||
value: 4
|
||||
```
|
||||
then
|
||||
```
|
||||
yq r sample.yaml 'b.e[1].name'
|
||||
```
|
||||
will output 'sam'
|
||||
|
||||
Note that the path is in quotes to avoid the square brackets being interpreted by your shell.
|
||||
|
||||
### Array Splat
|
||||
e.g.: given a sample file of
|
||||
```yaml
|
||||
b:
|
||||
e:
|
||||
- name: fred
|
||||
value: 3
|
||||
- name: sam
|
||||
value: 4
|
||||
```
|
||||
then
|
||||
```
|
||||
yq r sample.yaml 'b.e[*].name'
|
||||
```
|
||||
will output:
|
||||
```
|
||||
- fred
|
||||
- sam
|
||||
```
|
||||
Note that the path is in quotes to avoid the square brackets being interpreted by your shell.
|
||||
|
||||
{!snippets/niche.md!}
|
@ -1,35 +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.
|
||||
|
||||
### 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
|
||||
```
|
@ -1 +0,0 @@
|
||||
This command can take a json file as input too, and will output yaml unless specified to export as json (-j)
|
250
mkdocs/write.md
250
mkdocs/write.md
@ -1,250 +0,0 @@
|
||||
```
|
||||
yq w <yaml_file> <path> <new value>
|
||||
```
|
||||
|
||||
### To Stdout
|
||||
Given a sample.yaml file of:
|
||||
```yaml
|
||||
b:
|
||||
c: 2
|
||||
```
|
||||
then
|
||||
```bash
|
||||
yq w sample.yaml b.c cat
|
||||
```
|
||||
will output:
|
||||
```yaml
|
||||
b:
|
||||
c: cat
|
||||
```
|
||||
|
||||
### From STDIN
|
||||
```bash
|
||||
cat sample.yaml | yq w - b.c blah
|
||||
```
|
||||
|
||||
### Adding new fields
|
||||
Any missing fields in the path will be created on the fly.
|
||||
|
||||
Given a sample.yaml file of:
|
||||
```yaml
|
||||
b:
|
||||
c: 2
|
||||
```
|
||||
then
|
||||
```bash
|
||||
yq w sample.yaml b.d[+] "new thing"
|
||||
```
|
||||
will output:
|
||||
```yaml
|
||||
b:
|
||||
c: cat
|
||||
d:
|
||||
- new thing
|
||||
```
|
||||
|
||||
### Splat
|
||||
Given a sample.yaml file of:
|
||||
```yaml
|
||||
---
|
||||
bob:
|
||||
item1:
|
||||
cats: bananas
|
||||
item2:
|
||||
cats: apples
|
||||
thing:
|
||||
cats: oranges
|
||||
```
|
||||
then
|
||||
```bash
|
||||
yq w sample.yaml bob.*.cats meow
|
||||
```
|
||||
will output:
|
||||
```yaml
|
||||
---
|
||||
bob:
|
||||
item1:
|
||||
cats: meow
|
||||
item2:
|
||||
cats: meow
|
||||
thing:
|
||||
cats: meow
|
||||
```
|
||||
|
||||
### Prefix Splat
|
||||
Given a sample.yaml file of:
|
||||
```yaml
|
||||
---
|
||||
bob:
|
||||
item1:
|
||||
cats: bananas
|
||||
item2:
|
||||
cats: apples
|
||||
thing:
|
||||
cats: oranges
|
||||
```
|
||||
then
|
||||
```bash
|
||||
yq w sample.yaml bob.item*.cats meow
|
||||
```
|
||||
will output:
|
||||
```yaml
|
||||
---
|
||||
bob:
|
||||
item1:
|
||||
cats: meow
|
||||
item2:
|
||||
cats: meow
|
||||
thing:
|
||||
cats: oranges
|
||||
```
|
||||
|
||||
### Array Splat
|
||||
Given a sample.yaml file of:
|
||||
```yaml
|
||||
---
|
||||
bob:
|
||||
- cats: bananas
|
||||
- cats: apples
|
||||
- cats: oranges
|
||||
```
|
||||
then
|
||||
```bash
|
||||
yq w sample.yaml bob[*].cats meow
|
||||
```
|
||||
will output:
|
||||
```yaml
|
||||
---
|
||||
bob:
|
||||
- cats: meow
|
||||
- cats: meow
|
||||
- cats: meow
|
||||
```
|
||||
|
||||
### Appending value to an array field
|
||||
Given a sample.yaml file of:
|
||||
```yaml
|
||||
b:
|
||||
c: 2
|
||||
d:
|
||||
- new thing
|
||||
- foo thing
|
||||
```
|
||||
then
|
||||
```bash
|
||||
yq w sample.yaml "b.d[+]" "bar thing"
|
||||
```
|
||||
will output:
|
||||
```yaml
|
||||
b:
|
||||
c: cat
|
||||
d:
|
||||
- new thing
|
||||
- foo thing
|
||||
- bar thing
|
||||
```
|
||||
|
||||
Note that the path is in quotes to avoid the square brackets being interpreted by your shell.
|
||||
|
||||
### Multiple Documents - update a single document
|
||||
Given a sample.yaml file of:
|
||||
```yaml
|
||||
something: else
|
||||
---
|
||||
b:
|
||||
c: 2
|
||||
```
|
||||
then
|
||||
```bash
|
||||
yq w -d1 sample.yaml b.c 5
|
||||
```
|
||||
will output:
|
||||
```yaml
|
||||
something: else
|
||||
---
|
||||
b:
|
||||
c: 5
|
||||
```
|
||||
|
||||
### Multiple Documents - update all documents
|
||||
Given a sample.yaml file of:
|
||||
```yaml
|
||||
something: else
|
||||
---
|
||||
b:
|
||||
c: 2
|
||||
```
|
||||
then
|
||||
```bash
|
||||
yq w -d'*' sample.yaml b.c 5
|
||||
```
|
||||
will output:
|
||||
```yaml
|
||||
something: else
|
||||
b:
|
||||
c: 5
|
||||
---
|
||||
b:
|
||||
c: 5
|
||||
```
|
||||
|
||||
Note that '*' is in quotes to avoid being interpreted by your shell.
|
||||
|
||||
### Updating files in-place
|
||||
Given a sample.yaml file of:
|
||||
```yaml
|
||||
b:
|
||||
c: 2
|
||||
```
|
||||
then
|
||||
```bash
|
||||
yq w -i sample.yaml b.c cat
|
||||
```
|
||||
will update the sample.yaml file so that the value of 'c' is cat.
|
||||
|
||||
|
||||
### Updating multiple values with a script
|
||||
Given a sample.yaml file of:
|
||||
```yaml
|
||||
b:
|
||||
c: 2
|
||||
e:
|
||||
- name: Billy Bob
|
||||
```
|
||||
and a script update_instructions.yaml of:
|
||||
```yaml
|
||||
b.c: 3
|
||||
b.e[+].name: Howdy Partner
|
||||
```
|
||||
then
|
||||
|
||||
```bash
|
||||
yq w -s update_instructions.yaml sample.yaml
|
||||
```
|
||||
will output:
|
||||
```yaml
|
||||
b:
|
||||
c: 3
|
||||
e:
|
||||
- name: Howdy Partner
|
||||
```
|
||||
|
||||
And, of course, you can pipe the instructions in using '-':
|
||||
```bash
|
||||
cat update_instructions.yaml | yq w -s - sample.yaml
|
||||
```
|
||||
|
||||
### Values starting with a hyphen (or dash)
|
||||
The flag terminator needs to be used to stop the app from attempting to parse the subsequent arguments as flags:
|
||||
|
||||
```
|
||||
yq w -- my.path -3
|
||||
```
|
||||
|
||||
will output
|
||||
```yaml
|
||||
my:
|
||||
path: -3
|
||||
```
|
||||
|
||||
{!snippets/niche.md!}
|
@ -1,54 +0,0 @@
|
||||
package marshal
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"strconv"
|
||||
|
||||
yaml "github.com/mikefarah/yaml/v2"
|
||||
)
|
||||
|
||||
type JsonConverter interface {
|
||||
JsonToString(context interface{}) (string, error)
|
||||
}
|
||||
|
||||
type jsonConverter struct{}
|
||||
|
||||
func NewJsonConverter() JsonConverter {
|
||||
return &jsonConverter{}
|
||||
}
|
||||
|
||||
func (j *jsonConverter) JsonToString(context interface{}) (string, error) {
|
||||
out, err := json.Marshal(j.toJSON(context))
|
||||
if err != nil {
|
||||
return "", fmt.Errorf("error printing yaml as json: %v", err)
|
||||
}
|
||||
return string(out), nil
|
||||
}
|
||||
|
||||
func (j *jsonConverter) toJSON(context interface{}) interface{} {
|
||||
switch context := context.(type) {
|
||||
case []interface{}:
|
||||
oldArray := context
|
||||
newArray := make([]interface{}, len(oldArray))
|
||||
for index, value := range oldArray {
|
||||
newArray[index] = j.toJSON(value)
|
||||
}
|
||||
return newArray
|
||||
case yaml.MapSlice:
|
||||
oldMap := context
|
||||
newMap := make(map[string]interface{})
|
||||
for _, entry := range oldMap {
|
||||
if str, ok := entry.Key.(string); ok {
|
||||
newMap[str] = j.toJSON(entry.Value)
|
||||
} else if i, ok := entry.Key.(int); ok {
|
||||
newMap[strconv.Itoa(i)] = j.toJSON(entry.Value)
|
||||
} else if b, ok := entry.Key.(bool); ok {
|
||||
newMap[strconv.FormatBool(b)] = j.toJSON(entry.Value)
|
||||
}
|
||||
}
|
||||
return newMap
|
||||
default:
|
||||
return context
|
||||
}
|
||||
}
|
@ -1,48 +0,0 @@
|
||||
package marshal
|
||||
|
||||
import (
|
||||
"testing"
|
||||
|
||||
"github.com/mikefarah/yq/v2/test"
|
||||
)
|
||||
|
||||
func TestJsonToString(t *testing.T) {
|
||||
var data = test.ParseData(`
|
||||
---
|
||||
b:
|
||||
c: 2
|
||||
`)
|
||||
got, _ := NewJsonConverter().JsonToString(data)
|
||||
test.AssertResult(t, "{\"b\":{\"c\":2}}", got)
|
||||
}
|
||||
|
||||
func TestJsonToString_withIntKey(t *testing.T) {
|
||||
var data = test.ParseData(`
|
||||
---
|
||||
b:
|
||||
2: c
|
||||
`)
|
||||
got, _ := NewJsonConverter().JsonToString(data)
|
||||
test.AssertResult(t, `{"b":{"2":"c"}}`, got)
|
||||
}
|
||||
|
||||
func TestJsonToString_withBoolKey(t *testing.T) {
|
||||
var data = test.ParseData(`
|
||||
---
|
||||
b:
|
||||
false: c
|
||||
`)
|
||||
got, _ := NewJsonConverter().JsonToString(data)
|
||||
test.AssertResult(t, `{"b":{"false":"c"}}`, got)
|
||||
}
|
||||
|
||||
func TestJsonToString_withArray(t *testing.T) {
|
||||
var data = test.ParseData(`
|
||||
---
|
||||
b:
|
||||
- item: one
|
||||
- item: two
|
||||
`)
|
||||
got, _ := NewJsonConverter().JsonToString(data)
|
||||
test.AssertResult(t, "{\"b\":[{\"item\":\"one\"},{\"item\":\"two\"}]}", got)
|
||||
}
|
@ -1,43 +0,0 @@
|
||||
package marshal
|
||||
|
||||
import (
|
||||
"strings"
|
||||
|
||||
yaml "github.com/mikefarah/yaml/v2"
|
||||
errors "github.com/pkg/errors"
|
||||
)
|
||||
|
||||
type YamlConverter interface {
|
||||
YamlToString(context interface{}, trimOutput bool) (string, error)
|
||||
}
|
||||
|
||||
type yamlConverter struct{}
|
||||
|
||||
func NewYamlConverter() YamlConverter {
|
||||
return &yamlConverter{}
|
||||
}
|
||||
|
||||
func (y *yamlConverter) YamlToString(context interface{}, trimOutput bool) (string, error) {
|
||||
switch context := context.(type) {
|
||||
case string:
|
||||
return context, nil
|
||||
default:
|
||||
return y.marshalContext(context, trimOutput)
|
||||
}
|
||||
}
|
||||
|
||||
func (y *yamlConverter) marshalContext(context interface{}, trimOutput bool) (string, error) {
|
||||
out, err := yaml.Marshal(context)
|
||||
|
||||
if err != nil {
|
||||
return "", errors.Wrap(err, "error printing yaml")
|
||||
}
|
||||
|
||||
outStr := string(out)
|
||||
// trim the trailing new line as it's easier for a script to add
|
||||
// it in if required than to remove it
|
||||
if trimOutput {
|
||||
return strings.Trim(outStr, "\n "), nil
|
||||
}
|
||||
return outStr, nil
|
||||
}
|
@ -1,52 +0,0 @@
|
||||
package marshal
|
||||
|
||||
import (
|
||||
"testing"
|
||||
|
||||
"github.com/mikefarah/yq/v2/test"
|
||||
)
|
||||
|
||||
func TestYamlToString(t *testing.T) {
|
||||
var raw = `b:
|
||||
c: 2
|
||||
`
|
||||
var data = test.ParseData(raw)
|
||||
got, _ := NewYamlConverter().YamlToString(data, false)
|
||||
test.AssertResult(t, raw, got)
|
||||
}
|
||||
|
||||
func TestYamlToString_withTrim(t *testing.T) {
|
||||
var raw = `b:
|
||||
c: 2`
|
||||
var data = test.ParseData(raw)
|
||||
got, _ := NewYamlConverter().YamlToString(data, true)
|
||||
test.AssertResult(t, raw, got)
|
||||
}
|
||||
|
||||
func TestYamlToString_withIntKey(t *testing.T) {
|
||||
var raw = `b:
|
||||
2: c
|
||||
`
|
||||
var data = test.ParseData(raw)
|
||||
got, _ := NewYamlConverter().YamlToString(data, false)
|
||||
test.AssertResult(t, raw, got)
|
||||
}
|
||||
|
||||
func TestYamlToString_withBoolKey(t *testing.T) {
|
||||
var raw = `b:
|
||||
false: c
|
||||
`
|
||||
var data = test.ParseData(raw)
|
||||
got, _ := NewYamlConverter().YamlToString(data, false)
|
||||
test.AssertResult(t, raw, got)
|
||||
}
|
||||
|
||||
func TestYamlToString_withArray(t *testing.T) {
|
||||
var raw = `b:
|
||||
- item: one
|
||||
- item: two
|
||||
`
|
||||
var data = test.ParseData(raw)
|
||||
got, _ := NewYamlConverter().YamlToString(data, false)
|
||||
test.AssertResult(t, raw, got)
|
||||
}
|
@ -1,376 +1,249 @@
|
||||
package yqlib
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"reflect"
|
||||
"strconv"
|
||||
"strings"
|
||||
|
||||
yaml "github.com/mikefarah/yaml/v2"
|
||||
logging "gopkg.in/op/go-logging.v1"
|
||||
errors "github.com/pkg/errors"
|
||||
yaml "gopkg.in/yaml.v3"
|
||||
)
|
||||
|
||||
type DataNavigator interface {
|
||||
ReadChildValue(child interface{}, remainingPaths []string) (interface{}, error)
|
||||
UpdatedChildValue(child interface{}, remainingPaths []string, value interface{}) interface{}
|
||||
DeleteChildValue(child interface{}, remainingPaths []string) (interface{}, error)
|
||||
Traverse(value *yaml.Node, path []string) error
|
||||
}
|
||||
|
||||
type navigator struct {
|
||||
log *logging.Logger
|
||||
navigationStrategy NavigationStrategy
|
||||
}
|
||||
|
||||
func NewDataNavigator(l *logging.Logger) DataNavigator {
|
||||
func NewDataNavigator(NavigationStrategy NavigationStrategy) DataNavigator {
|
||||
return &navigator{
|
||||
log: l,
|
||||
navigationStrategy: NavigationStrategy,
|
||||
}
|
||||
}
|
||||
|
||||
func (n *navigator) ReadChildValue(child interface{}, remainingPaths []string) (interface{}, error) {
|
||||
if len(remainingPaths) == 0 {
|
||||
return child, nil
|
||||
func (n *navigator) Traverse(value *yaml.Node, path []string) error {
|
||||
realValue := value
|
||||
emptyArray := make([]interface{}, 0)
|
||||
if realValue.Kind == yaml.DocumentNode {
|
||||
log.Debugf("its a document! returning the first child")
|
||||
return n.doTraverse(value.Content[0], "", path, emptyArray)
|
||||
}
|
||||
return n.recurse(child, remainingPaths[0], remainingPaths[1:])
|
||||
return n.doTraverse(value, "", path, emptyArray)
|
||||
}
|
||||
|
||||
func (n *navigator) UpdatedChildValue(child interface{}, remainingPaths []string, value interface{}) interface{} {
|
||||
if len(remainingPaths) == 0 {
|
||||
return value
|
||||
}
|
||||
n.log.Debugf("UpdatedChildValue for child %v with path %v to set value %v", child, remainingPaths, value)
|
||||
n.log.Debugf("type of child is %v", reflect.TypeOf(child))
|
||||
|
||||
switch child := child.(type) {
|
||||
case nil:
|
||||
if remainingPaths[0] == "+" || remainingPaths[0] == "*" {
|
||||
return n.writeArray(child, remainingPaths, value)
|
||||
}
|
||||
case []interface{}:
|
||||
_, nextIndexErr := strconv.ParseInt(remainingPaths[0], 10, 64)
|
||||
arrayCommand := nextIndexErr == nil || remainingPaths[0] == "+" || remainingPaths[0] == "*"
|
||||
if arrayCommand {
|
||||
return n.writeArray(child, remainingPaths, value)
|
||||
}
|
||||
}
|
||||
return n.writeMap(child, remainingPaths, value)
|
||||
}
|
||||
|
||||
func (n *navigator) DeleteChildValue(child interface{}, remainingPaths []string) (interface{}, error) {
|
||||
n.log.Debugf("DeleteChildValue for %v for %v\n", remainingPaths, child)
|
||||
if len(remainingPaths) == 0 {
|
||||
return child, nil
|
||||
}
|
||||
var head = remainingPaths[0]
|
||||
var tail = remainingPaths[1:]
|
||||
switch child := child.(type) {
|
||||
case yaml.MapSlice:
|
||||
return n.deleteMap(child, remainingPaths)
|
||||
case []interface{}:
|
||||
if head == "*" {
|
||||
return n.deleteArraySplat(child, tail)
|
||||
}
|
||||
index, err := strconv.ParseInt(head, 10, 64)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("error accessing array: %v", err)
|
||||
}
|
||||
return n.deleteArray(child, remainingPaths, index)
|
||||
}
|
||||
return child, nil
|
||||
}
|
||||
|
||||
func (n *navigator) recurse(value interface{}, head string, tail []string) (interface{}, error) {
|
||||
switch value := value.(type) {
|
||||
case []interface{}:
|
||||
if head == "*" {
|
||||
return n.readArraySplat(value, tail)
|
||||
}
|
||||
index, err := strconv.ParseInt(head, 10, 64)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("error accessing array: %v", err)
|
||||
}
|
||||
return n.readArray(value, index, tail)
|
||||
case yaml.MapSlice:
|
||||
return n.readMap(value, head, tail)
|
||||
default:
|
||||
return nil, nil
|
||||
}
|
||||
}
|
||||
|
||||
func (n *navigator) 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 (n *navigator) entriesInSlice(context yaml.MapSlice, key string) []*yaml.MapItem {
|
||||
var matches = make([]*yaml.MapItem, 0)
|
||||
for idx := range context {
|
||||
var entry = &context[idx]
|
||||
if n.matchesKey(key, entry.Key) {
|
||||
matches = append(matches, entry)
|
||||
}
|
||||
}
|
||||
return matches
|
||||
}
|
||||
|
||||
func (n *navigator) getMapSlice(context interface{}) yaml.MapSlice {
|
||||
var mapSlice yaml.MapSlice
|
||||
switch context := context.(type) {
|
||||
case yaml.MapSlice:
|
||||
mapSlice = context
|
||||
default:
|
||||
mapSlice = make(yaml.MapSlice, 0)
|
||||
}
|
||||
return mapSlice
|
||||
}
|
||||
|
||||
func (n *navigator) getArray(context interface{}) (array []interface{}, ok bool) {
|
||||
switch context := context.(type) {
|
||||
case []interface{}:
|
||||
array = context
|
||||
ok = true
|
||||
default:
|
||||
array = make([]interface{}, 0)
|
||||
ok = false
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
func (n *navigator) writeMap(context interface{}, paths []string, value interface{}) interface{} {
|
||||
n.log.Debugf("writeMap with path %v for %v to set value %v\n", paths, context, value)
|
||||
|
||||
mapSlice := n.getMapSlice(context)
|
||||
|
||||
if len(paths) == 0 {
|
||||
return context
|
||||
}
|
||||
|
||||
children := n.entriesInSlice(mapSlice, paths[0])
|
||||
|
||||
if len(children) == 0 && paths[0] == "*" {
|
||||
n.log.Debugf("\tNo matches, return map as is")
|
||||
return context
|
||||
}
|
||||
|
||||
if len(children) == 0 {
|
||||
newChild := yaml.MapItem{Key: paths[0]}
|
||||
mapSlice = append(mapSlice, newChild)
|
||||
children = n.entriesInSlice(mapSlice, paths[0])
|
||||
n.log.Debugf("\tAppended child at %v for mapSlice %v\n", paths[0], mapSlice)
|
||||
}
|
||||
|
||||
remainingPaths := paths[1:]
|
||||
for _, child := range children {
|
||||
child.Value = n.UpdatedChildValue(child.Value, remainingPaths, value)
|
||||
}
|
||||
n.log.Debugf("\tReturning mapSlice %v\n", mapSlice)
|
||||
return mapSlice
|
||||
}
|
||||
|
||||
func (n *navigator) writeArray(context interface{}, paths []string, value interface{}) []interface{} {
|
||||
n.log.Debugf("writeArray with path %v for %v to set value %v\n", paths, context, value)
|
||||
array, _ := n.getArray(context)
|
||||
|
||||
if len(paths) == 0 {
|
||||
return array
|
||||
}
|
||||
|
||||
n.log.Debugf("\tarray %v\n", array)
|
||||
|
||||
rawIndex := paths[0]
|
||||
remainingPaths := paths[1:]
|
||||
var index int64
|
||||
// the append array indicator
|
||||
if rawIndex == "+" {
|
||||
index = int64(len(array))
|
||||
} else if rawIndex == "*" {
|
||||
for index, oldChild := range array {
|
||||
array[index] = n.UpdatedChildValue(oldChild, remainingPaths, value)
|
||||
}
|
||||
return array
|
||||
} else {
|
||||
index, _ = strconv.ParseInt(rawIndex, 10, 64) // nolint
|
||||
// writeArray is only called by UpdatedChildValue which handles parsing the
|
||||
// index, as such this renders this dead code.
|
||||
}
|
||||
|
||||
for index >= int64(len(array)) {
|
||||
array = append(array, nil)
|
||||
}
|
||||
currentChild := array[index]
|
||||
|
||||
n.log.Debugf("\tcurrentChild %v\n", currentChild)
|
||||
|
||||
array[index] = n.UpdatedChildValue(currentChild, remainingPaths, value)
|
||||
n.log.Debugf("\tReturning array %v\n", array)
|
||||
return array
|
||||
}
|
||||
|
||||
func (n *navigator) readMap(context yaml.MapSlice, head string, tail []string) (interface{}, error) {
|
||||
n.log.Debugf("readingMap %v with key %v\n", context, head)
|
||||
if head == "*" {
|
||||
return n.readMapSplat(context, tail)
|
||||
}
|
||||
|
||||
entries := n.entriesInSlice(context, head)
|
||||
if len(entries) == 1 {
|
||||
return n.calculateValue(entries[0].Value, tail)
|
||||
} else if len(entries) == 0 {
|
||||
return nil, nil
|
||||
}
|
||||
var errInIdx error
|
||||
values := make([]interface{}, len(entries))
|
||||
for idx, entry := range entries {
|
||||
values[idx], errInIdx = n.calculateValue(entry.Value, tail)
|
||||
if errInIdx != nil {
|
||||
n.log.Errorf("Error updating index %v in %v", idx, context)
|
||||
return nil, errInIdx
|
||||
}
|
||||
|
||||
}
|
||||
return values, nil
|
||||
}
|
||||
|
||||
func (n *navigator) readMapSplat(context yaml.MapSlice, tail []string) (interface{}, error) {
|
||||
var newArray = make([]interface{}, len(context))
|
||||
var i = 0
|
||||
for _, entry := range context {
|
||||
func (n *navigator) doTraverse(value *yaml.Node, head string, tail []string, pathStack []interface{}) error {
|
||||
log.Debug("head %v", head)
|
||||
DebugNode(value)
|
||||
var errorDeepSplatting error
|
||||
if head == "**" && value.Kind != yaml.ScalarNode {
|
||||
errorDeepSplatting = n.recurse(value, head, tail, pathStack)
|
||||
// ignore errors here, we are deep splatting so we may accidently give a string key
|
||||
// to an array sequence
|
||||
if len(tail) > 0 {
|
||||
val, err := n.recurse(entry.Value, tail[0], tail[1:])
|
||||
if err != nil {
|
||||
return nil, err
|
||||
_ = n.recurse(value, tail[0], tail[1:], pathStack)
|
||||
}
|
||||
newArray[i] = val
|
||||
} else {
|
||||
newArray[i] = entry.Value
|
||||
}
|
||||
i++
|
||||
}
|
||||
return newArray, nil
|
||||
return errorDeepSplatting
|
||||
}
|
||||
|
||||
func (n *navigator) readArray(array []interface{}, head int64, tail []string) (interface{}, error) {
|
||||
if head >= int64(len(array)) {
|
||||
return nil, nil
|
||||
}
|
||||
|
||||
value := array[head]
|
||||
return n.calculateValue(value, tail)
|
||||
}
|
||||
|
||||
func (n *navigator) readArraySplat(array []interface{}, tail []string) (interface{}, error) {
|
||||
var newArray = make([]interface{}, len(array))
|
||||
for index, value := range array {
|
||||
val, err := n.calculateValue(value, tail)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
newArray[index] = val
|
||||
}
|
||||
return newArray, nil
|
||||
}
|
||||
|
||||
func (n *navigator) calculateValue(value interface{}, tail []string) (interface{}, error) {
|
||||
if len(tail) > 0 {
|
||||
return n.recurse(value, tail[0], tail[1:])
|
||||
log.Debugf("diving into %v", tail[0])
|
||||
DebugNode(value)
|
||||
return n.recurse(value, tail[0], tail[1:], pathStack)
|
||||
}
|
||||
return value, nil
|
||||
return n.navigationStrategy.Visit(NewNodeContext(value, head, tail, pathStack))
|
||||
}
|
||||
|
||||
func (n *navigator) deleteMap(context interface{}, paths []string) (yaml.MapSlice, error) {
|
||||
n.log.Debugf("deleteMap for %v for %v\n", paths, context)
|
||||
|
||||
mapSlice := n.getMapSlice(context)
|
||||
|
||||
if len(paths) == 0 {
|
||||
return mapSlice, nil
|
||||
func (n *navigator) getOrReplace(original *yaml.Node, expectedKind yaml.Kind) *yaml.Node {
|
||||
if original.Kind != expectedKind {
|
||||
log.Debug("wanted %v but it was %v, overriding", expectedKind, original.Kind)
|
||||
return &yaml.Node{Kind: expectedKind}
|
||||
}
|
||||
return original
|
||||
}
|
||||
|
||||
var index int
|
||||
var child yaml.MapItem
|
||||
for index, child = range mapSlice {
|
||||
if n.matchesKey(paths[0], child.Key) {
|
||||
n.log.Debugf("\tMatched [%v] with [%v] at index %v", paths[0], child.Key, index)
|
||||
var badDelete error
|
||||
mapSlice, badDelete = n.deleteEntryInMap(mapSlice, child, index, paths)
|
||||
if badDelete != nil {
|
||||
return nil, badDelete
|
||||
func (n *navigator) recurse(value *yaml.Node, head string, tail []string, pathStack []interface{}) error {
|
||||
log.Debug("recursing, processing %v", head)
|
||||
switch value.Kind {
|
||||
case yaml.MappingNode:
|
||||
log.Debug("its a map with %v entries", len(value.Content)/2)
|
||||
return n.recurseMap(value, head, tail, pathStack)
|
||||
case yaml.SequenceNode:
|
||||
log.Debug("its a sequence of %v things!", len(value.Content))
|
||||
if n.navigationStrategy.GetPathParser().IsPathExpression(head) {
|
||||
return n.splatArray(value, head, tail, pathStack)
|
||||
} else if head == "+" {
|
||||
return n.appendArray(value, head, tail, pathStack)
|
||||
}
|
||||
return n.recurseArray(value, head, tail, pathStack)
|
||||
case yaml.AliasNode:
|
||||
log.Debug("its an alias!")
|
||||
DebugNode(value.Alias)
|
||||
if n.navigationStrategy.FollowAlias(NewNodeContext(value, head, tail, pathStack)) {
|
||||
log.Debug("following the alias")
|
||||
return n.recurse(value.Alias, head, tail, pathStack)
|
||||
}
|
||||
return nil
|
||||
default:
|
||||
return nil
|
||||
}
|
||||
}
|
||||
|
||||
return mapSlice, nil
|
||||
|
||||
}
|
||||
|
||||
func (n *navigator) deleteEntryInMap(original yaml.MapSlice, child yaml.MapItem, index int, paths []string) (yaml.MapSlice, error) {
|
||||
remainingPaths := paths[1:]
|
||||
|
||||
var newSlice yaml.MapSlice
|
||||
if len(remainingPaths) > 0 {
|
||||
newChild := yaml.MapItem{Key: child.Key}
|
||||
var errorDeleting error
|
||||
newChild.Value, errorDeleting = n.DeleteChildValue(child.Value, remainingPaths)
|
||||
if errorDeleting != nil {
|
||||
return nil, errorDeleting
|
||||
}
|
||||
|
||||
newSlice = make(yaml.MapSlice, len(original))
|
||||
for i := range original {
|
||||
item := original[i]
|
||||
if i == index {
|
||||
item = newChild
|
||||
}
|
||||
newSlice[i] = item
|
||||
}
|
||||
func (n *navigator) recurseMap(value *yaml.Node, head string, tail []string, pathStack []interface{}) error {
|
||||
traversedEntry := false
|
||||
errorVisiting := n.visitMatchingEntries(value, head, tail, pathStack, func(contents []*yaml.Node, indexInMap int) error {
|
||||
log.Debug("recurseMap: visitMatchingEntries")
|
||||
n.navigationStrategy.DebugVisitedNodes()
|
||||
newPathStack := append(pathStack, contents[indexInMap].Value)
|
||||
log.Debug("appended %v", contents[indexInMap].Value)
|
||||
n.navigationStrategy.DebugVisitedNodes()
|
||||
log.Debug("should I traverse? head: %v, path: %v", head, pathStackToString(newPathStack))
|
||||
DebugNode(value)
|
||||
if n.navigationStrategy.ShouldTraverse(NewNodeContext(contents[indexInMap+1], head, tail, newPathStack), contents[indexInMap].Value) {
|
||||
log.Debug("recurseMap: Going to traverse")
|
||||
traversedEntry = true
|
||||
// contents[indexInMap+1] = n.getOrReplace(contents[indexInMap+1], guessKind(head, tail, contents[indexInMap+1].Kind))
|
||||
errorTraversing := n.doTraverse(contents[indexInMap+1], head, tail, newPathStack)
|
||||
log.Debug("recurseMap: Finished traversing")
|
||||
n.navigationStrategy.DebugVisitedNodes()
|
||||
return errorTraversing
|
||||
} else {
|
||||
// Delete item from slice at index
|
||||
newSlice = append(original[:index], original[index+1:]...)
|
||||
n.log.Debugf("\tDeleted item index %d from original", index)
|
||||
log.Debug("nope not traversing")
|
||||
}
|
||||
return nil
|
||||
})
|
||||
|
||||
if errorVisiting != nil {
|
||||
return errorVisiting
|
||||
}
|
||||
|
||||
n.log.Debugf("\tReturning original %v\n", original)
|
||||
return newSlice, nil
|
||||
if traversedEntry || n.navigationStrategy.GetPathParser().IsPathExpression(head) || !n.navigationStrategy.AutoCreateMap(NewNodeContext(value, head, tail, pathStack)) {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (n *navigator) deleteArraySplat(array []interface{}, tail []string) (interface{}, error) {
|
||||
n.log.Debugf("deleteArraySplat for %v for %v\n", tail, array)
|
||||
var newArray = make([]interface{}, len(array))
|
||||
for index, value := range array {
|
||||
val, err := n.DeleteChildValue(value, tail)
|
||||
mapEntryKey := yaml.Node{Value: head, Kind: yaml.ScalarNode}
|
||||
value.Content = append(value.Content, &mapEntryKey)
|
||||
mapEntryValue := yaml.Node{Kind: guessKind(head, tail, 0)}
|
||||
value.Content = append(value.Content, &mapEntryValue)
|
||||
log.Debug("adding new node %v", head)
|
||||
return n.doTraverse(&mapEntryValue, head, tail, append(pathStack, head))
|
||||
}
|
||||
|
||||
// need to pass the node in, as it may be aliased
|
||||
type mapVisitorFn func(contents []*yaml.Node, index int) error
|
||||
|
||||
func (n *navigator) visitDirectMatchingEntries(node *yaml.Node, head string, tail []string, pathStack []interface{}, visit mapVisitorFn) error {
|
||||
var contents = node.Content
|
||||
for index := 0; index < len(contents); index = index + 2 {
|
||||
content := contents[index]
|
||||
|
||||
log.Debug("index %v, checking %v, %v", index, content.Value, content.Tag)
|
||||
n.navigationStrategy.DebugVisitedNodes()
|
||||
errorVisiting := visit(contents, index)
|
||||
if errorVisiting != nil {
|
||||
return errorVisiting
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (n *navigator) visitMatchingEntries(node *yaml.Node, head string, tail []string, pathStack []interface{}, visit mapVisitorFn) error {
|
||||
var contents = node.Content
|
||||
log.Debug("visitMatchingEntries %v", head)
|
||||
DebugNode(node)
|
||||
// value.Content is a concatenated array of key, value,
|
||||
// so keys are in the even indexes, values in odd.
|
||||
// merge aliases are defined first, but we only want to traverse them
|
||||
// if we don't find a match directly on this node first.
|
||||
errorVisitedDirectEntries := n.visitDirectMatchingEntries(node, head, tail, pathStack, visit)
|
||||
|
||||
if errorVisitedDirectEntries != nil || !n.navigationStrategy.FollowAlias(NewNodeContext(node, head, tail, pathStack)) {
|
||||
return errorVisitedDirectEntries
|
||||
}
|
||||
return n.visitAliases(contents, head, tail, pathStack, visit)
|
||||
}
|
||||
|
||||
func (n *navigator) visitAliases(contents []*yaml.Node, head string, tail []string, pathStack []interface{}, visit mapVisitorFn) error {
|
||||
// merge aliases are defined first, but we only want to traverse them
|
||||
// if we don't find a match on this node first.
|
||||
// traverse them backwards so that the last alias overrides the preceding.
|
||||
// a node can either be
|
||||
// an alias to one other node (e.g. <<: *blah)
|
||||
// or a sequence of aliases (e.g. <<: [*blah, *foo])
|
||||
log.Debug("checking for aliases")
|
||||
for index := len(contents) - 2; index >= 0; index = index - 2 {
|
||||
|
||||
if contents[index+1].Kind == yaml.AliasNode {
|
||||
valueNode := contents[index+1]
|
||||
log.Debug("found an alias")
|
||||
DebugNode(contents[index])
|
||||
DebugNode(valueNode)
|
||||
|
||||
errorInAlias := n.visitMatchingEntries(valueNode.Alias, head, tail, pathStack, visit)
|
||||
if errorInAlias != nil {
|
||||
return errorInAlias
|
||||
}
|
||||
} else if contents[index+1].Kind == yaml.SequenceNode {
|
||||
// could be an array of aliases...
|
||||
errorVisitingAliasSeq := n.visitAliasSequence(contents[index+1].Content, head, tail, pathStack, visit)
|
||||
if errorVisitingAliasSeq != nil {
|
||||
return errorVisitingAliasSeq
|
||||
}
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (n *navigator) visitAliasSequence(possibleAliasArray []*yaml.Node, head string, tail []string, pathStack []interface{}, visit mapVisitorFn) error {
|
||||
// need to search this backwards too, so that aliases defined last override the preceding.
|
||||
for aliasIndex := len(possibleAliasArray) - 1; aliasIndex >= 0; aliasIndex = aliasIndex - 1 {
|
||||
child := possibleAliasArray[aliasIndex]
|
||||
if child.Kind == yaml.AliasNode {
|
||||
log.Debug("found an alias")
|
||||
DebugNode(child)
|
||||
errorInAlias := n.visitMatchingEntries(child.Alias, head, tail, pathStack, visit)
|
||||
if errorInAlias != nil {
|
||||
return errorInAlias
|
||||
}
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (n *navigator) splatArray(value *yaml.Node, head string, tail []string, pathStack []interface{}) error {
|
||||
for index, childValue := range value.Content {
|
||||
log.Debug("processing")
|
||||
DebugNode(childValue)
|
||||
childValue = n.getOrReplace(childValue, guessKind(head, tail, childValue.Kind))
|
||||
|
||||
newPathStack := append(pathStack, index)
|
||||
if n.navigationStrategy.ShouldTraverse(NewNodeContext(childValue, head, tail, newPathStack), childValue.Value) {
|
||||
var err = n.doTraverse(childValue, head, tail, newPathStack)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
return err
|
||||
}
|
||||
newArray[index] = val
|
||||
}
|
||||
return newArray, nil
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (n *navigator) deleteArray(array []interface{}, paths []string, index int64) (interface{}, error) {
|
||||
n.log.Debugf("deleteArray for %v for %v\n", paths, array)
|
||||
|
||||
if index >= int64(len(array)) {
|
||||
return array, nil
|
||||
func (n *navigator) appendArray(value *yaml.Node, head string, tail []string, pathStack []interface{}) error {
|
||||
var newNode = yaml.Node{Kind: guessKind(head, tail, 0)}
|
||||
value.Content = append(value.Content, &newNode)
|
||||
log.Debug("appending a new node, %v", value.Content)
|
||||
return n.doTraverse(&newNode, head, tail, append(pathStack, len(value.Content)-1))
|
||||
}
|
||||
|
||||
remainingPaths := paths[1:]
|
||||
if len(remainingPaths) > 0 {
|
||||
// recurse into the array element at index
|
||||
var errorDeleting error
|
||||
array[index], errorDeleting = n.deleteMap(array[index], remainingPaths)
|
||||
if errorDeleting != nil {
|
||||
return nil, errorDeleting
|
||||
func (n *navigator) recurseArray(value *yaml.Node, head string, tail []string, pathStack []interface{}) error {
|
||||
var index, err = strconv.ParseInt(head, 10, 64) // nolint
|
||||
if err != nil {
|
||||
return errors.Wrapf(err, "Error parsing array index '%v' for '%v'", head, pathStackToString(pathStack))
|
||||
}
|
||||
|
||||
} else {
|
||||
// Delete the array element at index
|
||||
array = append(array[:index], array[index+1:]...)
|
||||
n.log.Debugf("\tDeleted item index %d from array, leaving %v", index, array)
|
||||
for int64(len(value.Content)) <= index {
|
||||
value.Content = append(value.Content, &yaml.Node{Kind: guessKind(head, tail, 0)})
|
||||
}
|
||||
|
||||
n.log.Debugf("\tReturning array: %v\n", array)
|
||||
return array, nil
|
||||
value.Content[index] = n.getOrReplace(value.Content[index], guessKind(head, tail, value.Content[index].Kind))
|
||||
|
||||
return n.doTraverse(value.Content[index], head, tail, append(pathStack, index))
|
||||
}
|
||||
|
@ -1,397 +1 @@
|
||||
package yqlib
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"sort"
|
||||
"testing"
|
||||
|
||||
"github.com/mikefarah/yq/v2/test"
|
||||
logging "gopkg.in/op/go-logging.v1"
|
||||
)
|
||||
|
||||
func TestDataNavigator(t *testing.T) {
|
||||
var log = logging.MustGetLogger("yq")
|
||||
subject := NewDataNavigator(log)
|
||||
|
||||
t.Run("TestReadMap_simple", func(t *testing.T) {
|
||||
var data = test.ParseData(`
|
||||
---
|
||||
b:
|
||||
c: 2
|
||||
`)
|
||||
got, _ := subject.ReadChildValue(data, []string{"b", "c"})
|
||||
test.AssertResult(t, 2, got)
|
||||
})
|
||||
|
||||
t.Run("TestReadMap_numberKey", func(t *testing.T) {
|
||||
var data = test.ParseData(`
|
||||
---
|
||||
200: things
|
||||
`)
|
||||
got, _ := subject.ReadChildValue(data, []string{"200"})
|
||||
test.AssertResult(t, "things", got)
|
||||
})
|
||||
|
||||
t.Run("TestReadMap_splat", func(t *testing.T) {
|
||||
var data = test.ParseData(`
|
||||
---
|
||||
mapSplat:
|
||||
item1: things
|
||||
item2: whatever
|
||||
otherThing: cat
|
||||
`)
|
||||
res, _ := subject.ReadChildValue(data, []string{"mapSplat", "*"})
|
||||
test.AssertResult(t, "[things whatever cat]", fmt.Sprintf("%v", res))
|
||||
})
|
||||
|
||||
t.Run("TestReadMap_prefixSplat", func(t *testing.T) {
|
||||
var data = test.ParseData(`
|
||||
---
|
||||
mapSplat:
|
||||
item1: things
|
||||
item2: whatever
|
||||
otherThing: cat
|
||||
`)
|
||||
res, _ := subject.ReadChildValue(data, []string{"mapSplat", "item*"})
|
||||
test.AssertResult(t, "[things whatever]", fmt.Sprintf("%v", res))
|
||||
})
|
||||
|
||||
t.Run("TestReadMap_deep_splat", func(t *testing.T) {
|
||||
var data = test.ParseData(`
|
||||
---
|
||||
mapSplatDeep:
|
||||
item1:
|
||||
cats: bananas
|
||||
item2:
|
||||
cats: apples
|
||||
`)
|
||||
|
||||
res, _ := subject.ReadChildValue(data, []string{"mapSplatDeep", "*", "cats"})
|
||||
result := res.([]interface{})
|
||||
var actual = []string{result[0].(string), result[1].(string)}
|
||||
sort.Strings(actual)
|
||||
test.AssertResult(t, "[apples bananas]", fmt.Sprintf("%v", actual))
|
||||
})
|
||||
|
||||
t.Run("TestReadMap_key_doesnt_exist", func(t *testing.T) {
|
||||
var data = test.ParseData(`
|
||||
---
|
||||
b:
|
||||
c: 2
|
||||
`)
|
||||
got, _ := subject.ReadChildValue(data, []string{"b", "x", "f", "c"})
|
||||
test.AssertResult(t, nil, got)
|
||||
})
|
||||
|
||||
t.Run("TestReadMap_recurse_against_string", func(t *testing.T) {
|
||||
var data = test.ParseData(`
|
||||
---
|
||||
a: cat
|
||||
`)
|
||||
got, _ := subject.ReadChildValue(data, []string{"a", "b"})
|
||||
test.AssertResult(t, nil, got)
|
||||
})
|
||||
|
||||
t.Run("TestReadMap_with_array", func(t *testing.T) {
|
||||
var data = test.ParseData(`
|
||||
---
|
||||
b:
|
||||
d:
|
||||
- 3
|
||||
- 4
|
||||
`)
|
||||
got, _ := subject.ReadChildValue(data, []string{"b", "d", "1"})
|
||||
test.AssertResult(t, 4, got)
|
||||
})
|
||||
|
||||
t.Run("TestReadMap_with_array_and_bad_index", func(t *testing.T) {
|
||||
var data = test.ParseData(`
|
||||
---
|
||||
b:
|
||||
d:
|
||||
- 3
|
||||
- 4
|
||||
`)
|
||||
_, err := subject.ReadChildValue(data, []string{"b", "d", "x"})
|
||||
if err == nil {
|
||||
t.Fatal("Expected error due to invalid path")
|
||||
}
|
||||
expectedOutput := `error accessing array: strconv.ParseInt: parsing "x": invalid syntax`
|
||||
test.AssertResult(t, expectedOutput, err.Error())
|
||||
})
|
||||
|
||||
t.Run("TestReadMap_with_mapsplat_array_and_bad_index", func(t *testing.T) {
|
||||
var data = test.ParseData(`
|
||||
---
|
||||
b:
|
||||
d:
|
||||
e:
|
||||
- 3
|
||||
- 4
|
||||
f:
|
||||
- 1
|
||||
- 2
|
||||
`)
|
||||
_, err := subject.ReadChildValue(data, []string{"b", "d", "*", "x"})
|
||||
if err == nil {
|
||||
t.Fatal("Expected error due to invalid path")
|
||||
}
|
||||
expectedOutput := `error accessing array: strconv.ParseInt: parsing "x": invalid syntax`
|
||||
test.AssertResult(t, expectedOutput, err.Error())
|
||||
})
|
||||
|
||||
t.Run("TestReadMap_with_arraysplat_map_array_and_bad_index", func(t *testing.T) {
|
||||
var data = test.ParseData(`
|
||||
---
|
||||
b:
|
||||
d:
|
||||
- names:
|
||||
- fred
|
||||
- smith
|
||||
- names:
|
||||
- sam
|
||||
- bo
|
||||
`)
|
||||
_, err := subject.ReadChildValue(data, []string{"b", "d", "*", "names", "x"})
|
||||
if err == nil {
|
||||
t.Fatal("Expected error due to invalid path")
|
||||
}
|
||||
expectedOutput := `error accessing array: strconv.ParseInt: parsing "x": invalid syntax`
|
||||
test.AssertResult(t, expectedOutput, err.Error())
|
||||
})
|
||||
|
||||
t.Run("TestReadMap_with_array_out_of_bounds", func(t *testing.T) {
|
||||
var data = test.ParseData(`
|
||||
---
|
||||
b:
|
||||
d:
|
||||
- 3
|
||||
- 4
|
||||
`)
|
||||
got, _ := subject.ReadChildValue(data, []string{"b", "d", "3"})
|
||||
test.AssertResult(t, nil, got)
|
||||
})
|
||||
|
||||
t.Run("TestReadMap_with_array_out_of_bounds_by_1", func(t *testing.T) {
|
||||
var data = test.ParseData(`
|
||||
---
|
||||
b:
|
||||
d:
|
||||
- 3
|
||||
- 4
|
||||
`)
|
||||
got, _ := subject.ReadChildValue(data, []string{"b", "d", "2"})
|
||||
test.AssertResult(t, nil, got)
|
||||
})
|
||||
|
||||
t.Run("TestReadMap_with_array_splat", func(t *testing.T) {
|
||||
var data = test.ParseData(`
|
||||
e:
|
||||
-
|
||||
name: Fred
|
||||
thing: cat
|
||||
-
|
||||
name: Sam
|
||||
thing: dog
|
||||
`)
|
||||
got, _ := subject.ReadChildValue(data, []string{"e", "*", "name"})
|
||||
test.AssertResult(t, "[Fred Sam]", fmt.Sprintf("%v", got))
|
||||
})
|
||||
|
||||
t.Run("TestWrite_really_simple", func(t *testing.T) {
|
||||
var data = test.ParseData(`
|
||||
b: 2
|
||||
`)
|
||||
|
||||
updated := subject.UpdatedChildValue(data, []string{"b"}, "4")
|
||||
test.AssertResult(t, "[{b 4}]", fmt.Sprintf("%v", updated))
|
||||
})
|
||||
|
||||
t.Run("TestWrite_simple", func(t *testing.T) {
|
||||
var data = test.ParseData(`
|
||||
b:
|
||||
c: 2
|
||||
`)
|
||||
|
||||
updated := subject.UpdatedChildValue(data, []string{"b", "c"}, "4")
|
||||
test.AssertResult(t, "[{b [{c 4}]}]", fmt.Sprintf("%v", updated))
|
||||
})
|
||||
|
||||
t.Run("TestWrite_new", func(t *testing.T) {
|
||||
var data = test.ParseData(`
|
||||
b:
|
||||
c: 2
|
||||
`)
|
||||
|
||||
updated := subject.UpdatedChildValue(data, []string{"b", "d"}, "4")
|
||||
test.AssertResult(t, "[{b [{c 2} {d 4}]}]", fmt.Sprintf("%v", updated))
|
||||
})
|
||||
|
||||
t.Run("TestWrite_new_deep", func(t *testing.T) {
|
||||
var data = test.ParseData(`
|
||||
b:
|
||||
c: 2
|
||||
`)
|
||||
|
||||
updated := subject.UpdatedChildValue(data, []string{"b", "d", "f"}, "4")
|
||||
test.AssertResult(t, "[{b [{c 2} {d [{f 4}]}]}]", fmt.Sprintf("%v", updated))
|
||||
})
|
||||
|
||||
t.Run("TestWrite_array", func(t *testing.T) {
|
||||
var data = test.ParseData(`
|
||||
b:
|
||||
- aa
|
||||
`)
|
||||
|
||||
updated := subject.UpdatedChildValue(data, []string{"b", "0"}, "bb")
|
||||
|
||||
test.AssertResult(t, "[{b [bb]}]", fmt.Sprintf("%v", updated))
|
||||
})
|
||||
|
||||
t.Run("TestWrite_new_array", func(t *testing.T) {
|
||||
var data = test.ParseData(`
|
||||
b:
|
||||
c: 2
|
||||
`)
|
||||
|
||||
updated := subject.UpdatedChildValue(data, []string{"b", "0"}, "4")
|
||||
test.AssertResult(t, "[{b [{c 2} {0 4}]}]", fmt.Sprintf("%v", updated))
|
||||
})
|
||||
|
||||
t.Run("TestWrite_new_array_deep", func(t *testing.T) {
|
||||
var data = test.ParseData(`
|
||||
a: apple
|
||||
`)
|
||||
|
||||
updated := subject.UpdatedChildValue(data, []string{"b", "+", "c"}, "4")
|
||||
test.AssertResult(t, "[{a apple} {b [[{c 4}]]}]", fmt.Sprintf("%v", updated))
|
||||
})
|
||||
|
||||
t.Run("TestWrite_new_map_array_deep", func(t *testing.T) {
|
||||
var data = test.ParseData(`
|
||||
b:
|
||||
c: 2
|
||||
`)
|
||||
|
||||
updated := subject.UpdatedChildValue(data, []string{"b", "d", "+"}, "4")
|
||||
test.AssertResult(t, "[{b [{c 2} {d [4]}]}]", fmt.Sprintf("%v", updated))
|
||||
})
|
||||
|
||||
t.Run("TestWrite_add_to_array", func(t *testing.T) {
|
||||
var data = test.ParseData(`
|
||||
b:
|
||||
- aa
|
||||
`)
|
||||
|
||||
updated := subject.UpdatedChildValue(data, []string{"b", "1"}, "bb")
|
||||
test.AssertResult(t, "[{b [aa bb]}]", fmt.Sprintf("%v", updated))
|
||||
})
|
||||
|
||||
t.Run("TestWrite_with_no_tail", func(t *testing.T) {
|
||||
var data = test.ParseData(`
|
||||
b:
|
||||
c: 2
|
||||
`)
|
||||
updated := subject.UpdatedChildValue(data, []string{"b"}, "4")
|
||||
|
||||
test.AssertResult(t, "[{b 4}]", fmt.Sprintf("%v", updated))
|
||||
})
|
||||
|
||||
t.Run("TestWriteMap_no_paths", func(t *testing.T) {
|
||||
var data = test.ParseData(`
|
||||
b: 5
|
||||
`)
|
||||
var new = test.ParseData(`
|
||||
c: 4
|
||||
`)
|
||||
result := subject.UpdatedChildValue(data, []string{}, new)
|
||||
test.AssertResult(t, fmt.Sprintf("%v", new), fmt.Sprintf("%v", result))
|
||||
})
|
||||
|
||||
t.Run("TestWriteArray_no_paths", func(t *testing.T) {
|
||||
var data = make([]interface{}, 1)
|
||||
data[0] = "mike"
|
||||
var new = test.ParseData(`
|
||||
c: 4
|
||||
`)
|
||||
result := subject.UpdatedChildValue(data, []string{}, new)
|
||||
test.AssertResult(t, fmt.Sprintf("%v", new), fmt.Sprintf("%v", result))
|
||||
})
|
||||
|
||||
t.Run("TestDelete_MapItem", func(t *testing.T) {
|
||||
var data = test.ParseData(`
|
||||
a: 123
|
||||
b: 456
|
||||
`)
|
||||
var expected = test.ParseData(`
|
||||
b: 456
|
||||
`)
|
||||
|
||||
result, _ := subject.DeleteChildValue(data, []string{"a"})
|
||||
test.AssertResult(t, fmt.Sprintf("%v", expected), fmt.Sprintf("%v", result))
|
||||
})
|
||||
|
||||
// Ensure deleting an index into a string does nothing
|
||||
t.Run("TestDelete_index_to_string", func(t *testing.T) {
|
||||
var data = test.ParseData(`
|
||||
a: mystring
|
||||
`)
|
||||
result, _ := subject.DeleteChildValue(data, []string{"a", "0"})
|
||||
test.AssertResult(t, fmt.Sprintf("%v", data), fmt.Sprintf("%v", result))
|
||||
})
|
||||
|
||||
t.Run("TestDelete_list_index", func(t *testing.T) {
|
||||
var data = test.ParseData(`
|
||||
a: [3, 4]
|
||||
`)
|
||||
var expected = test.ParseData(`
|
||||
a: [3]
|
||||
`)
|
||||
result, _ := subject.DeleteChildValue(data, []string{"a", "1"})
|
||||
test.AssertResult(t, fmt.Sprintf("%v", expected), fmt.Sprintf("%v", result))
|
||||
})
|
||||
|
||||
t.Run("TestDelete_list_index_beyond_bounds", func(t *testing.T) {
|
||||
var data = test.ParseData(`
|
||||
a: [3, 4]
|
||||
`)
|
||||
result, _ := subject.DeleteChildValue(data, []string{"a", "5"})
|
||||
test.AssertResult(t, fmt.Sprintf("%v", data), fmt.Sprintf("%v", result))
|
||||
})
|
||||
|
||||
t.Run("TestDelete_list_index_out_of_bounds_by_1", func(t *testing.T) {
|
||||
var data = test.ParseData(`
|
||||
a: [3, 4]
|
||||
`)
|
||||
result, _ := subject.DeleteChildValue(data, []string{"a", "2"})
|
||||
test.AssertResult(t, fmt.Sprintf("%v", data), fmt.Sprintf("%v", result))
|
||||
})
|
||||
|
||||
t.Run("TestDelete_no_paths", func(t *testing.T) {
|
||||
var data = test.ParseData(`
|
||||
a: [3, 4]
|
||||
b:
|
||||
- name: test
|
||||
`)
|
||||
result, _ := subject.DeleteChildValue(data, []string{})
|
||||
test.AssertResult(t, fmt.Sprintf("%v", data), fmt.Sprintf("%v", result))
|
||||
})
|
||||
|
||||
t.Run("TestDelete_array_map_item", func(t *testing.T) {
|
||||
var data = test.ParseData(`
|
||||
b:
|
||||
- name: fred
|
||||
value: blah
|
||||
- name: john
|
||||
value: test
|
||||
`)
|
||||
var expected = test.ParseData(`
|
||||
b:
|
||||
- value: blah
|
||||
- name: john
|
||||
value: test
|
||||
`)
|
||||
result, _ := subject.DeleteChildValue(data, []string{"b", "0", "name"})
|
||||
test.AssertResult(t, fmt.Sprintf("%v", expected), fmt.Sprintf("%v", result))
|
||||
})
|
||||
}
|
||||
|
67
pkg/yqlib/delete_navigation_strategy.go
Normal file
67
pkg/yqlib/delete_navigation_strategy.go
Normal file
@ -0,0 +1,67 @@
|
||||
package yqlib
|
||||
|
||||
import (
|
||||
"strconv"
|
||||
|
||||
yaml "gopkg.in/yaml.v3"
|
||||
)
|
||||
|
||||
func DeleteNavigationStrategy(pathElementToDelete string) NavigationStrategy {
|
||||
parser := NewPathParser()
|
||||
return &NavigationStrategyImpl{
|
||||
visitedNodes: []*NodeContext{},
|
||||
pathParser: parser,
|
||||
followAlias: func(nodeContext NodeContext) bool {
|
||||
return false
|
||||
},
|
||||
autoCreateMap: func(nodeContext NodeContext) bool {
|
||||
return true
|
||||
},
|
||||
visit: func(nodeContext NodeContext) error {
|
||||
node := nodeContext.Node
|
||||
log.Debug("need to find and delete %v in here", pathElementToDelete)
|
||||
DebugNode(node)
|
||||
if node.Kind == yaml.SequenceNode {
|
||||
newContent, errorDeleting := deleteFromArray(node.Content, pathElementToDelete)
|
||||
if errorDeleting != nil {
|
||||
return errorDeleting
|
||||
}
|
||||
node.Content = newContent
|
||||
} else if node.Kind == yaml.MappingNode {
|
||||
node.Content = deleteFromMap(parser, node.Content, nodeContext.PathStack, pathElementToDelete)
|
||||
}
|
||||
return nil
|
||||
},
|
||||
}
|
||||
}
|
||||
func deleteFromMap(pathParser PathParser, contents []*yaml.Node, pathStack []interface{}, pathElementToDelete string) []*yaml.Node {
|
||||
newContents := make([]*yaml.Node, 0)
|
||||
for index := 0; index < len(contents); index = index + 2 {
|
||||
keyNode := contents[index]
|
||||
valueNode := contents[index+1]
|
||||
if !pathParser.MatchesNextPathElement(NewNodeContext(keyNode, pathElementToDelete, []string{}, pathStack), keyNode.Value) {
|
||||
log.Debug("adding node %v", keyNode.Value)
|
||||
newContents = append(newContents, keyNode, valueNode)
|
||||
} else {
|
||||
log.Debug("skipping node %v", keyNode.Value)
|
||||
}
|
||||
}
|
||||
return newContents
|
||||
}
|
||||
|
||||
func deleteFromArray(content []*yaml.Node, pathElementToDelete string) ([]*yaml.Node, error) {
|
||||
|
||||
if pathElementToDelete == "*" {
|
||||
return make([]*yaml.Node, 0), nil
|
||||
}
|
||||
|
||||
var index, err = strconv.ParseInt(pathElementToDelete, 10, 64) // nolint
|
||||
if err != nil {
|
||||
return content, err
|
||||
}
|
||||
if index >= int64(len(content)) {
|
||||
log.Debug("index %v is greater than content length %v", index, len(content))
|
||||
return content, nil
|
||||
}
|
||||
return append(content[:index], content[index+1:]...), nil
|
||||
}
|
44
pkg/yqlib/encoder.go
Normal file
44
pkg/yqlib/encoder.go
Normal file
@ -0,0 +1,44 @@
|
||||
package yqlib
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"io"
|
||||
|
||||
yaml "gopkg.in/yaml.v3"
|
||||
)
|
||||
|
||||
type Encoder interface {
|
||||
Encode(node *yaml.Node) error
|
||||
}
|
||||
|
||||
type yamlEncoder struct {
|
||||
encoder *yaml.Encoder
|
||||
}
|
||||
|
||||
func NewYamlEncoder(destination io.Writer) Encoder {
|
||||
var encoder = yaml.NewEncoder(destination)
|
||||
encoder.SetIndent(2)
|
||||
return &yamlEncoder{encoder}
|
||||
}
|
||||
|
||||
func (ye *yamlEncoder) Encode(node *yaml.Node) error {
|
||||
return ye.encoder.Encode(node)
|
||||
}
|
||||
|
||||
type jsonEncoder struct {
|
||||
encoder *json.Encoder
|
||||
}
|
||||
|
||||
func NewJsonEncoder(destination io.Writer) Encoder {
|
||||
var encoder = json.NewEncoder(destination)
|
||||
return &jsonEncoder{encoder}
|
||||
}
|
||||
|
||||
func (je *jsonEncoder) Encode(node *yaml.Node) error {
|
||||
var dataBucket interface{}
|
||||
errorDecoding := node.Decode(&dataBucket)
|
||||
if errorDecoding != nil {
|
||||
return errorDecoding
|
||||
}
|
||||
return je.encoder.Encode(dataBucket)
|
||||
}
|
21
pkg/yqlib/filter_matching_node_navigation_strategy.go
Normal file
21
pkg/yqlib/filter_matching_node_navigation_strategy.go
Normal file
@ -0,0 +1,21 @@
|
||||
package yqlib
|
||||
|
||||
func FilterMatchingNodesNavigationStrategy(value string) NavigationStrategy {
|
||||
return &NavigationStrategyImpl{
|
||||
visitedNodes: []*NodeContext{},
|
||||
pathParser: NewPathParser(),
|
||||
followAlias: func(nodeContext NodeContext) bool {
|
||||
return true
|
||||
},
|
||||
autoCreateMap: func(nodeContext NodeContext) bool {
|
||||
return false
|
||||
},
|
||||
visit: func(nodeContext NodeContext) error {
|
||||
return nil
|
||||
},
|
||||
shouldVisitExtraFn: func(nodeContext NodeContext) bool {
|
||||
log.Debug("does %v match %v ? %v", nodeContext.Node.Value, value, nodeContext.Node.Value == value)
|
||||
return matchesString(value, nodeContext.Node.Value)
|
||||
},
|
||||
}
|
||||
}
|
163
pkg/yqlib/lib.go
163
pkg/yqlib/lib.go
@ -1,68 +1,149 @@
|
||||
package yqlib
|
||||
|
||||
import (
|
||||
mergo "gopkg.in/imdario/mergo.v0"
|
||||
"bytes"
|
||||
"fmt"
|
||||
"strconv"
|
||||
"strings"
|
||||
|
||||
logging "gopkg.in/op/go-logging.v1"
|
||||
yaml "gopkg.in/yaml.v3"
|
||||
)
|
||||
|
||||
var log = logging.MustGetLogger("yq")
|
||||
|
||||
type UpdateCommand struct {
|
||||
Command string
|
||||
Path string
|
||||
Value *yaml.Node
|
||||
Overwrite bool
|
||||
}
|
||||
|
||||
func DebugNode(value *yaml.Node) {
|
||||
if value == nil {
|
||||
log.Debug("-- node is nil --")
|
||||
} else if log.IsEnabledFor(logging.DEBUG) {
|
||||
buf := new(bytes.Buffer)
|
||||
encoder := yaml.NewEncoder(buf)
|
||||
errorEncoding := encoder.Encode(value)
|
||||
if errorEncoding != nil {
|
||||
log.Error("Error debugging node, %v", errorEncoding.Error())
|
||||
}
|
||||
encoder.Close()
|
||||
log.Debug("Tag: %v", value.Tag)
|
||||
log.Debug("%v", buf.String())
|
||||
}
|
||||
}
|
||||
|
||||
func pathStackToString(pathStack []interface{}) string {
|
||||
return mergePathStackToString(pathStack, false)
|
||||
}
|
||||
|
||||
func mergePathStackToString(pathStack []interface{}, appendArrays bool) string {
|
||||
var sb strings.Builder
|
||||
for index, path := range pathStack {
|
||||
switch path.(type) {
|
||||
case int:
|
||||
if appendArrays {
|
||||
sb.WriteString("[+]")
|
||||
} else {
|
||||
sb.WriteString(fmt.Sprintf("[%v]", path))
|
||||
}
|
||||
|
||||
default:
|
||||
sb.WriteString(fmt.Sprintf("%v", path))
|
||||
}
|
||||
|
||||
if index < len(pathStack)-1 {
|
||||
sb.WriteString(".")
|
||||
}
|
||||
}
|
||||
return sb.String()
|
||||
}
|
||||
|
||||
func guessKind(head string, tail []string, guess yaml.Kind) yaml.Kind {
|
||||
log.Debug("tail %v", tail)
|
||||
if len(tail) == 0 && guess == 0 {
|
||||
log.Debug("end of path, must be a scalar")
|
||||
return yaml.ScalarNode
|
||||
} else if len(tail) == 0 {
|
||||
return guess
|
||||
}
|
||||
|
||||
var _, errorParsingInt = strconv.ParseInt(tail[0], 10, 64)
|
||||
if tail[0] == "+" || errorParsingInt == nil {
|
||||
return yaml.SequenceNode
|
||||
}
|
||||
pathParser := NewPathParser()
|
||||
if (pathParser.IsPathExpression(tail[0]) || head == "**") && (guess == yaml.SequenceNode || guess == yaml.MappingNode) {
|
||||
return guess
|
||||
}
|
||||
if guess == yaml.AliasNode {
|
||||
log.Debug("guess was an alias, okey doke.")
|
||||
return guess
|
||||
}
|
||||
log.Debug("forcing a mapping node")
|
||||
log.Debug("yaml.SequenceNode %v", guess == yaml.SequenceNode)
|
||||
log.Debug("yaml.ScalarNode %v", guess == yaml.ScalarNode)
|
||||
return yaml.MappingNode
|
||||
}
|
||||
|
||||
type YqLib interface {
|
||||
ReadPath(dataBucket interface{}, path string) (interface{}, error)
|
||||
WritePath(dataBucket interface{}, path string, value interface{}) interface{}
|
||||
PrefixPath(dataBucket interface{}, prefix string) interface{}
|
||||
DeletePath(dataBucket interface{}, path string) (interface{}, error)
|
||||
Merge(dst interface{}, src interface{}, overwrite bool, append bool) error
|
||||
Get(rootNode *yaml.Node, path string) ([]*NodeContext, error)
|
||||
Update(rootNode *yaml.Node, updateCommand UpdateCommand, autoCreate bool) error
|
||||
New(path string) yaml.Node
|
||||
|
||||
PathStackToString(pathStack []interface{}) string
|
||||
MergePathStackToString(pathStack []interface{}, appendArrays bool) string
|
||||
}
|
||||
|
||||
type lib struct {
|
||||
navigator DataNavigator
|
||||
parser PathParser
|
||||
}
|
||||
|
||||
func NewYqLib(l *logging.Logger) YqLib {
|
||||
func NewYqLib() YqLib {
|
||||
return &lib{
|
||||
navigator: NewDataNavigator(l),
|
||||
parser: NewPathParser(),
|
||||
}
|
||||
}
|
||||
|
||||
func (l *lib) ReadPath(dataBucket interface{}, path string) (interface{}, error) {
|
||||
func (l *lib) Get(rootNode *yaml.Node, path string) ([]*NodeContext, error) {
|
||||
var paths = l.parser.ParsePath(path)
|
||||
return l.navigator.ReadChildValue(dataBucket, paths)
|
||||
navigationStrategy := ReadNavigationStrategy()
|
||||
navigator := NewDataNavigator(navigationStrategy)
|
||||
error := navigator.Traverse(rootNode, paths)
|
||||
return navigationStrategy.GetVisitedNodes(), error
|
||||
|
||||
}
|
||||
|
||||
func (l *lib) WritePath(dataBucket interface{}, path string, value interface{}) interface{} {
|
||||
func (l *lib) PathStackToString(pathStack []interface{}) string {
|
||||
return pathStackToString(pathStack)
|
||||
}
|
||||
|
||||
func (l *lib) MergePathStackToString(pathStack []interface{}, appendArrays bool) string {
|
||||
return mergePathStackToString(pathStack, appendArrays)
|
||||
}
|
||||
|
||||
func (l *lib) New(path string) yaml.Node {
|
||||
var paths = l.parser.ParsePath(path)
|
||||
return l.navigator.UpdatedChildValue(dataBucket, paths, value)
|
||||
newNode := yaml.Node{Kind: guessKind("", paths, 0)}
|
||||
return newNode
|
||||
}
|
||||
|
||||
func (l *lib) PrefixPath(dataBucket interface{}, prefix string) interface{} {
|
||||
var paths = l.parser.ParsePath(prefix)
|
||||
|
||||
// Inverse order
|
||||
for i := len(paths)/2 - 1; i >= 0; i-- {
|
||||
opp := len(paths) - 1 - i
|
||||
paths[i], paths[opp] = paths[opp], paths[i]
|
||||
func (l *lib) Update(rootNode *yaml.Node, updateCommand UpdateCommand, autoCreate bool) error {
|
||||
log.Debugf("%v to %v", updateCommand.Command, updateCommand.Path)
|
||||
switch updateCommand.Command {
|
||||
case "update":
|
||||
var paths = l.parser.ParsePath(updateCommand.Path)
|
||||
navigator := NewDataNavigator(UpdateNavigationStrategy(updateCommand, autoCreate))
|
||||
return navigator.Traverse(rootNode, paths)
|
||||
case "delete":
|
||||
var paths = l.parser.ParsePath(updateCommand.Path)
|
||||
lastBit, newTail := paths[len(paths)-1], paths[:len(paths)-1]
|
||||
navigator := NewDataNavigator(DeleteNavigationStrategy(lastBit))
|
||||
return navigator.Traverse(rootNode, newTail)
|
||||
default:
|
||||
return fmt.Errorf("Unknown command %v", updateCommand.Command)
|
||||
}
|
||||
|
||||
var mapDataBucket = dataBucket
|
||||
for _, key := range paths {
|
||||
singlePath := []string{key}
|
||||
mapDataBucket = l.navigator.UpdatedChildValue(nil, singlePath, mapDataBucket)
|
||||
}
|
||||
|
||||
return mapDataBucket
|
||||
}
|
||||
|
||||
func (l *lib) DeletePath(dataBucket interface{}, path string) (interface{}, error) {
|
||||
var paths = l.parser.ParsePath(path)
|
||||
return l.navigator.DeleteChildValue(dataBucket, paths)
|
||||
}
|
||||
|
||||
func (l *lib) Merge(dst interface{}, src interface{}, overwrite bool, append bool) error {
|
||||
if overwrite {
|
||||
return mergo.Merge(dst, src, mergo.WithOverride)
|
||||
} else if append {
|
||||
return mergo.Merge(dst, src, mergo.WithAppendSlice)
|
||||
}
|
||||
return mergo.Merge(dst, src)
|
||||
}
|
||||
|
@ -1,166 +1,176 @@
|
||||
package yqlib
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"testing"
|
||||
|
||||
"github.com/mikefarah/yq/v2/test"
|
||||
logging "gopkg.in/op/go-logging.v1"
|
||||
"github.com/mikefarah/yq/v3/test"
|
||||
)
|
||||
|
||||
func TestLib(t *testing.T) {
|
||||
|
||||
var log = logging.MustGetLogger("yq")
|
||||
subject := NewYqLib(log)
|
||||
subject := NewYqLib()
|
||||
|
||||
t.Run("TestReadPath", func(t *testing.T) {
|
||||
var data = test.ParseData(`
|
||||
---
|
||||
b:
|
||||
2: c
|
||||
`)
|
||||
|
||||
got, _ := subject.ReadPath(data, "b.2")
|
||||
test.AssertResult(t, `c`, got)
|
||||
t.Run("PathStackToString_Empty", func(t *testing.T) {
|
||||
emptyArray := make([]interface{}, 0)
|
||||
got := subject.PathStackToString(emptyArray)
|
||||
test.AssertResult(t, ``, got)
|
||||
})
|
||||
|
||||
t.Run("TestReadPath_WithError", func(t *testing.T) {
|
||||
var data = test.ParseData(`
|
||||
---
|
||||
b:
|
||||
- c
|
||||
`)
|
||||
|
||||
_, err := subject.ReadPath(data, "b.[a]")
|
||||
if err == nil {
|
||||
t.Fatal("Expected error due to invalid path")
|
||||
}
|
||||
t.Run("PathStackToString", func(t *testing.T) {
|
||||
array := make([]interface{}, 3)
|
||||
array[0] = "a"
|
||||
array[1] = 0
|
||||
array[2] = "b"
|
||||
got := subject.PathStackToString(array)
|
||||
test.AssertResult(t, `a.[0].b`, got)
|
||||
})
|
||||
|
||||
t.Run("TestWritePath", func(t *testing.T) {
|
||||
var data = test.ParseData(`
|
||||
---
|
||||
b:
|
||||
2: c
|
||||
`)
|
||||
|
||||
got := subject.WritePath(data, "b.3", "a")
|
||||
test.AssertResult(t, `[{b [{2 c} {3 a}]}]`, fmt.Sprintf("%v", got))
|
||||
t.Run("MergePathStackToString", func(t *testing.T) {
|
||||
array := make([]interface{}, 3)
|
||||
array[0] = "a"
|
||||
array[1] = 0
|
||||
array[2] = "b"
|
||||
got := subject.MergePathStackToString(array, true)
|
||||
test.AssertResult(t, `a.[+].b`, got)
|
||||
})
|
||||
|
||||
t.Run("TestPrefixPath", func(t *testing.T) {
|
||||
var data = test.ParseData(`
|
||||
---
|
||||
b:
|
||||
2: c
|
||||
`)
|
||||
// t.Run("TestReadPath_WithError", func(t *testing.T) {
|
||||
// var data = test.ParseData(`
|
||||
// ---
|
||||
// b:
|
||||
// - c
|
||||
// `)
|
||||
|
||||
got := subject.PrefixPath(data, "a.d")
|
||||
test.AssertResult(t, `[{a [{d [{b [{2 c}]}]}]}]`, fmt.Sprintf("%v", got))
|
||||
})
|
||||
// _, err := subject.ReadPath(data, "b.[a]")
|
||||
// if err == nil {
|
||||
// t.Fatal("Expected error due to invalid path")
|
||||
// }
|
||||
// })
|
||||
|
||||
t.Run("TestDeletePath", func(t *testing.T) {
|
||||
var data = test.ParseData(`
|
||||
---
|
||||
b:
|
||||
2: c
|
||||
3: a
|
||||
`)
|
||||
// t.Run("TestWritePath", func(t *testing.T) {
|
||||
// var data = test.ParseData(`
|
||||
// ---
|
||||
// b:
|
||||
// 2: c
|
||||
// `)
|
||||
|
||||
got, _ := subject.DeletePath(data, "b.2")
|
||||
test.AssertResult(t, `[{b [{3 a}]}]`, fmt.Sprintf("%v", got))
|
||||
})
|
||||
// got := subject.WritePath(data, "b.3", "a")
|
||||
// test.AssertResult(t, `[{b [{2 c} {3 a}]}]`, fmt.Sprintf("%v", got))
|
||||
// })
|
||||
|
||||
t.Run("TestDeletePath_WithError", func(t *testing.T) {
|
||||
var data = test.ParseData(`
|
||||
---
|
||||
b:
|
||||
- c
|
||||
`)
|
||||
// t.Run("TestPrefixPath", func(t *testing.T) {
|
||||
// var data = test.ParseData(`
|
||||
// ---
|
||||
// b:
|
||||
// 2: c
|
||||
// `)
|
||||
|
||||
_, err := subject.DeletePath(data, "b.[a]")
|
||||
if err == nil {
|
||||
t.Fatal("Expected error due to invalid path")
|
||||
}
|
||||
})
|
||||
// got := subject.PrefixPath(data, "a.d")
|
||||
// test.AssertResult(t, `[{a [{d [{b [{2 c}]}]}]}]`, fmt.Sprintf("%v", got))
|
||||
// })
|
||||
|
||||
t.Run("TestMerge", func(t *testing.T) {
|
||||
var dst = test.ParseData(`
|
||||
---
|
||||
a: b
|
||||
c: d
|
||||
`)
|
||||
var src = test.ParseData(`
|
||||
---
|
||||
a: 1
|
||||
b: 2
|
||||
`)
|
||||
// t.Run("TestDeletePath", func(t *testing.T) {
|
||||
// var data = test.ParseData(`
|
||||
// ---
|
||||
// b:
|
||||
// 2: c
|
||||
// 3: a
|
||||
// `)
|
||||
|
||||
var mergedData = make(map[interface{}]interface{})
|
||||
mergedData["root"] = dst
|
||||
var mapDataBucket = make(map[interface{}]interface{})
|
||||
mapDataBucket["root"] = src
|
||||
// got, _ := subject.DeletePath(data, "b.2")
|
||||
// test.AssertResult(t, `[{b [{3 a}]}]`, fmt.Sprintf("%v", got))
|
||||
// })
|
||||
|
||||
err := subject.Merge(&mergedData, mapDataBucket, false, false)
|
||||
if err != nil {
|
||||
t.Fatal("Unexpected error")
|
||||
}
|
||||
test.AssertResult(t, `[{a b} {c d}]`, fmt.Sprintf("%v", mergedData["root"]))
|
||||
})
|
||||
// t.Run("TestDeletePath_WithError", func(t *testing.T) {
|
||||
// var data = test.ParseData(`
|
||||
// ---
|
||||
// b:
|
||||
// - c
|
||||
// `)
|
||||
|
||||
t.Run("TestMerge_WithOverwrite", func(t *testing.T) {
|
||||
var dst = test.ParseData(`
|
||||
---
|
||||
a: b
|
||||
c: d
|
||||
`)
|
||||
var src = test.ParseData(`
|
||||
---
|
||||
a: 1
|
||||
b: 2
|
||||
`)
|
||||
// _, err := subject.DeletePath(data, "b.[a]")
|
||||
// if err == nil {
|
||||
// t.Fatal("Expected error due to invalid path")
|
||||
// }
|
||||
// })
|
||||
|
||||
var mergedData = make(map[interface{}]interface{})
|
||||
mergedData["root"] = dst
|
||||
var mapDataBucket = make(map[interface{}]interface{})
|
||||
mapDataBucket["root"] = src
|
||||
// t.Run("TestMerge", func(t *testing.T) {
|
||||
// var dst = test.ParseData(`
|
||||
// ---
|
||||
// a: b
|
||||
// c: d
|
||||
// `)
|
||||
// var src = test.ParseData(`
|
||||
// ---
|
||||
// a: 1
|
||||
// b: 2
|
||||
// `)
|
||||
|
||||
err := subject.Merge(&mergedData, mapDataBucket, true, false)
|
||||
if err != nil {
|
||||
t.Fatal("Unexpected error")
|
||||
}
|
||||
test.AssertResult(t, `[{a 1} {b 2}]`, fmt.Sprintf("%v", mergedData["root"]))
|
||||
})
|
||||
// var mergedData = make(map[interface{}]interface{})
|
||||
// mergedData["root"] = dst
|
||||
// var mapDataBucket = make(map[interface{}]interface{})
|
||||
// mapDataBucket["root"] = src
|
||||
|
||||
t.Run("TestMerge_WithAppend", func(t *testing.T) {
|
||||
var dst = test.ParseData(`
|
||||
---
|
||||
a: b
|
||||
c: d
|
||||
`)
|
||||
var src = test.ParseData(`
|
||||
---
|
||||
a: 1
|
||||
b: 2
|
||||
`)
|
||||
// err := subject.Merge(&mergedData, mapDataBucket, false, false)
|
||||
// if err != nil {
|
||||
// t.Fatal("Unexpected error")
|
||||
// }
|
||||
// test.AssertResult(t, `[{a b} {c d}]`, fmt.Sprintf("%v", mergedData["root"]))
|
||||
// })
|
||||
|
||||
var mergedData = make(map[interface{}]interface{})
|
||||
mergedData["root"] = dst
|
||||
var mapDataBucket = make(map[interface{}]interface{})
|
||||
mapDataBucket["root"] = src
|
||||
// t.Run("TestMerge_WithOverwrite", func(t *testing.T) {
|
||||
// var dst = test.ParseData(`
|
||||
// ---
|
||||
// a: b
|
||||
// c: d
|
||||
// `)
|
||||
// var src = test.ParseData(`
|
||||
// ---
|
||||
// a: 1
|
||||
// b: 2
|
||||
// `)
|
||||
|
||||
err := subject.Merge(&mergedData, mapDataBucket, false, true)
|
||||
if err != nil {
|
||||
t.Fatal("Unexpected error")
|
||||
}
|
||||
test.AssertResult(t, `[{a b} {c d} {a 1} {b 2}]`, fmt.Sprintf("%v", mergedData["root"]))
|
||||
})
|
||||
// var mergedData = make(map[interface{}]interface{})
|
||||
// mergedData["root"] = dst
|
||||
// var mapDataBucket = make(map[interface{}]interface{})
|
||||
// mapDataBucket["root"] = src
|
||||
|
||||
t.Run("TestMerge_WithError", func(t *testing.T) {
|
||||
err := subject.Merge(nil, nil, false, false)
|
||||
if err == nil {
|
||||
t.Fatal("Expected error due to nil")
|
||||
}
|
||||
})
|
||||
// err := subject.Merge(&mergedData, mapDataBucket, true, false)
|
||||
// if err != nil {
|
||||
// t.Fatal("Unexpected error")
|
||||
// }
|
||||
// test.AssertResult(t, `[{a 1} {b 2}]`, fmt.Sprintf("%v", mergedData["root"]))
|
||||
// })
|
||||
|
||||
// t.Run("TestMerge_WithAppend", func(t *testing.T) {
|
||||
// var dst = test.ParseData(`
|
||||
// ---
|
||||
// a: b
|
||||
// c: d
|
||||
// `)
|
||||
// var src = test.ParseData(`
|
||||
// ---
|
||||
// a: 1
|
||||
// b: 2
|
||||
// `)
|
||||
|
||||
// var mergedData = make(map[interface{}]interface{})
|
||||
// mergedData["root"] = dst
|
||||
// var mapDataBucket = make(map[interface{}]interface{})
|
||||
// mapDataBucket["root"] = src
|
||||
|
||||
// err := subject.Merge(&mergedData, mapDataBucket, false, true)
|
||||
// if err != nil {
|
||||
// t.Fatal("Unexpected error")
|
||||
// }
|
||||
// test.AssertResult(t, `[{a b} {c d} {a 1} {b 2}]`, fmt.Sprintf("%v", mergedData["root"]))
|
||||
// })
|
||||
|
||||
// t.Run("TestMerge_WithError", func(t *testing.T) {
|
||||
// err := subject.Merge(nil, nil, false, false)
|
||||
// if err == nil {
|
||||
// t.Fatal("Expected error due to nil")
|
||||
// }
|
||||
// })
|
||||
|
||||
}
|
||||
|
152
pkg/yqlib/navigation_strategy.go
Normal file
152
pkg/yqlib/navigation_strategy.go
Normal file
@ -0,0 +1,152 @@
|
||||
package yqlib
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
yaml "gopkg.in/yaml.v3"
|
||||
)
|
||||
|
||||
type NodeContext struct {
|
||||
Node *yaml.Node
|
||||
Head string
|
||||
Tail []string
|
||||
PathStack []interface{}
|
||||
}
|
||||
|
||||
func NewNodeContext(node *yaml.Node, head string, tail []string, pathStack []interface{}) NodeContext {
|
||||
newTail := make([]string, len(tail))
|
||||
copy(newTail, tail)
|
||||
|
||||
newPathStack := make([]interface{}, len(pathStack))
|
||||
copy(newPathStack, pathStack)
|
||||
return NodeContext{
|
||||
Node: node,
|
||||
Head: head,
|
||||
Tail: newTail,
|
||||
PathStack: newPathStack,
|
||||
}
|
||||
}
|
||||
|
||||
type NavigationStrategy interface {
|
||||
FollowAlias(nodeContext NodeContext) bool
|
||||
AutoCreateMap(nodeContext NodeContext) bool
|
||||
Visit(nodeContext NodeContext) error
|
||||
// node key is the string value of the last element in the path stack
|
||||
// we use it to match against the pathExpression in head.
|
||||
ShouldTraverse(nodeContext NodeContext, nodeKey string) bool
|
||||
GetVisitedNodes() []*NodeContext
|
||||
DebugVisitedNodes()
|
||||
GetPathParser() PathParser
|
||||
}
|
||||
|
||||
type NavigationStrategyImpl struct {
|
||||
followAlias func(nodeContext NodeContext) bool
|
||||
autoCreateMap func(nodeContext NodeContext) bool
|
||||
visit func(nodeContext NodeContext) error
|
||||
shouldVisitExtraFn func(nodeContext NodeContext) bool
|
||||
visitedNodes []*NodeContext
|
||||
pathParser PathParser
|
||||
}
|
||||
|
||||
func (ns *NavigationStrategyImpl) GetPathParser() PathParser {
|
||||
return ns.pathParser
|
||||
}
|
||||
|
||||
func (ns *NavigationStrategyImpl) GetVisitedNodes() []*NodeContext {
|
||||
return ns.visitedNodes
|
||||
}
|
||||
|
||||
func (ns *NavigationStrategyImpl) FollowAlias(nodeContext NodeContext) bool {
|
||||
return ns.followAlias(nodeContext)
|
||||
}
|
||||
|
||||
func (ns *NavigationStrategyImpl) AutoCreateMap(nodeContext NodeContext) bool {
|
||||
return ns.autoCreateMap(nodeContext)
|
||||
}
|
||||
|
||||
func (ns *NavigationStrategyImpl) ShouldTraverse(nodeContext NodeContext, nodeKey string) bool {
|
||||
// we should traverse aliases (if enabled), but not visit them :/
|
||||
if len(nodeContext.PathStack) == 0 {
|
||||
return true
|
||||
}
|
||||
|
||||
if ns.alreadyVisited(nodeContext.PathStack) {
|
||||
return false
|
||||
}
|
||||
|
||||
return (nodeKey == "<<" && ns.FollowAlias(nodeContext)) || (nodeKey != "<<" &&
|
||||
ns.pathParser.MatchesNextPathElement(nodeContext, nodeKey))
|
||||
}
|
||||
|
||||
func (ns *NavigationStrategyImpl) shouldVisit(nodeContext NodeContext) bool {
|
||||
pathStack := nodeContext.PathStack
|
||||
if len(pathStack) == 0 {
|
||||
return true
|
||||
}
|
||||
log.Debug("tail len %v", len(nodeContext.Tail))
|
||||
// SOMETHING HERE!
|
||||
|
||||
if ns.alreadyVisited(pathStack) || len(nodeContext.Tail) != 0 {
|
||||
return false
|
||||
}
|
||||
|
||||
nodeKey := fmt.Sprintf("%v", pathStack[len(pathStack)-1])
|
||||
log.Debug("nodeKey: %v, nodeContext.Head: %v", nodeKey, nodeContext.Head)
|
||||
|
||||
// only visit aliases if its an exact match
|
||||
return ((nodeKey == "<<" && nodeContext.Head == "<<") || (nodeKey != "<<" &&
|
||||
ns.pathParser.MatchesNextPathElement(nodeContext, nodeKey))) && (ns.shouldVisitExtraFn == nil || ns.shouldVisitExtraFn(nodeContext))
|
||||
}
|
||||
|
||||
func (ns *NavigationStrategyImpl) Visit(nodeContext NodeContext) error {
|
||||
log.Debug("Visit?, %v, %v", nodeContext.Head, pathStackToString(nodeContext.PathStack))
|
||||
DebugNode(nodeContext.Node)
|
||||
if ns.shouldVisit(nodeContext) {
|
||||
log.Debug("yep, visiting")
|
||||
// pathStack array must be
|
||||
// copied, as append() may sometimes reuse and modify the array
|
||||
ns.visitedNodes = append(ns.visitedNodes, &nodeContext)
|
||||
ns.DebugVisitedNodes()
|
||||
return ns.visit(nodeContext)
|
||||
}
|
||||
log.Debug("nope, skip it")
|
||||
return nil
|
||||
}
|
||||
|
||||
func (ns *NavigationStrategyImpl) DebugVisitedNodes() {
|
||||
log.Debug("Visited Nodes:")
|
||||
for _, candidate := range ns.visitedNodes {
|
||||
log.Debug(" - %v", pathStackToString(candidate.PathStack))
|
||||
}
|
||||
}
|
||||
|
||||
func (ns *NavigationStrategyImpl) alreadyVisited(pathStack []interface{}) bool {
|
||||
log.Debug("checking already visited pathStack: %v", pathStackToString(pathStack))
|
||||
for _, candidate := range ns.visitedNodes {
|
||||
candidatePathStack := candidate.PathStack
|
||||
if patchStacksMatch(candidatePathStack, pathStack) {
|
||||
log.Debug("paths match, already seen it")
|
||||
return true
|
||||
}
|
||||
|
||||
}
|
||||
log.Debug("never seen it before!")
|
||||
return false
|
||||
}
|
||||
|
||||
func patchStacksMatch(path1 []interface{}, path2 []interface{}) bool {
|
||||
log.Debug("checking against path: %v", pathStackToString(path1))
|
||||
|
||||
if len(path1) != len(path2) {
|
||||
return false
|
||||
}
|
||||
for index, p1Value := range path1 {
|
||||
|
||||
p2Value := path2[index]
|
||||
if p1Value != p2Value {
|
||||
return false
|
||||
}
|
||||
}
|
||||
return true
|
||||
|
||||
}
|
@ -1,7 +1,14 @@
|
||||
package yqlib
|
||||
|
||||
import (
|
||||
"strconv"
|
||||
"strings"
|
||||
)
|
||||
|
||||
type PathParser interface {
|
||||
ParsePath(path string) []string
|
||||
MatchesNextPathElement(nodeContext NodeContext, nodeKey string) bool
|
||||
IsPathExpression(pathElement string) bool
|
||||
}
|
||||
|
||||
type pathParser struct{}
|
||||
@ -10,7 +17,66 @@ func NewPathParser() PathParser {
|
||||
return &pathParser{}
|
||||
}
|
||||
|
||||
func matchesString(expression string, value string) bool {
|
||||
var prefixMatch = strings.TrimSuffix(expression, "*")
|
||||
if prefixMatch != expression {
|
||||
log.Debug("prefix match, %v", strings.HasPrefix(value, prefixMatch))
|
||||
return strings.HasPrefix(value, prefixMatch)
|
||||
}
|
||||
return value == expression
|
||||
}
|
||||
|
||||
func (p *pathParser) IsPathExpression(pathElement string) bool {
|
||||
return pathElement == "*" || pathElement == "**" || strings.Contains(pathElement, "==")
|
||||
}
|
||||
|
||||
/**
|
||||
* node: node that we may traverse/visit
|
||||
* head: path element expression to match against
|
||||
* tail: remaining path element expressions
|
||||
* pathStack: stack of actual paths we've matched to get to node
|
||||
* nodeKey: actual value of this nodes 'key' or index.
|
||||
*/
|
||||
func (p *pathParser) MatchesNextPathElement(nodeContext NodeContext, nodeKey string) bool {
|
||||
head := nodeContext.Head
|
||||
if head == "**" || head == "*" {
|
||||
return true
|
||||
}
|
||||
if strings.Contains(head, "==") {
|
||||
log.Debug("ooh deep recursion time")
|
||||
result := strings.SplitN(head, "==", 2)
|
||||
path := strings.TrimSpace(result[0])
|
||||
value := strings.TrimSpace(result[1])
|
||||
log.Debug("path %v", path)
|
||||
log.Debug("value %v", value)
|
||||
DebugNode(nodeContext.Node)
|
||||
navigationStrategy := FilterMatchingNodesNavigationStrategy(value)
|
||||
|
||||
navigator := NewDataNavigator(navigationStrategy)
|
||||
err := navigator.Traverse(nodeContext.Node, p.ParsePath(path))
|
||||
if err != nil {
|
||||
log.Error(err.Error())
|
||||
}
|
||||
//crap handle error
|
||||
log.Debug("done deep recursing, found %v matches", len(navigationStrategy.GetVisitedNodes()))
|
||||
return len(navigationStrategy.GetVisitedNodes()) > 0
|
||||
}
|
||||
|
||||
if head == "+" {
|
||||
log.Debug("head is +, nodeKey is %v", nodeKey)
|
||||
var _, err = strconv.ParseInt(nodeKey, 10, 64) // nolint
|
||||
if err == nil {
|
||||
return true
|
||||
}
|
||||
}
|
||||
|
||||
return matchesString(head, nodeKey)
|
||||
}
|
||||
|
||||
func (p *pathParser) ParsePath(path string) []string {
|
||||
if path == "" {
|
||||
return []string{}
|
||||
}
|
||||
return p.parsePathAccum([]string{}, path)
|
||||
}
|
||||
|
||||
@ -30,9 +96,12 @@ func (p *pathParser) nextYamlPath(path string) (pathElement string, remaining st
|
||||
case '"':
|
||||
// e.g "a.b".blah.cat -> we need to return "a.b" and "blah.cat"
|
||||
return p.search(path[1:], []uint8{'"'}, true)
|
||||
case '(':
|
||||
// e.g "a.b".blah.cat -> we need to return "a.b" and "blah.cat"
|
||||
return p.search(path[1:], []uint8{')'}, true)
|
||||
default:
|
||||
// e.g "a.blah.cat" -> return "a" and "blah.cat"
|
||||
return p.search(path[0:], []uint8{'.', '['}, false)
|
||||
return p.search(path[0:], []uint8{'.', '[', '"', '('}, false)
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -3,14 +3,18 @@ package yqlib
|
||||
import (
|
||||
"testing"
|
||||
|
||||
"github.com/mikefarah/yq/v2/test"
|
||||
"github.com/mikefarah/yq/v3/test"
|
||||
)
|
||||
|
||||
var parser = NewPathParser()
|
||||
|
||||
var parsePathsTests = []struct {
|
||||
path string
|
||||
expectedPaths []string
|
||||
}{
|
||||
{"a.b", []string{"a", "b"}},
|
||||
{"a.b.**", []string{"a", "b", "**"}},
|
||||
{"a.b.*", []string{"a", "b", "*"}},
|
||||
{"a.b[0]", []string{"a", "b", "0"}},
|
||||
{"a.b.d[+]", []string{"a", "b", "d", "+"}},
|
||||
{"a", []string{"a"}},
|
||||
@ -22,8 +26,53 @@ var parsePathsTests = []struct {
|
||||
{"[0]", []string{"0"}},
|
||||
}
|
||||
|
||||
func TestParsePath(t *testing.T) {
|
||||
func TestPathParserParsePath(t *testing.T) {
|
||||
for _, tt := range parsePathsTests {
|
||||
test.AssertResultComplex(t, tt.expectedPaths, NewPathParser().ParsePath(tt.path))
|
||||
test.AssertResultComplex(t, tt.expectedPaths, parser.ParsePath(tt.path))
|
||||
}
|
||||
}
|
||||
|
||||
func TestPathParserMatchesNextPathElementSplat(t *testing.T) {
|
||||
var node = NodeContext{Head: "*"}
|
||||
test.AssertResult(t, true, parser.MatchesNextPathElement(node, ""))
|
||||
}
|
||||
|
||||
func TestPathParserMatchesNextPathElementDeepSplat(t *testing.T) {
|
||||
var node = NodeContext{Head: "**"}
|
||||
test.AssertResult(t, true, parser.MatchesNextPathElement(node, ""))
|
||||
}
|
||||
|
||||
func TestPathParserMatchesNextPathElementAppendArrayValid(t *testing.T) {
|
||||
var node = NodeContext{Head: "+"}
|
||||
test.AssertResult(t, true, parser.MatchesNextPathElement(node, "3"))
|
||||
}
|
||||
|
||||
func TestPathParserMatchesNextPathElementAppendArrayInvalid(t *testing.T) {
|
||||
var node = NodeContext{Head: "+"}
|
||||
test.AssertResult(t, false, parser.MatchesNextPathElement(node, "cat"))
|
||||
}
|
||||
|
||||
func TestPathParserMatchesNextPathElementPrefixMatchesWhole(t *testing.T) {
|
||||
var node = NodeContext{Head: "cat*"}
|
||||
test.AssertResult(t, true, parser.MatchesNextPathElement(node, "cat"))
|
||||
}
|
||||
|
||||
func TestPathParserMatchesNextPathElementPrefixMatchesStart(t *testing.T) {
|
||||
var node = NodeContext{Head: "cat*"}
|
||||
test.AssertResult(t, true, parser.MatchesNextPathElement(node, "caterpillar"))
|
||||
}
|
||||
|
||||
func TestPathParserMatchesNextPathElementPrefixMismatch(t *testing.T) {
|
||||
var node = NodeContext{Head: "cat*"}
|
||||
test.AssertResult(t, false, parser.MatchesNextPathElement(node, "dog"))
|
||||
}
|
||||
|
||||
func TestPathParserMatchesNextPathElementExactMatch(t *testing.T) {
|
||||
var node = NodeContext{Head: "farahtek"}
|
||||
test.AssertResult(t, true, parser.MatchesNextPathElement(node, "farahtek"))
|
||||
}
|
||||
|
||||
func TestPathParserMatchesNextPathElementExactMismatch(t *testing.T) {
|
||||
var node = NodeContext{Head: "farahtek"}
|
||||
test.AssertResult(t, false, parser.MatchesNextPathElement(node, "othertek"))
|
||||
}
|
||||
|
17
pkg/yqlib/read_navigation_strategy.go
Normal file
17
pkg/yqlib/read_navigation_strategy.go
Normal file
@ -0,0 +1,17 @@
|
||||
package yqlib
|
||||
|
||||
func ReadNavigationStrategy() NavigationStrategy {
|
||||
return &NavigationStrategyImpl{
|
||||
visitedNodes: []*NodeContext{},
|
||||
pathParser: NewPathParser(),
|
||||
followAlias: func(nodeContext NodeContext) bool {
|
||||
return true
|
||||
},
|
||||
autoCreateMap: func(nodeContext NodeContext) bool {
|
||||
return false
|
||||
},
|
||||
visit: func(nodeContext NodeContext) error {
|
||||
return nil
|
||||
},
|
||||
}
|
||||
}
|
35
pkg/yqlib/update_navigation_strategy.go
Normal file
35
pkg/yqlib/update_navigation_strategy.go
Normal file
@ -0,0 +1,35 @@
|
||||
package yqlib
|
||||
|
||||
func UpdateNavigationStrategy(updateCommand UpdateCommand, autoCreate bool) NavigationStrategy {
|
||||
return &NavigationStrategyImpl{
|
||||
visitedNodes: []*NodeContext{},
|
||||
pathParser: NewPathParser(),
|
||||
followAlias: func(nodeContext NodeContext) bool {
|
||||
return false
|
||||
},
|
||||
autoCreateMap: func(nodeContext NodeContext) bool {
|
||||
return autoCreate
|
||||
},
|
||||
visit: func(nodeContext NodeContext) error {
|
||||
node := nodeContext.Node
|
||||
changesToApply := updateCommand.Value
|
||||
if updateCommand.Overwrite || node.Value == "" {
|
||||
log.Debug("going to update")
|
||||
DebugNode(node)
|
||||
log.Debug("with")
|
||||
DebugNode(changesToApply)
|
||||
node.Value = changesToApply.Value
|
||||
node.Tag = changesToApply.Tag
|
||||
node.Kind = changesToApply.Kind
|
||||
node.Style = changesToApply.Style
|
||||
node.Content = changesToApply.Content
|
||||
node.HeadComment = changesToApply.HeadComment
|
||||
node.LineComment = changesToApply.LineComment
|
||||
node.FootComment = changesToApply.FootComment
|
||||
} else {
|
||||
log.Debug("skipping update as node already has value %v and overwriteFlag is ", node.Value, updateCommand.Overwrite)
|
||||
}
|
||||
return nil
|
||||
},
|
||||
}
|
||||
}
|
@ -1,35 +1,23 @@
|
||||
package yqlib
|
||||
|
||||
import (
|
||||
"strconv"
|
||||
yaml "gopkg.in/yaml.v3"
|
||||
)
|
||||
|
||||
type ValueParser interface {
|
||||
ParseValue(argument string) interface{}
|
||||
Parse(argument string, customTag string) *yaml.Node
|
||||
}
|
||||
|
||||
type valueParser struct{}
|
||||
type valueParser struct {
|
||||
}
|
||||
|
||||
func NewValueParser() ValueParser {
|
||||
return &valueParser{}
|
||||
}
|
||||
|
||||
func (v *valueParser) ParseValue(argument string) interface{} {
|
||||
var value, err interface{}
|
||||
var inQuotes = len(argument) > 0 && argument[0] == '"'
|
||||
if !inQuotes {
|
||||
value, err = strconv.ParseFloat(argument, 64)
|
||||
if err == nil {
|
||||
return value
|
||||
}
|
||||
value, err = strconv.ParseBool(argument)
|
||||
if err == nil {
|
||||
return value
|
||||
}
|
||||
func (v *valueParser) Parse(argument string, customTag string) *yaml.Node {
|
||||
if argument == "[]" {
|
||||
return make([]interface{}, 0)
|
||||
return &yaml.Node{Tag: "!!seq", Kind: yaml.SequenceNode}
|
||||
}
|
||||
return argument
|
||||
}
|
||||
return argument[1 : len(argument)-1]
|
||||
return &yaml.Node{Value: argument, Tag: customTag, Kind: yaml.ScalarNode}
|
||||
}
|
||||
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in New Issue
Block a user