mikefarah / yq Goto Github PK
View Code? Open in Web Editor NEWyq is a portable command-line YAML, JSON, XML, CSV, TOML and properties processor
Home Page: https://mikefarah.gitbook.io/yq/
License: MIT License
yq is a portable command-line YAML, JSON, XML, CSV, TOML and properties processor
Home Page: https://mikefarah.gitbook.io/yq/
License: MIT License
Add support for built-in function 'keys, keys_unsorted'
The builtin function keys, when given an object, returns its keys in an array.
The keys are sorted “alphabetically”, by unicode codepoint order. This is not an order that makes particular sense in any particular language, but you can count on it being the same for any two objects with the same set of keys, regardless of locale settings.
When keys is given an array, it returns the valid indices for that array: the integers from 0 to length-1.
The keys_unsorted function is just like keys, but if the input is an object then the keys will not be sorted, instead the keys will roughly be in insertion order.
Add support for Operator '*, /, and %'
These infix operators behave as expected when given two numbers. Division by zero raises an error. x % y computes x modulo y.
Multiplying a string by a number produces the concatenation of that string that many times. "x" * 0 produces null.
Dividing a string by another splits the first using the second as separators.
Multiplying two objects will merge them recursively: this works like addition but if both objects contain a value for the same key, and the values are objects, the two are merged with the same strategy.
Add support for Pipe
The | operator combines two filters by feeding the output(s) of the one on the left into the input of the one on the right. It’s pretty much the same as the Unix shell’s pipe, if you’re used to that.
If the one on the left produces multiple results, the one on the right will be run for each of those results. So, the expression .[] | .foo retrieves the “foo” field of each element of the input array.
Note that .a.b.c is the same as .a | .b | .c.
Note too that . is the input value at the particular stage in a “pipeline”, specifically: where the . expression appears. Thus .a | . | .b is the same as .a.b, as the . in the middle refers to whatever value .a produced.
Version: 1.10
File: (project.yml)
metadata:
name: example
version: 0.4.0
pretag: dev
Command:
yaml write -i project.yml metadata.pretag ''
Response:
panic: runtime error: index out of range
goroutine 1 [running]:
panic(0x5e3500, 0xc4200100c0)
/usr/local/Cellar/go/1.7.5/libexec/src/runtime/panic.go:500 +0x1a1
main.parseValue(0x7ffd1417ced1, 0x0, 0x1, 0xc4200ae880)
/Users/mikefarah/dev/go/src/github.com/mikefarah/yaml/yaml.go:199 +0x83e
main.updateYaml(0xc4200bc2d0, 0x3, 0x5, 0x0, 0xc4200e3c77)
/Users/mikefarah/dev/go/src/github.com/mikefarah/yaml/yaml.go:188 +0x2e1
main.writeProperty(0xc4201481e0, 0xc4200bc2d0, 0x3, 0x5)
/Users/mikefarah/dev/go/src/github.com/mikefarah/yaml/yaml.go:162 +0x58
github.com/mikefarah/yaml/Godeps/_workspace/src/github.com/spf13/cobra.(*Command).execute(0xc4201481e0, 0xc4200bc280, 0x5, 0x5, 0xc4201481e0, 0xc4200bc280)
/Users/mikefarah/dev/go/src/github.com/mikefarah/yaml/Godeps/_workspace/src/github.com/spf13/cobra/command.go:547 +0x411
github.com/mikefarah/yaml/Godeps/_workspace/src/github.com/spf13/cobra.(*Command).Execute(0xc4201485a0, 0xc4200e3f10, 0x3)
/Users/mikefarah/dev/go/src/github.com/mikefarah/yaml/Godeps/_workspace/src/github.com/spf13/cobra/command.go:630 +0x398
main.main()
/Users/mikefarah/dev/go/src/github.com/mikefarah/yaml/yaml.go:41 +0x449
Seems like setting a value to empty should be valid, but instead it will panic.
Add support for built-in function 'getpath(PATHS)'
The builtin function getpath outputs the values in . found at each path in PATHS.
When updating a Yaml file, the original quotes are not maintained, e.g. 'version' originally has single quotes, but this ends up with double quotes.
version: '2'
services:
test:
image: ubuntu:14.04
stdin_open: true
tty: true
yaml w docker-compose.yml services.test.image nginx:master
services:
test:
image: nginx:master
stdin_open: true
tty: true
version: "2"
Add support for built-in function 'add'
The filter add takes as input an array, and produces as output the elements of the array added together. This might mean summed, concatenated or merged depending on the types of the elements of the input array - the rules are the same as those for the + operator (described above).
If the input is an empty array, add returns null.
Add support for built-in function 'to_entries, from_entries, with_entries'
These functions convert between an object and an array of key-value pairs. If to_entries is passed an object, then for each k: v entry in the input, the output array includes {"key": k, "value": v}.
from_entries does the opposite conversion, and with_entries(foo) is a shorthand for to_entries | map(foo) | from_entries, useful for doing some operation to all keys and values of an object. from_entries accepts key, Key, name, Name, value and Value as keys.
Add support for Operator '+'
The operator + takes two filters, applies them both to the same input, and adds the results together. What “adding” means depends on the types involved:
Numbers are added by normal arithmetic.
Arrays are added by being concatenated into a larger array.
Strings are added by being joined into a larger string.
Objects are added by merging, that is, inserting all the key-value pairs from both objects into a single combined object. If both objects contain a value for the same key, the object on the right of the + wins. (For recursive merge use the * operator.)
null can be added to any value, and returns the other value unchanged.
The Swagger / OpenAPI yaml files have responses where the code is the key.
responses:
201:
description: Version successfully provisioned
schema:
$ref: '#/definitions/versionProvision'
yaml -j read api-docs/api.yaml paths
panic: interface conversion: interface {} is int, not string
goroutine 1 [running]:
main.toJSON(0x5e0500, 0xc0420ef780, 0xc0420b39a0, 0xc04208a8a8)
/Users/mikefarah/dev/go/src/github.com/mikefarah/yaml/json_converter.go:29 +0x37c
main.toJSON(0x5e0500, 0xc0420ef7c0, 0xc0420b3a78, 0xc04208a748)
/Users/mikefarah/dev/go/src/github.com/mikefarah/yaml/json_converter.go:29 +0x2c0
main.toJSON(0x5e0500, 0xc0420ef800, 0xc0420712f0, 0x0)
/Users/mikefarah/dev/go/src/github.com/mikefarah/yaml/json_converter.go:29 +0x2c0
main.toJSON(0x5e0500, 0xc0420f5c20, 0xc04207ce00, 0xb)
/Users/mikefarah/dev/go/src/github.com/mikefarah/yaml/json_converter.go:29 +0x2c0
main.jsonToString(0x5e0500, 0xc0420f5c20, 0x5aae17, 0xc042048c00)
/Users/mikefarah/dev/go/src/github.com/mikefarah/yaml/json_converter.go:9 +0x49
main.print(0x5e0500, 0xc0420f5c20)
/Users/mikefarah/dev/go/src/github.com/mikefarah/yaml/yaml.go:251 +0x4f
main.readProperty(0xc0420ba000, 0xc042070db0, 0x2, 0x3)
/Users/mikefarah/dev/go/src/github.com/mikefarah/yaml/yaml.go:116 +0x6d
github.com/spf13/cobra.(*Command).execute(0xc0420ba000, 0xc042070cc0, 0x3, 0x3, 0xc0420ba000, 0xc042070cc0)
/Users/mikefarah/dev/go/src/github.com/spf13/cobra/command.go:651 +0x241
github.com/spf13/cobra.(*Command).ExecuteC(0xc0420ba6c0, 0xc0420b3f78, 0xc, 0xc042046780)
/Users/mikefarah/dev/go/src/github.com/spf13/cobra/command.go:726 +0x340
github.com/spf13/cobra.(*Command).Execute(0xc0420ba6c0, 0xc0420b3f60, 0x3)
/Users/mikefarah/dev/go/src/github.com/spf13/cobra/command.go:685 +0x32
main.main()
/Users/mikefarah/dev/go/src/github.com/mikefarah/yaml/yaml.go:40 +0x428
Build a config.yml like this:
test:
- aa
When I use yaml r config.yml test[0]
, it output aa
.
When I use yaml w -i config.yml test[0] bb
, it gives this error.
panic: interface conversion: interface {} is []interface {}, not map[interface {}]interface {}
goroutine 1 [running]:
panic(0x665980, 0xc820070780)
/usr/local/Cellar/go/1.6/libexec/src/runtime/panic.go:464 +0x3e6
main.write(0xc820076f90, 0x7ffc1e8d26be, 0x4, 0xc82006fbd0, 0x1, 0x1, 0x5fe200, 0xc820074b20)
/Users/mikefarah/dev/go/src/github.com/mikefarah/yaml/data_navigator.go:13 +0x261
main.updateYaml(0xc820076cf0, 0x3, 0x3, 0x0, 0x0)
/Users/mikefarah/dev/go/src/github.com/mikefarah/yaml/yaml.go:122 +0x278
main.writeProperty(0xc82010c1e0, 0xc820076cf0, 0x3, 0x3)
/Users/mikefarah/dev/go/src/github.com/mikefarah/yaml/yaml.go:98 +0x4a
github.com/mikefarah/yaml/Godeps/_workspace/src/github.com/spf13/cobra.(_Command).execute(0xc82010c1e0, 0xc820076b70, 0x3, 0x3, 0x0, 0x0)
/Users/mikefarah/dev/go/src/github.com/mikefarah/yaml/Godeps/_workspace/src/github.com/spf13/cobra/command.go:547 +0x85a
github.com/mikefarah/yaml/Godeps/_workspace/src/github.com/spf13/cobra.(_Command).Execute(0xc82010c3c0, 0x0, 0x0)
/Users/mikefarah/dev/go/src/github.com/mikefarah/yaml/Godeps/_workspace/src/github.com/spf13/cobra/command.go:630 +0x46a
main.main()
/Users/mikefarah/dev/go/src/github.com/mikefarah/yaml/yaml.go:29 +0x36d
So is this an issue or I'm using wrong way to write Array?
This is not an issue, but very important task for me:
let.s assume I have following yaml:
test:
a:
- name: name1
value: 1
- name: name2
value: 2
and I need to update only value where name == name1
Is it possible with this tool?
Add support for Operator '-'
As well as normal arithmetic subtraction on numbers, the - operator can be used on arrays to remove all occurrences of the second array’s elements from the first array.
test.yml
UseMock: true
abc: 123
When I do yaml r -j testyml > test.json, it make the json file like
{"UseMock":true,"abc":123}
I want to convert true (bool) to true (string)
i.e
Require
{"UseMock":"true","abc":123}
Add support for built-in function 'delpaths(PATHS)'
The builtin function delpaths sets the PATHS in .. PATHS must be an array of paths, where each path is an array of strings and numbers.
Add support for Array/String Slice
The .[10:15] syntax can be used to return a subarray of an array or substring of a string. The array returned by .[10:15] will be of length 5, containing the elements from index 10 (inclusive) to index 15 (exclusive). Either index may be negative (in which case it counts backwards from the end of the array), or omitted (in which case it refers to the start or end of the array).
a: Easy! as one two three
b:
c: 2
d: [3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15]
e:
- name: fred
value: 3
- name: sam
value: 4
$ yaml r sample.yaml b.d[2:5]
- 5
- 6
- 7
- 8
Add support for built-in function 'utf8bytelength'
The builtin function utf8bytelength outputs the number of bytes used to encode a string in UTF-8.
Add support for built-in function 'in'
The builtin function in returns whether or not the input key is in the given object, or the input index corresponds to an element in the given array. It is, essentially, an inverse version of has.
Just did some testing on new append feature and noticed following bug:
command:
echo -e "a: 2\n" | yaml w - b[+] v
result:
a: 2
b:
Looks like one line fix:
change line: array = make([]interface{}, 1)
to: array = make([]interface{}, 0)
Running command yaml read test.yaml gather_facts
results in output null, expected result is false. Culprit is the -
in-front of become, which is valid yaml. If I remove it, it works but it should obviously work with it as well.
---
- become: true
gather_facts: false
hosts: lalaland
name: "Apply smth"
roles:
- lala
- land
serial: 1
yaml w foo.yaml a []
want: a: []
got: a: '[]'
Perhaps the CLI syntax would need to be different to disambiguate []
vs "[]"
.
The CLI strips out comments given the following yaml file:
# comment
a:
b:
Using the following command for my test:
yaml w -i test.yml a.b.c[0] "test"
Add support for built-in function 'empty'
empty returns no results. None at all. Not even null.
Say I have:
---
mykey: myvalue
---
mykey: myothervalue
---
mykey: myotherothervalue
I'd expect the tool to be able to handle all three documents and give me a list of values when I run
yaml r myfile.yaml mykey
, instead it'd just give me the first value.
Is this something you'd be willing to add as a feature? Happy to work on it myself but I have limited go knowledge.
Add support for built-in function 'length'
The builtin function length gets the length of various different types of value:
The length of a string is the number of Unicode codepoints it contains (which will be the same as its JSON-encoded length in bytes if it’s pure ASCII).
The length of an array is the number of elements.
The length of an object is the number of key-value pairs.
The length of null is zero.
Add support for built-in function 'del(path_expression)'
The builtin function del removes a key and its corresponding value from an object.
Add support for built-in function 'setpath(PATHS; VALUE)'
The builtin function setpath sets the PATHS in . to VALUE.
It seems running
go get github.com/mikefarah/yaml
will hanging and give no response. Has this way of installation been deprecated?
Add support for built-in function 'arrays, objects, iterables, booleans, numbers, normals, finites, strings, nulls, values, scalars'
These built-ins select only inputs that are arrays, objects, iterables (arrays or objects), booleans, numbers, normal numbers, finite numbers, strings, null, non-null values, and non-iterables, respectively.
Add support for built-in function 'map(x), map_values(x)'
For any filter x, map(x) will run that filter for each element of the input array, and return the outputs in a new array. map(.+1) will increment each element of an array of numbers.
Similarly, map_values(x) will run that filter for each element, but it will return an object when an object is passed.
map(x) is equivalent to [.[] | x]. In fact, this is how it’s defined. Similarly, map_values(x) is defined as .[] |= x.
Given a sample.yaml file of:
b:
c: 2
then
yaml w -i sample.yaml b.d cat
Expected result:
b:
c: 2
d: cat
Add ability to merge multiple yaml files.
example:
yaml merge data1.yaml data2.yaml data3.yaml
yaml merge --overwrite data1.yaml data2.yaml data3.yaml
yaml merge -i data1.yaml data2.yaml data3.yaml
If agreeable, I can submit a PR with the enhancement.
When using the write command, the order of the fields in the Yaml file is not maintained.
version: '2'
services:
test:
image: ubuntu:14.04
stdin_open: true
tty: true
yaml w docker-compose.yml services.test.image nginx:master
services:
test:
image: nginx:master
stdin_open: true
tty: true
version: "2"
With the addition of the merge
command, the documentation needs to be updated to provide more details.
The following two examples don't seem to work for me on Linux using version 1.11.
$ echo 'alphabet' | yaml r -
[error parsing data: yaml: unmarshal errors:
line 1: cannot unmarshal !!str `alphabet` into yaml.MapSlice]
$ echo -e '- alpha\n- beta' | yaml r -
[error parsing data: yaml: unmarshal errors:
line 1: cannot unmarshal !!str `alpha` into yaml.MapItem
line 2: cannot unmarshal !!str `beta` into yaml.MapItem]
Is there possible to support write key with empty value like that:
networks:
networkName:
In my case, I have to write yaml arrays to file in this way
yaml w -i $COMPOSE_FILE services.$peerContainer.environment[0] a
yaml w -i $COMPOSE_FILE services.$peerContainer.environment[1] b
yaml w -i $COMPOSE_FILE services.$peerContainer.environment[2] c
yaml w -i $COMPOSE_FILE services.$peerContainer.environment[3] d
yaml w -i $COMPOSE_FILE services.$peerContainer.environment[4] e
yaml w -i $COMPOSE_FILE services.$peerContainer.environment[5] f
yaml w -i $COMPOSE_FILE services.$peerContainer.environment[6] g
which manually input index is clumsy. script file option might help, but I do not like to use this method
Is there any plan to support new feature like that
yaml w -i --append $COMPOSE_FILE services.$peerContainer.environment[] newValPush2end
I'm trying to read a value of write_files[0].content and then set another value to the same path.
It doesn't work with write_files[0].path
$ yaml r templates/coreos-install-cloud-config/skeleton.yml \
write_files[0].path
bash: no matches found: write_files[0].path
Doesn't work with write_files[0]
yaml r templates/coreos-install-cloud-config/skeleton.yml \
write_files[0]
bash: no matches found: write_files[0]
But if I request the full value of write_files the I get what I asked for:
yaml r templates/coreos-install-cloud-config/skeleton.yml \
write_files
- path: /root/process-cloud-config.sh
permissions: "0755"
owner: root
content: null
- path: /root/cloud-config.yml
permissions: "0644"
owner: root
content: null
Here is the file I'm processing:
write_files:
- path: /root/process-cloud-config.sh
permissions: "0755"
owner: root
content:
- path: /root/cloud-config.yml
permissions: "0644"
owner: root
content:
Can you advise how to handle my case with yaml tool?
I'm trying to create this:
applications:
- name: wasabi
- name: oscar
By doing this:
touch manifest.yml
yaml w -i manifest.yml applications[0].name wasabi
yaml w -i manifest.yml applications[1].name oscar
but... the third line (yaml w -i manifest.yml applications[1].name oscar
) results in this:
# yaml w -i manifest.yml applications[1].name oscar
panic: runtime error: index out of range
goroutine 1 [running]:
panic(0x5e3500, 0xc420010080)
/usr/local/Cellar/go/1.7.5/libexec/src/runtime/panic.go:500 +0x1a1
main.writeArray(0x5cb680, 0xc42000ec60, 0xc4200487d0, 0x2, 0x3, 0x5cfbc0, 0xc420010fd0, 0xc4200b1980, 0x4d3040, 0xc420066c90)
/Users/mikefarah/dev/go/src/github.com/mikefarah/yaml/data_navigator.go:85 +0x5c3
main.updatedChildValue(0x5cb680, 0xc42000ec60, 0xc4200487d0, 0x2, 0x3, 0x5cfbc0, 0xc420010fd0, 0x4146be, 0xc42000ece0)
/Users/mikefarah/dev/go/src/github.com/mikefarah/yaml/data_navigator.go:61 +0x1a6
main.writeMap(0x5da5a0, 0xc42000ece0, 0xc4200487c0, 0x3, 0x4, 0x5cfbc0, 0xc420010fd0, 0xc4200b1b47, 0xc4200b1b60, 0x52f630)
/Users/mikefarah/dev/go/src/github.com/mikefarah/yaml/data_navigator.go:44 +0x38c
main.updateYaml(0xc420048740, 0x3, 0x4, 0xc420010fb5, 0xc4200b1c77)
/Users/mikefarah/dev/go/src/github.com/mikefarah/yaml/yaml.go:191 +0x2de
main.writeProperty(0xc4201021e0, 0xc420048740, 0x3, 0x4)
/Users/mikefarah/dev/go/src/github.com/mikefarah/yaml/yaml.go:167 +0x58
github.com/mikefarah/yaml/Godeps/_workspace/src/github.com/spf13/cobra.(*Command).execute(0xc4201021e0, 0xc4200485c0, 0x4, 0x4, 0xc4201021e0, 0xc4200485c0)
/Users/mikefarah/dev/go/src/github.com/mikefarah/yaml/Godeps/_workspace/src/github.com/spf13/cobra/command.go:547 +0x411
github.com/mikefarah/yaml/Godeps/_workspace/src/github.com/spf13/cobra.(*Command).Execute(0xc4201025a0, 0xc4200b1f10, 0x3)
/Users/mikefarah/dev/go/src/github.com/mikefarah/yaml/Godeps/_workspace/src/github.com/spf13/cobra/command.go:630 +0x398
main.main()
/Users/mikefarah/dev/go/src/github.com/mikefarah/yaml/yaml.go:41 +0x449
I'm new to this project, so not sure if i'm doing something wrong... or if I've hit a bug.
Given the following Kubernetes YAML configuration file:
apiVersion: extensions/v1beta1
kind: Deployment
metadata:
name: somename
spec:
revisionHistoryLimit: 5
minReadySeconds: 10
strategy:
type: RollingUpdate
rollingUpdate:
maxUnavailable: 0
maxSurge: 1
replicas: 1
template:
metadata:
labels:
microservice: somename
spec:
containers:
- name: serviceapi
image: myimage:0.0.6
ports:
- containerPort: 8080
env:
##### ENVIRONMENT VARIABLES
- name: somename
valueFrom:
configMapKeyRef:
name: serviceapi-environment-configuration
key: somekey
---
apiVersion: v1
kind: Service
metadata:
name: somename
labels:
microservice: somename
spec:
type: NodePort
ports:
- port: 8080
selector:
microservice: somename
---
apiVersion: v1
kind: ConfigMap
metadata:
name: some-name
namespace: default
data:
someData: data
This command will work:
./yaml w -i myfile.yaml spec.template.spec.containers[0].image myimage:0.0.19
The image
value will be replaced, however, the file will then change to this:
apiVersion: extensions/v1beta1
kind: Deployment
metadata:
name: somename
spec:
revisionHistoryLimit: 5
minReadySeconds: 10
strategy:
type: RollingUpdate
rollingUpdate:
maxUnavailable: 0
maxSurge: 1
replicas: 1
template:
metadata:
labels:
microservice: somename
spec:
containers:
- name: serviceapi
image: myimage:0.0.19
ports:
- containerPort: 8080
env:
##### ENVIRONMENT VARIABLES
- name: somename
valueFrom:
configMapKeyRef:
name: serviceapi-environment-configuration
key: somekey
As you can see, the Services and ConfigMap sections (denoted with ---
) have disappeared.
I can't tell if this is expected, or a bug. Let's say I have the following Yaml file:
title: "My Book"
tags:
- "adventure"
- "novel"
and I run the following command: `yaml write -i mybooks.yml author "J.K. Rowling"
The updated Yaml file now looks like:
title: My Book
tags:
- adventure
- novel
author: J.K. Rowling
This GitHub Issue is due to the fact that the 'tags' list has lost its indention. That didn't look like valid Yaml to me so I ran it through http://www.yamllint.com/. While the Yaml did validate, the tags
list was "corrected" to the indention I had it previously. So is this a bug?
Also, as you can see, the quotes around the strings are gone. I can see from this issue that it's because of the parser so I guess we can't do anything about it. Sucks though.
Is it currently possible to have the CLI only list the top level keys? For example, given the following yaml file:
a:
b:
c:
- 'test'
- "test2"
d:
e:
Is there a way to only list b
, d
and e
and no other subkeys with something like yaml r test.yml a
?
Add support for built-in function 'select(boolean_expression)'
The function select(foo) produces its input unchanged if foo returns true for that input, and produces no output otherwise.
It’s useful for filtering lists: [1,2,3] | map(select(. >= 2)) will give you [2,3].
Right now, yaml --version
(or even yaml version
) doesn't return the version of the release. I've seen in other Issues the author refer to release numbers. This should be outputted.
Add support for built-in function 'has(key)'
The builtin function has returns whether the input object has the given key, or the input array has an element at the given index.
has($key) has the same effect as checking whether $key is a member of the array returned by keys, although has will be faster.
yaml w -i task-output/manifest.yml 'env.JAVA_OPTS' '-Djava.security.egd=file:///dev/urandom'
Usage:
yaml write [yaml_file] [path] [value] [flags]
Aliases:
write, w
Examples:
yaml write things.yaml a.b.c cat
yaml write --inplace things.yaml a.b.c cat
yaml w -i things.yaml a.b.c cat
yaml w --script update_script.yaml things.yaml
yaml w -i -s update_script.yaml things.yaml
Flags:
-i, --inplace[=false]: update the yaml file inplace
-s, --script="": yaml script for updating yaml
Global Flags:
-J, --fromjson[=false]: input as json
-j, --tojson[=false]: output as json
-t, --trim[=true]: trim yaml output
-v, --verbose[=false]: verbose mode
Error: unknown shorthand flag: 'D' in -Djava.security.egd=file:///dev/urandom
Given the following example:
version: '2'
services:
test:
image: ubuntu:14.04
stdin_open: true
tty: true
When I try to update the image
key, using both the in place and write to stdout command:
yaml w docker-compose.yml services.test.image nginx:master
yaml w -i docker-compose.yml services.test.image nginx:master
I get unexpected output:
services:
test:
image: nginx:master
stdin_open: true
tty: true
version: "2"
Add support for Comma
If two filters are separated by a comma, then the same input will be fed into both and the two filters’
output value streams will be concatenated in order: first, all of the outputs produced by the left expression, and then all of the outputs produced by the right. For instance, filter .foo, .bar, produces both the “foo” fields and “bar” fields as separate outputs.
a: Easy! as one two three
b:
c: 2
d: [3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15]
e:
- name: fred
value: 3
- name: sam
value: 4
$ yaml r sample.yaml 'b.e[0].name,b.e[1].name'
fred sam
When attempting to extract an entry from an empty array, the program exits rather abruptly with a panic:
$ echo 'a: []' | yaml r - 'a[0]'
panic: runtime error: index out of range
goroutine 1 [running]:
main.readArray(0x3c64e0, 0x0, 0x0, 0x0, 0xc20801e670, 0x0, 0x0, 0x0, 0x0)
/Users/morgan/Projects/golang/src/github.com/mikefarah/yaml/data_navigator.go:65 +0xd6
main.recurse(0x1b5300, 0xc20801e600, 0x7fff5fbff9e3, 0x1, 0xc20801e670, 0x0, 0x0, 0x0, 0x0)
/Users/morgan/Projects/golang/src/github.com/mikefarah/yaml/data_navigator.go:52 +0x36e
main.calculateValue(0x1b5300, 0xc20801e600, 0xc20801e670, 0x1, 0x1, 0x0, 0x0)
/Users/morgan/Projects/golang/src/github.com/mikefarah/yaml/data_navigator.go:80 +0xcb
main.readMap(0xc20803ca50, 0x7fff5fbff9e1, 0x1, 0xc20801e670, 0x1, 0x1, 0x0, 0x0)
/Users/morgan/Projects/golang/src/github.com/mikefarah/yaml/data_navigator.go:25 +0x182
main.read(0xc20801e520, 0x2, 0x2, 0x0, 0x0)
/Users/morgan/Projects/golang/src/github.com/mikefarah/yaml/yaml.go:94 +0x196
main.readProperty(0xc208088000, 0xc20801e520, 0x2, 0x2)
/Users/morgan/Projects/golang/src/github.com/mikefarah/yaml/yaml.go:80 +0x3c
github.com/mikefarah/yaml/Godeps/_workspace/src/github.com/spf13/cobra.(*Command).execute(0xc208088000, 0xc20801e3a0, 0x2, 0x2, 0x0, 0x0)
/Users/morgan/Projects/golang/src/github.com/mikefarah/yaml/Godeps/_workspace/src/github.com/spf13/cobra/command.go:547 +0x82f
github.com/mikefarah/yaml/Godeps/_workspace/src/github.com/spf13/cobra.(*Command).Execute(0xc2080883c0, 0x0, 0x0)
/Users/morgan/Projects/golang/src/github.com/mikefarah/yaml/Godeps/_workspace/src/github.com/spf13/cobra/command.go:630 +0x414
main.main()
/Users/morgan/Projects/golang/src/github.com/mikefarah/yaml/yaml.go:29 +0x3c9
This is a bit user-hostile, and doesn't really point to where the issue arises in the source file in order to debug it.
This script doesnt work for:
# parameters.yml
parameters:
database.name: app
$ yaml read parameters.yml parameters.database.name
null
I think this is valid yaml.
Am I missing something?
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.