mirror of
https://github.com/mikefarah/yq.git
synced 2024-12-19 20:19:04 +00:00
174 lines
16 KiB
JSON
174 lines
16 KiB
JSON
{
|
|
"docs": [
|
|
{
|
|
"location": "/",
|
|
"text": "yq\n\u00b6\n\n\nyq is a lightweight and portable command-line YAML processor\n\n\nThe aim of the project is to be the \njq\n or sed of yaml files.\n\n\nbrew install yq\n\u00b6\n\n\ndownload latest binary\n\u00b6\n\n\nget the source\n\u00b6\n\n\ngo get github.com/mikefarah/yq\n\n\n\n\n.zip\n or \ntar.gz\n\n\nView on GitHub",
|
|
"title": "Install"
|
|
},
|
|
{
|
|
"location": "/#yq",
|
|
"text": "yq is a lightweight and portable command-line YAML processor The aim of the project is to be the jq or sed of yaml files.",
|
|
"title": "yq"
|
|
},
|
|
{
|
|
"location": "/#brew-install-yq",
|
|
"text": "",
|
|
"title": "brew install yq"
|
|
},
|
|
{
|
|
"location": "/#download-latest-binary",
|
|
"text": "",
|
|
"title": "download latest binary"
|
|
},
|
|
{
|
|
"location": "/#get-the-source",
|
|
"text": "go get github.com/mikefarah/yq .zip or tar.gz View on GitHub",
|
|
"title": "get the source"
|
|
},
|
|
{
|
|
"location": "/read/",
|
|
"text": "yq r <yaml_file|json_file> <path>\n\n\n\n\nThis command can take a json file as input too, and will output yaml unless specified to export as json (-j)\n\n\nBasic\n\u00b6\n\n\nGiven a sample.yaml file of:\n\n\nb:\n c: 2\n\n\n\n\nthen\n\n\nyq r sample.yaml b.c\n\n\n\n\nwill output the value of '2'.\n\n\nFrom Stdin\n\u00b6\n\n\nGiven a sample.yaml file of:\n\n\ncat sample.yaml | yq r - b.c\n\n\n\n\nwill output the value of '2'.\n\n\nSplat\n\u00b6\n\n\nGiven a sample.yaml file of:\n\n\n---\nbob:\n item1:\n cats: bananas\n item2:\n cats: apples\n\n\n\n\nthen\n\n\nyq r sample.yaml bob.*.cats\n\n\n\n\nwill output\n\n\n- bananas\n- apples\n\n\n\n\nHandling '.' in the yaml key\n\u00b6\n\n\nGiven a sample.yaml file of:\n\n\nb.x:\n c: 2\n\n\n\n\nthen\n\n\nyq r sample.yaml \\\"b.x\\\".c\n\n\n\n\nwill output the value of '2'.\n\n\nArrays\n\u00b6\n\n\nYou can give an index to access a specific element:\ne.g.: given a sample file of\n\n\nb:\n e:\n - name: fred\n value: 3\n - name: sam\n value: 4\n\n\n\n\nthen\n\n\nyq r sample.yaml b.e[1].name\n\n\n\n\nwill output 'sam'\n\n\nArray Splat\n\u00b6\n\n\ne.g.: given a sample file of\n\n\nb:\n e:\n - name: fred\n value: 3\n - name: sam\n value: 4\n\n\n\n\nthen\n\n\nyq r sample.yaml b.e[*].name\n\n\n\n\nwill output:\n\n\n- fred\n- sam\n\n\n\n\nKeys with dots\n\u00b6\n\n\nWhen specifying a key that has a dot use key lookup indicator.\n\n\nb:\n foo.bar: 7\n\n\n\n\nyaml r sample.yaml b[foo.bar]\n\n\n\n\nyaml w sample.yaml b[foo.bar] 9\n\n\n\n\nAny valid yaml key can be specified as part of a key lookup.",
|
|
"title": "Read"
|
|
},
|
|
{
|
|
"location": "/read/#basic",
|
|
"text": "Given a sample.yaml file of: b:\n c: 2 then yq r sample.yaml b.c will output the value of '2'.",
|
|
"title": "Basic"
|
|
},
|
|
{
|
|
"location": "/read/#from-stdin",
|
|
"text": "Given a sample.yaml file of: cat sample.yaml | yq r - b.c will output the value of '2'.",
|
|
"title": "From Stdin"
|
|
},
|
|
{
|
|
"location": "/read/#splat",
|
|
"text": "Given a sample.yaml file of: ---\nbob:\n item1:\n cats: bananas\n item2:\n cats: apples then yq r sample.yaml bob.*.cats will output - bananas\n- apples",
|
|
"title": "Splat"
|
|
},
|
|
{
|
|
"location": "/read/#handling-in-the-yaml-key",
|
|
"text": "Given a sample.yaml file of: b.x:\n c: 2 then yq r sample.yaml \\\"b.x\\\".c will output the value of '2'.",
|
|
"title": "Handling '.' in the yaml key"
|
|
},
|
|
{
|
|
"location": "/read/#arrays",
|
|
"text": "You can give an index to access a specific element:\ne.g.: given a sample file of b:\n e:\n - name: fred\n value: 3\n - name: sam\n value: 4 then yq r sample.yaml b.e[1].name will output 'sam'",
|
|
"title": "Arrays"
|
|
},
|
|
{
|
|
"location": "/read/#array-splat",
|
|
"text": "e.g.: given a sample file of b:\n e:\n - name: fred\n value: 3\n - name: sam\n value: 4 then yq r sample.yaml b.e[*].name will output: - fred\n- sam",
|
|
"title": "Array Splat"
|
|
},
|
|
{
|
|
"location": "/read/#keys-with-dots",
|
|
"text": "When specifying a key that has a dot use key lookup indicator. b:\n foo.bar: 7 yaml r sample.yaml b[foo.bar] yaml w sample.yaml b[foo.bar] 9 Any valid yaml key can be specified as part of a key lookup.",
|
|
"title": "Keys with dots"
|
|
},
|
|
{
|
|
"location": "/write/",
|
|
"text": "yq w <yaml_file|json_file> <path> <new value>\n\n\n\n\nThis command can take a json file as input too, and will output yaml unless specified to export as json (-j)\n\n\nTo Stdout\n\u00b6\n\n\nGiven a sample.yaml file of:\n\n\nb:\n c: 2\n\n\n\n\nthen\n\n\nyq w sample.yaml b.c cat\n\n\n\n\nwill output:\n\n\nb:\n c: cat\n\n\n\n\nFrom STDIN\n\u00b6\n\n\ncat sample.yaml | yq w - b.c blah\n\n\n\n\nAdding new fields\n\u00b6\n\n\nAny missing fields in the path will be created on the fly.\n\n\nGiven a sample.yaml file of:\n\n\nb:\n c: 2\n\n\n\n\nthen\n\n\nyq w sample.yaml b.d[0] \"new thing\"\n\n\n\n\nwill output:\n\n\nb:\n c: cat\n d:\n - new thing\n\n\n\n\nAppending value to an array field\n\u00b6\n\n\nGiven a sample.yaml file of:\n\n\nb:\n c: 2\n d:\n - new thing\n - foo thing\n\n\n\n\nthen\n\n\nyq w sample.yaml b.d[+] \"bar thing\"\n\n\n\n\nwill output:\n\n\nb:\n c: cat\n d:\n - new thing\n - foo thing\n - bar thing\n\n\n\n\nUpdating files in-place\n\u00b6\n\n\nGiven a sample.yaml file of:\n\n\nb:\n c: 2\n\n\n\n\nthen\n\n\nyq w -i sample.yaml b.c cat\n\n\n\n\nwill update the sample.yaml file so that the value of 'c' is cat.\n\n\nUpdating multiple values with a script\n\u00b6\n\n\nGiven a sample.yaml file of:\n\n\nb:\n c: 2\n e:\n - name: Billy Bob\n\n\n\n\nand a script update_instructions.yaml of:\n\n\nb.c: 3\nb.e[0].name: Howdy Partner\n\n\n\n\nthen\n\n\nyq w -s update_instructions.yaml sample.yaml\n\n\n\n\nwill output:\n\n\nb:\n c: 3\n e:\n - name: Howdy Partner\n\n\n\n\nAnd, of course, you can pipe the instructions in using '-':\n\n\ncat update_instructions.yaml | yq w -s - sample.yaml\n\n\n\n\nValues starting with a hyphen (or dash)\n\u00b6\n\n\nThe flag terminator needs to be used to stop the app from attempting to parse the subsequent arguments as flags:\n\n\nyq w -- my.path -3\n\n\n\n\nwill output\n\n\nmy:\n path: -3\n\n\n\n\nKeys with dots\n\u00b6\n\n\nWhen specifying a key that has a dot use key lookup indicator.\n\n\nb:\n foo.bar: 7\n\n\n\n\nyaml r sample.yaml b[foo.bar]\n\n\n\n\nyaml w sample.yaml b[foo.bar] 9\n\n\n\n\nAny valid yaml key can be specified as part of a key lookup.",
|
|
"title": "Write/Update"
|
|
},
|
|
{
|
|
"location": "/write/#to-stdout",
|
|
"text": "Given a sample.yaml file of: b:\n c: 2 then yq w sample.yaml b.c cat will output: b:\n c: cat",
|
|
"title": "To Stdout"
|
|
},
|
|
{
|
|
"location": "/write/#from-stdin",
|
|
"text": "cat sample.yaml | yq w - b.c blah",
|
|
"title": "From STDIN"
|
|
},
|
|
{
|
|
"location": "/write/#adding-new-fields",
|
|
"text": "Any missing fields in the path will be created on the fly. Given a sample.yaml file of: b:\n c: 2 then yq w sample.yaml b.d[0] \"new thing\" will output: b:\n c: cat\n d:\n - new thing",
|
|
"title": "Adding new fields"
|
|
},
|
|
{
|
|
"location": "/write/#appending-value-to-an-array-field",
|
|
"text": "Given a sample.yaml file of: b:\n c: 2\n d:\n - new thing\n - foo thing then yq w sample.yaml b.d[+] \"bar thing\" will output: b:\n c: cat\n d:\n - new thing\n - foo thing\n - bar thing",
|
|
"title": "Appending value to an array field"
|
|
},
|
|
{
|
|
"location": "/write/#updating-files-in-place",
|
|
"text": "Given a sample.yaml file of: b:\n c: 2 then yq w -i sample.yaml b.c cat will update the sample.yaml file so that the value of 'c' is cat.",
|
|
"title": "Updating files in-place"
|
|
},
|
|
{
|
|
"location": "/write/#updating-multiple-values-with-a-script",
|
|
"text": "Given a sample.yaml file of: b:\n c: 2\n e:\n - name: Billy Bob and a script update_instructions.yaml of: b.c: 3\nb.e[0].name: Howdy Partner then yq w -s update_instructions.yaml sample.yaml will output: b:\n c: 3\n e:\n - name: Howdy Partner And, of course, you can pipe the instructions in using '-': cat update_instructions.yaml | yq w -s - sample.yaml",
|
|
"title": "Updating multiple values with a script"
|
|
},
|
|
{
|
|
"location": "/write/#values-starting-with-a-hyphen-or-dash",
|
|
"text": "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 my:\n path: -3",
|
|
"title": "Values starting with a hyphen (or dash)"
|
|
},
|
|
{
|
|
"location": "/write/#keys-with-dots",
|
|
"text": "When specifying a key that has a dot use key lookup indicator. b:\n foo.bar: 7 yaml r sample.yaml b[foo.bar] yaml w sample.yaml b[foo.bar] 9 Any valid yaml key can be specified as part of a key lookup.",
|
|
"title": "Keys with dots"
|
|
},
|
|
{
|
|
"location": "/create/",
|
|
"text": "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.\n\n\nyq n <path> <new value>\n\n\n\n\nCreating a simple yaml file\n\u00b6\n\n\nyq n b.c cat\n\n\n\n\nwill output:\n\n\nb:\n c: cat\n\n\n\n\nCreating using a create script\n\u00b6\n\n\nCreate scripts follow the same format as the update scripts.\n\n\nGiven a script create_instructions.yaml of:\n\n\nb.c: 3\nb.e[0].name: Howdy Partner\n\n\n\n\nthen\n\n\nyq n -s create_instructions.yaml\n\n\n\n\nwill output:\n\n\nb:\n c: 3\n e:\n - name: Howdy Partner\n\n\n\n\nYou can also pipe the instructions in:\n\n\ncat create_instructions.yaml | yq n -s -\n\n\n\n\nKeys with dots\n\u00b6\n\n\nWhen specifying a key that has a dot use key lookup indicator.\n\n\nb:\n foo.bar: 7\n\n\n\n\nyaml r sample.yaml b[foo.bar]\n\n\n\n\nyaml w sample.yaml b[foo.bar] 9\n\n\n\n\nAny valid yaml key can be specified as part of a key lookup.",
|
|
"title": "Create"
|
|
},
|
|
{
|
|
"location": "/create/#creating-a-simple-yaml-file",
|
|
"text": "yq n b.c cat will output: b:\n c: cat",
|
|
"title": "Creating a simple yaml file"
|
|
},
|
|
{
|
|
"location": "/create/#creating-using-a-create-script",
|
|
"text": "Create scripts follow the same format as the update scripts. Given a script create_instructions.yaml of: b.c: 3\nb.e[0].name: Howdy Partner then yq n -s create_instructions.yaml will output: b:\n c: 3\n e:\n - name: Howdy Partner You can also pipe the instructions in: cat create_instructions.yaml | yq n -s -",
|
|
"title": "Creating using a create script"
|
|
},
|
|
{
|
|
"location": "/create/#keys-with-dots",
|
|
"text": "When specifying a key that has a dot use key lookup indicator. b:\n foo.bar: 7 yaml r sample.yaml b[foo.bar] yaml w sample.yaml b[foo.bar] 9 Any valid yaml key can be specified as part of a key lookup.",
|
|
"title": "Keys with dots"
|
|
},
|
|
{
|
|
"location": "/convert/",
|
|
"text": "Yaml to Json\n\u00b6\n\n\nTo convert output to json, use the --tojson (or -j) flag. This can be used with any command.\n\n\nGiven a sample.yaml file of:\n\n\nb:\n c: 2\n\n\n\n\nthen\n\n\nyq r -j sample.yaml b.c\n\n\n\n\nwill output\n\n\n{\"b\":{\"c\":2}}\n\n\n\n\nJson to Yaml\n\u00b6\n\n\nTo read in json, just pass in a json file instead of yaml, it will just work :)\n\n\ne.g given a json file\n\n\n{\"a\":\"Easy! as one two three\",\"b\":{\"c\":2,\"d\":[3,4]}}\n\n\n\n\nthen\n\n\nyq r sample.json\n\n\n\n\nwill output\n\n\na: Easy! as one two three\nb:\n c: 2\n d:\n - 3\n - 4",
|
|
"title": "Convert"
|
|
},
|
|
{
|
|
"location": "/convert/#yaml-to-json",
|
|
"text": "To convert output to json, use the --tojson (or -j) flag. This can be used with any command. Given a sample.yaml file of: b:\n c: 2 then yq r -j sample.yaml b.c will output {\"b\":{\"c\":2}}",
|
|
"title": "Yaml to Json"
|
|
},
|
|
{
|
|
"location": "/convert/#json-to-yaml",
|
|
"text": "To read in json, just pass in a json file instead of yaml, it will just work :) e.g given a json file {\"a\":\"Easy! as one two three\",\"b\":{\"c\":2,\"d\":[3,4]}} then yq r sample.json will output a: Easy! as one two three\nb:\n c: 2\n d:\n - 3\n - 4",
|
|
"title": "Json to Yaml"
|
|
},
|
|
{
|
|
"location": "/merge/",
|
|
"text": "Yaml files can be merged using the 'merge' command. Each additional file merged with the first file will\nset values for any key not existing already or where the key has no value.\n\n\nyq m <yaml_file|json_file> <path>...\n\n\n\n\nThis command can take a json file as input too, and will output yaml unless specified to export as json (-j)\n\n\nTo Stdout\n\u00b6\n\n\nGiven a data1.yaml file of:\n\n\na: simple\nb: [1, 2]\n\n\n\n\nand data2.yaml file of:\n\n\na: other\nc:\n test: 1\n\n\n\n\nthen\n\n\nyq m data1.yaml data2.yaml\n\n\n\n\nwill output:\n\n\na: simple\nb: [1, 2]\nc:\n test: 1\n\n\n\n\nUpdating files in-place\n\u00b6\n\n\nGiven a data1.yaml file of:\n\n\na: simple\nb: [1, 2]\n\n\n\n\nand data2.yaml file of:\n\n\na: other\nc:\n test: 1\n\n\n\n\nthen\n\n\nyq m -i data1.yaml data2.yaml\n\n\n\n\nwill update the data1.yaml file so that the value of 'c' is 'test: 1'.\n\n\nOverwrite values\n\u00b6\n\n\nGiven a data1.yaml file of:\n\n\na: simple\nb: [1, 2]\n\n\n\n\nand data2.yaml file of:\n\n\na: other\nc:\n test: 1\n\n\n\n\nthen\n\n\nyq m -x data1.yaml data2.yaml\n\n\n\n\nwill output:\n\n\na: other\nb: [1, 2]\nc:\n test: 1\n\n\n\n\nOverwrite values with arrays\n\u00b6\n\n\nGiven a data1.yaml file of:\n\n\na: simple\nb: [1, 2]\n\n\n\n\nand data3.yaml file of:\n\n\nb: [2, 3, 4]\nc:\n test: 2\n other: true\nd: false\n\n\n\n\nthen\n\n\nyq m -x data1.yaml data3.yaml\n\n\n\n\nwill output:\n\n\na: simple\nb: [2, 3, 4]\nc:\n test: 2\n other: true\nd: false\n\n\n\n\nNotice that 'b' does not result in the merging of the values within an array. The underlying library does not\ncurrently handle merging values within an array.",
|
|
"title": "Merge"
|
|
},
|
|
{
|
|
"location": "/merge/#to-stdout",
|
|
"text": "Given a data1.yaml file of: a: simple\nb: [1, 2] and data2.yaml file of: a: other\nc:\n test: 1 then yq m data1.yaml data2.yaml will output: a: simple\nb: [1, 2]\nc:\n test: 1",
|
|
"title": "To Stdout"
|
|
},
|
|
{
|
|
"location": "/merge/#updating-files-in-place",
|
|
"text": "Given a data1.yaml file of: a: simple\nb: [1, 2] and data2.yaml file of: a: other\nc:\n test: 1 then yq m -i data1.yaml data2.yaml will update the data1.yaml file so that the value of 'c' is 'test: 1'.",
|
|
"title": "Updating files in-place"
|
|
},
|
|
{
|
|
"location": "/merge/#overwrite-values",
|
|
"text": "Given a data1.yaml file of: a: simple\nb: [1, 2] and data2.yaml file of: a: other\nc:\n test: 1 then yq m -x data1.yaml data2.yaml will output: a: other\nb: [1, 2]\nc:\n test: 1",
|
|
"title": "Overwrite values"
|
|
},
|
|
{
|
|
"location": "/merge/#overwrite-values-with-arrays",
|
|
"text": "Given a data1.yaml file of: a: simple\nb: [1, 2] and data3.yaml file of: b: [2, 3, 4]\nc:\n test: 2\n other: true\nd: false then yq m -x data1.yaml data3.yaml will output: a: simple\nb: [2, 3, 4]\nc:\n test: 2\n other: true\nd: false Notice that 'b' does not result in the merging of the values within an array. The underlying library does not\ncurrently handle merging values within an array.",
|
|
"title": "Overwrite values with arrays"
|
|
}
|
|
]
|
|
} |