mirror of
				https://github.com/taigrr/yq
				synced 2025-01-18 04:53:17 -08:00 
			
		
		
		
	wip
This commit is contained in:
		
							parent
							
								
									7b54bead5e
								
							
						
					
					
						commit
						4e1a1025c3
					
				| @ -8,8 +8,11 @@ Use `+=` as append assign for things like increment. `.a += .x` is equivalent to | ||||
| ## Concatenate and assign arrays | ||||
| Given a sample.yml file of: | ||||
| ```yaml | ||||
| a: {val: thing, b: [cat, dog]} | ||||
| '': null | ||||
| a: | ||||
|   val: thing | ||||
|   b: | ||||
|     - cat | ||||
|     - dog | ||||
| ``` | ||||
| then | ||||
| ```bash | ||||
| @ -17,16 +20,23 @@ yq eval '.a.b += ["cow"]' sample.yml | ||||
| ``` | ||||
| will output | ||||
| ```yaml | ||||
| a: {val: thing, b: [cat, dog, cow]} | ||||
| '': null | ||||
| a: | ||||
|   val: thing | ||||
|   b: | ||||
|     - cat | ||||
|     - dog | ||||
|     - cow | ||||
| ``` | ||||
| 
 | ||||
| ## Concatenate arrays | ||||
| Given a sample.yml file of: | ||||
| ```yaml | ||||
| a: [1, 2] | ||||
| b: [3, 4] | ||||
| '': null | ||||
| a: | ||||
|   - 1 | ||||
|   - 2 | ||||
| b: | ||||
|   - 3 | ||||
|   - 4 | ||||
| ``` | ||||
| then | ||||
| ```bash | ||||
| @ -34,14 +44,18 @@ yq eval '.a + .b' sample.yml | ||||
| ``` | ||||
| will output | ||||
| ```yaml | ||||
| [1, 2, 3, 4] | ||||
| - 1 | ||||
| - 2 | ||||
| - 3 | ||||
| - 4 | ||||
| ``` | ||||
| 
 | ||||
| ## Concatenate null to array | ||||
| Given a sample.yml file of: | ||||
| ```yaml | ||||
| a: [1, 2] | ||||
| '': null | ||||
| a: | ||||
|   - 1 | ||||
|   - 2 | ||||
| ``` | ||||
| then | ||||
| ```bash | ||||
| @ -49,15 +63,18 @@ yq eval '.a + null' sample.yml | ||||
| ``` | ||||
| will output | ||||
| ```yaml | ||||
| [1, 2] | ||||
| - 1 | ||||
| - 2 | ||||
| ``` | ||||
| 
 | ||||
| ## Add object to array | ||||
| Given a sample.yml file of: | ||||
| ```yaml | ||||
| a: [1, 2] | ||||
| c: {cat: meow} | ||||
| '': null | ||||
| a: | ||||
|   - 1 | ||||
|   - 2 | ||||
| c: | ||||
|   cat: meow | ||||
| ``` | ||||
| then | ||||
| ```bash | ||||
| @ -65,14 +82,17 @@ yq eval '.a + .c' sample.yml | ||||
| ``` | ||||
| will output | ||||
| ```yaml | ||||
| [1, 2, {cat: meow}] | ||||
| - 1 | ||||
| - 2 | ||||
| - cat: meow | ||||
| ``` | ||||
| 
 | ||||
| ## Add string to array | ||||
| Given a sample.yml file of: | ||||
| ```yaml | ||||
| a: [1, 2] | ||||
| '': null | ||||
| a: | ||||
|   - 1 | ||||
|   - 2 | ||||
| ``` | ||||
| then | ||||
| ```bash | ||||
| @ -80,15 +100,20 @@ yq eval '.a + "hello"' sample.yml | ||||
| ``` | ||||
| will output | ||||
| ```yaml | ||||
| [1, 2, hello] | ||||
| - 1 | ||||
| - 2 | ||||
| - hello | ||||
| ``` | ||||
| 
 | ||||
| ## Update array (append) | ||||
| Given a sample.yml file of: | ||||
| ```yaml | ||||
| a: [1, 2] | ||||
| b: [3, 4] | ||||
| '': null | ||||
| a: | ||||
|   - 1 | ||||
|   - 2 | ||||
| b: | ||||
|   - 3 | ||||
|   - 4 | ||||
| ``` | ||||
| then | ||||
| ```bash | ||||
| @ -96,8 +121,13 @@ yq eval '.a = .a + .b' sample.yml | ||||
| ``` | ||||
| will output | ||||
| ```yaml | ||||
| a: [1, 2, 3, 4] | ||||
| b: [3, 4] | ||||
| '': null | ||||
| a: | ||||
|   - 1 | ||||
|   - 2 | ||||
|   - 3 | ||||
|   - 4 | ||||
| b: | ||||
|   - 3 | ||||
|   - 4 | ||||
| ``` | ||||
| 
 | ||||
|  | ||||
| @ -4,7 +4,6 @@ This operator is used to provide alternative (or default) values when a particul | ||||
| Given a sample.yml file of: | ||||
| ```yaml | ||||
| a: bridge | ||||
| '': null | ||||
| ``` | ||||
| then | ||||
| ```bash | ||||
| @ -33,7 +32,6 @@ hello | ||||
| Given a sample.yml file of: | ||||
| ```yaml | ||||
| a: ~ | ||||
| '': null | ||||
| ``` | ||||
| then | ||||
| ```bash | ||||
| @ -48,7 +46,6 @@ hello | ||||
| Given a sample.yml file of: | ||||
| ```yaml | ||||
| a: false | ||||
| '': null | ||||
| ``` | ||||
| then | ||||
| ```bash | ||||
| @ -64,7 +61,6 @@ Given a sample.yml file of: | ||||
| ```yaml | ||||
| a: false | ||||
| b: cat | ||||
| '': null | ||||
| ``` | ||||
| then | ||||
| ```bash | ||||
|  | ||||
| @ -7,7 +7,6 @@ Use the `alias` and `anchor` operators to read and write yaml aliases and anchor | ||||
| Given a sample.yml file of: | ||||
| ```yaml | ||||
| a: &billyBob cat | ||||
| '': null | ||||
| ``` | ||||
| then | ||||
| ```bash | ||||
| @ -22,7 +21,6 @@ billyBob | ||||
| Given a sample.yml file of: | ||||
| ```yaml | ||||
| a: cat | ||||
| '': null | ||||
| ``` | ||||
| then | ||||
| ```bash | ||||
| @ -31,7 +29,6 @@ yq eval '.a anchor = "foobar"' sample.yml | ||||
| will output | ||||
| ```yaml | ||||
| a: &foobar cat | ||||
| '': null | ||||
| ``` | ||||
| 
 | ||||
| ## Get alias | ||||
| @ -39,7 +36,6 @@ Given a sample.yml file of: | ||||
| ```yaml | ||||
| b: &billyBob meow | ||||
| a: *billyBob | ||||
| '': null | ||||
| ``` | ||||
| then | ||||
| ```bash | ||||
| @ -55,7 +51,6 @@ Given a sample.yml file of: | ||||
| ```yaml | ||||
| b: &meow purr | ||||
| a: cat | ||||
| '': null | ||||
| ``` | ||||
| then | ||||
| ```bash | ||||
| @ -65,14 +60,14 @@ will output | ||||
| ```yaml | ||||
| b: &meow purr | ||||
| a: *meow | ||||
| '': null | ||||
| ``` | ||||
| 
 | ||||
| ## Explode alias and anchor | ||||
| Given a sample.yml file of: | ||||
| ```yaml | ||||
| f: {a: &a cat, b: *a} | ||||
| '': null | ||||
| f: | ||||
|   a: &a cat | ||||
|   b: *a | ||||
| ``` | ||||
| then | ||||
| ```bash | ||||
| @ -80,15 +75,15 @@ yq eval 'explode(.f)' sample.yml | ||||
| ``` | ||||
| will output | ||||
| ```yaml | ||||
| f: {a: cat, b: cat} | ||||
| '': null | ||||
| f: | ||||
|   a: cat | ||||
|   b: cat | ||||
| ``` | ||||
| 
 | ||||
| ## Explode with no aliases or anchors | ||||
| Given a sample.yml file of: | ||||
| ```yaml | ||||
| a: mike | ||||
| '': null | ||||
| ``` | ||||
| then | ||||
| ```bash | ||||
| @ -97,14 +92,14 @@ yq eval 'explode(.a)' sample.yml | ||||
| will output | ||||
| ```yaml | ||||
| a: mike | ||||
| '': null | ||||
| ``` | ||||
| 
 | ||||
| ## Explode with alias keys | ||||
| Given a sample.yml file of: | ||||
| ```yaml | ||||
| f: {a: &a cat, *a: b} | ||||
| '': null | ||||
| f: | ||||
|   a: &a cat | ||||
|   *a: b | ||||
| ``` | ||||
| then | ||||
| ```bash | ||||
| @ -112,8 +107,9 @@ yq eval 'explode(.f)' sample.yml | ||||
| ``` | ||||
| will output | ||||
| ```yaml | ||||
| f: {a: cat, cat: b} | ||||
| '': null | ||||
| f: | ||||
|   a: cat | ||||
|   cat: b | ||||
| ``` | ||||
| 
 | ||||
| ## Explode with merge anchors | ||||
| @ -129,13 +125,14 @@ bar: &bar | ||||
|   c: bar_c | ||||
| foobarList: | ||||
|   b: foobarList_b | ||||
|   !!merge <<: [*foo, *bar] | ||||
|   !!merge <<: | ||||
|     - *foo | ||||
|     - *bar | ||||
|   c: foobarList_c | ||||
| foobar: | ||||
|   c: foobar_c | ||||
|   !!merge <<: *foo | ||||
|   thing: foobar_thing | ||||
| '': null | ||||
| ``` | ||||
| then | ||||
| ```bash | ||||
| @ -160,6 +157,5 @@ foobar: | ||||
|   c: foo_c | ||||
|   a: foo_a | ||||
|   thing: foobar_thing | ||||
| '': null | ||||
| ``` | ||||
| 
 | ||||
|  | ||||
| @ -20,8 +20,9 @@ x: frog | ||||
| ## Update node to be the child value | ||||
| Given a sample.yml file of: | ||||
| ```yaml | ||||
| a: {b: {g: foof}} | ||||
| '': null | ||||
| a: | ||||
|   b: | ||||
|     g: foof | ||||
| ``` | ||||
| then | ||||
| ```bash | ||||
| @ -29,16 +30,16 @@ yq eval '.a |= .b' sample.yml | ||||
| ``` | ||||
| will output | ||||
| ```yaml | ||||
| a: {g: foof} | ||||
| '': null | ||||
| a: | ||||
|   g: foof | ||||
| ``` | ||||
| 
 | ||||
| ## Update node to be the sibling value | ||||
| Given a sample.yml file of: | ||||
| ```yaml | ||||
| a: {b: child} | ||||
| a: | ||||
|   b: child | ||||
| b: sibling | ||||
| '': null | ||||
| ``` | ||||
| then | ||||
| ```bash | ||||
| @ -48,7 +49,6 @@ will output | ||||
| ```yaml | ||||
| a: sibling | ||||
| b: sibling | ||||
| '': null | ||||
| ``` | ||||
| 
 | ||||
| ## Updated multiple paths | ||||
| @ -57,7 +57,6 @@ Given a sample.yml file of: | ||||
| a: fieldA | ||||
| b: fieldB | ||||
| c: fieldC | ||||
| '': null | ||||
| ``` | ||||
| then | ||||
| ```bash | ||||
| @ -68,14 +67,13 @@ will output | ||||
| a: potatoe | ||||
| b: fieldB | ||||
| c: potatoe | ||||
| '': null | ||||
| ``` | ||||
| 
 | ||||
| ## Update string value | ||||
| Given a sample.yml file of: | ||||
| ```yaml | ||||
| a: {b: apple} | ||||
| '': null | ||||
| a: | ||||
|   b: apple | ||||
| ``` | ||||
| then | ||||
| ```bash | ||||
| @ -83,8 +81,8 @@ yq eval '.a.b = "frog"' sample.yml | ||||
| ``` | ||||
| will output | ||||
| ```yaml | ||||
| a: {b: frog} | ||||
| '': null | ||||
| a: | ||||
|   b: frog | ||||
| ``` | ||||
| 
 | ||||
| ## Update string value via |= | ||||
| @ -92,8 +90,8 @@ Note there is no difference between `=` and `|=` when the RHS is a scalar | ||||
| 
 | ||||
| Given a sample.yml file of: | ||||
| ```yaml | ||||
| a: {b: apple} | ||||
| '': null | ||||
| a: | ||||
|   b: apple | ||||
| ``` | ||||
| then | ||||
| ```bash | ||||
| @ -101,15 +99,16 @@ yq eval '.a.b |= "frog"' sample.yml | ||||
| ``` | ||||
| will output | ||||
| ```yaml | ||||
| a: {b: frog} | ||||
| '': null | ||||
| a: | ||||
|   b: frog | ||||
| ``` | ||||
| 
 | ||||
| ## Update selected results | ||||
| Given a sample.yml file of: | ||||
| ```yaml | ||||
| a: {b: apple, c: cactus} | ||||
| '': null | ||||
| a: | ||||
|   b: apple | ||||
|   c: cactus | ||||
| ``` | ||||
| then | ||||
| ```bash | ||||
| @ -117,8 +116,9 @@ yq eval '(.a[] | select(. == "apple")) = "frog"' sample.yml | ||||
| ``` | ||||
| will output | ||||
| ```yaml | ||||
| a: {b: frog, c: cactus} | ||||
| '': null | ||||
| a: | ||||
|   b: frog | ||||
|   c: cactus | ||||
| ``` | ||||
| 
 | ||||
| ## Update array values | ||||
|  | ||||
| @ -24,13 +24,10 @@ Given a sample.yml file of: | ||||
| ```yaml | ||||
| - a: bird | ||||
|   b: dog | ||||
|   '': null | ||||
| - a: frog | ||||
|   b: bird | ||||
|   '': null | ||||
| - a: cat | ||||
|   b: fly | ||||
|   '': null | ||||
| ``` | ||||
| then | ||||
| ```bash | ||||
| @ -40,10 +37,8 @@ will output | ||||
| ```yaml | ||||
| - a: bird | ||||
|   b: dog | ||||
|   '': null | ||||
| - a: cat | ||||
|   b: fly | ||||
|   '': null | ||||
| ``` | ||||
| 
 | ||||
| ## Not true is false | ||||
|  | ||||
| @ -28,7 +28,6 @@ Given a sample.yml file of: | ||||
| ```yaml | ||||
| a: cat | ||||
| b: dog | ||||
| '': null | ||||
| ``` | ||||
| then | ||||
| ```bash | ||||
|  | ||||
| @ -13,7 +13,6 @@ will output | ||||
| Given a sample.yml file of: | ||||
| ```yaml | ||||
| name: Mike | ||||
| '': null | ||||
| ``` | ||||
| then | ||||
| ```bash | ||||
| @ -23,15 +22,15 @@ will output | ||||
| ```yaml | ||||
| wrap: | ||||
|   name: Mike | ||||
|   '': null | ||||
| ``` | ||||
| 
 | ||||
| ## Using splat to create multiple objects | ||||
| Given a sample.yml file of: | ||||
| ```yaml | ||||
| name: Mike | ||||
| pets: [cat, dog] | ||||
| '': null | ||||
| pets: | ||||
|   - cat | ||||
|   - dog | ||||
| ``` | ||||
| then | ||||
| ```bash | ||||
| @ -47,12 +46,14 @@ Mike: dog | ||||
| Given a sample.yml file of: | ||||
| ```yaml | ||||
| name: Mike | ||||
| pets: [cat, dog] | ||||
| '': null | ||||
| pets: | ||||
|   - cat | ||||
|   - dog | ||||
| --- | ||||
| name: Rosey | ||||
| pets: [monkey, sheep] | ||||
| '': null | ||||
| pets: | ||||
|   - monkey | ||||
|   - sheep | ||||
| ``` | ||||
| then | ||||
| ```bash | ||||
|  | ||||
| @ -3,7 +3,6 @@ Use these comment operators to set or retrieve comments. | ||||
| Given a sample.yml file of: | ||||
| ```yaml | ||||
| a: cat | ||||
| '': null | ||||
| ``` | ||||
| then | ||||
| ```bash | ||||
| @ -12,14 +11,12 @@ yq eval '.a lineComment="single"' sample.yml | ||||
| will output | ||||
| ```yaml | ||||
| a: cat # single | ||||
| '': null | ||||
| ``` | ||||
| 
 | ||||
| ## Set head comment | ||||
| Given a sample.yml file of: | ||||
| ```yaml | ||||
| a: cat | ||||
| '': null | ||||
| ``` | ||||
| then | ||||
| ```bash | ||||
| @ -30,14 +27,12 @@ will output | ||||
| # single | ||||
| 
 | ||||
| a: cat | ||||
| '': null | ||||
| ``` | ||||
| 
 | ||||
| ## Set foot comment, using an expression | ||||
| Given a sample.yml file of: | ||||
| ```yaml | ||||
| a: cat | ||||
| '': null | ||||
| ``` | ||||
| then | ||||
| ```bash | ||||
| @ -46,7 +41,6 @@ yq eval '. footComment=.a' sample.yml | ||||
| will output | ||||
| ```yaml | ||||
| a: cat | ||||
| '': null | ||||
| 
 | ||||
| # cat | ||||
| ``` | ||||
| @ -56,7 +50,6 @@ Given a sample.yml file of: | ||||
| ```yaml | ||||
| a: cat # comment | ||||
| b: dog # leave this | ||||
| '': null | ||||
| ``` | ||||
| then | ||||
| ```bash | ||||
| @ -66,14 +59,12 @@ will output | ||||
| ```yaml | ||||
| a: cat | ||||
| b: dog # leave this | ||||
| '': null | ||||
| ``` | ||||
| 
 | ||||
| ## Remove all comments | ||||
| Given a sample.yml file of: | ||||
| ```yaml | ||||
| a: cat # comment | ||||
| '': null | ||||
| ``` | ||||
| then | ||||
| ```bash | ||||
| @ -81,15 +72,13 @@ yq eval '.. comments=""' sample.yml | ||||
| ``` | ||||
| will output | ||||
| ```yaml | ||||
| a: cat # comment | ||||
| '': null | ||||
| a: cat | ||||
| ``` | ||||
| 
 | ||||
| ## Get line comment | ||||
| Given a sample.yml file of: | ||||
| ```yaml | ||||
| a: cat # meow | ||||
| '': null | ||||
| ``` | ||||
| then | ||||
| ```bash | ||||
| @ -104,7 +93,6 @@ meow | ||||
| Given a sample.yml file of: | ||||
| ```yaml | ||||
| a: cat # meow | ||||
| '': null | ||||
| ``` | ||||
| then | ||||
| ```bash | ||||
| @ -119,7 +107,6 @@ will output | ||||
| Given a sample.yml file of: | ||||
| ```yaml | ||||
| a: cat # meow | ||||
| '': null | ||||
| ``` | ||||
| then | ||||
| ```bash | ||||
|  | ||||
| @ -4,7 +4,6 @@ Given a sample.yml file of: | ||||
| ```yaml | ||||
| a: cat | ||||
| b: dog | ||||
| '': null | ||||
| ``` | ||||
| then | ||||
| ```bash | ||||
| @ -13,14 +12,14 @@ yq eval 'del(.b)' sample.yml | ||||
| will output | ||||
| ```yaml | ||||
| a: cat | ||||
| '': null | ||||
| ``` | ||||
| 
 | ||||
| ## Delete nested entry in map | ||||
| Given a sample.yml file of: | ||||
| ```yaml | ||||
| a: {a1: fred, a2: frood} | ||||
| '': null | ||||
| a: | ||||
|   a1: fred | ||||
|   a2: frood | ||||
| ``` | ||||
| then | ||||
| ```bash | ||||
| @ -28,8 +27,8 @@ yq eval 'del(.a.a1)' sample.yml | ||||
| ``` | ||||
| will output | ||||
| ```yaml | ||||
| a: {a2: frood} | ||||
| '': null | ||||
| a: | ||||
|   a2: frood | ||||
| ``` | ||||
| 
 | ||||
| ## Delete entry in array | ||||
| @ -54,7 +53,6 @@ Given a sample.yml file of: | ||||
| ```yaml | ||||
| - a: cat | ||||
|   b: dog | ||||
|   '': null | ||||
| ``` | ||||
| then | ||||
| ```bash | ||||
| @ -63,7 +61,6 @@ yq eval 'del(.[0].a)' sample.yml | ||||
| will output | ||||
| ```yaml | ||||
| - b: dog | ||||
|   '': null | ||||
| ``` | ||||
| 
 | ||||
| ## Delete no matches | ||||
| @ -71,7 +68,6 @@ Given a sample.yml file of: | ||||
| ```yaml | ||||
| a: cat | ||||
| b: dog | ||||
| '': null | ||||
| ``` | ||||
| then | ||||
| ```bash | ||||
| @ -81,7 +77,6 @@ will output | ||||
| ```yaml | ||||
| a: cat | ||||
| b: dog | ||||
| '': null | ||||
| ``` | ||||
| 
 | ||||
| ## Delete matching entries | ||||
| @ -90,7 +85,6 @@ Given a sample.yml file of: | ||||
| a: cat | ||||
| b: dog | ||||
| c: bat | ||||
| '': null | ||||
| ``` | ||||
| then | ||||
| ```bash | ||||
| @ -99,6 +93,5 @@ yq eval 'del( .[] | select(. == "*at") )' sample.yml | ||||
| will output | ||||
| ```yaml | ||||
| b: dog | ||||
| '': null | ||||
| ``` | ||||
| 
 | ||||
|  | ||||
| @ -3,10 +3,8 @@ Use the `documentIndex` operator to select nodes of a particular document. | ||||
| Given a sample.yml file of: | ||||
| ```yaml | ||||
| a: cat | ||||
| '': null | ||||
| --- | ||||
| a: frog | ||||
| '': null | ||||
| ``` | ||||
| then | ||||
| ```bash | ||||
| @ -23,10 +21,8 @@ will output | ||||
| Given a sample.yml file of: | ||||
| ```yaml | ||||
| a: cat | ||||
| '': null | ||||
| --- | ||||
| a: frog | ||||
| '': null | ||||
| ``` | ||||
| then | ||||
| ```bash | ||||
| @ -35,17 +31,14 @@ yq eval 'select(. | documentIndex == 1)' sample.yml | ||||
| will output | ||||
| ```yaml | ||||
| a: frog | ||||
| '': null | ||||
| ``` | ||||
| 
 | ||||
| ## Print Document Index with matches | ||||
| Given a sample.yml file of: | ||||
| ```yaml | ||||
| a: cat | ||||
| '': null | ||||
| --- | ||||
| a: frog | ||||
| '': null | ||||
| ``` | ||||
| then | ||||
| ```bash | ||||
| @ -53,7 +46,9 @@ yq eval '.a | ({"match": ., "doc": (. | documentIndex)})' sample.yml | ||||
| ``` | ||||
| will output | ||||
| ```yaml | ||||
| '': null | ||||
| '': null | ||||
| match: cat | ||||
| doc: 0 | ||||
| match: frog | ||||
| doc: 1 | ||||
| ``` | ||||
| 
 | ||||
|  | ||||
| @ -9,7 +9,6 @@ yq eval-all 'select(fileIndex == 0) * select(filename == "file2.yaml")' file1.ya | ||||
| Given a sample.yml file of: | ||||
| ```yaml | ||||
| a: cat | ||||
| '': null | ||||
| ``` | ||||
| then | ||||
| ```bash | ||||
| @ -24,7 +23,6 @@ sample.yaml | ||||
| Given a sample.yml file of: | ||||
| ```yaml | ||||
| a: cat | ||||
| '': null | ||||
| ``` | ||||
| then | ||||
| ```bash | ||||
|  | ||||
| @ -2,14 +2,10 @@ This is operation that returns true if the key exists in a map (or index in an a | ||||
| ## Has map key | ||||
| Given a sample.yml file of: | ||||
| ```yaml | ||||
| - a: "yes" | ||||
|   '': null | ||||
| - a: yes | ||||
| - a: ~ | ||||
|   '': null | ||||
| - a: | ||||
|   '': null | ||||
| - b: nope | ||||
|   '': null | ||||
| ``` | ||||
| then | ||||
| ```bash | ||||
|  | ||||
| @ -6,7 +6,6 @@ returns length of string | ||||
| Given a sample.yml file of: | ||||
| ```yaml | ||||
| a: cat | ||||
| '': null | ||||
| ``` | ||||
| then | ||||
| ```bash | ||||
| @ -24,7 +23,6 @@ Given a sample.yml file of: | ||||
| ```yaml | ||||
| a: cat | ||||
| c: dog | ||||
| '': null | ||||
| ``` | ||||
| then | ||||
| ```bash | ||||
| @ -32,7 +30,7 @@ yq eval 'length' sample.yml | ||||
| ``` | ||||
| will output | ||||
| ```yaml | ||||
| 3 | ||||
| 2 | ||||
| ``` | ||||
| 
 | ||||
| ## Array length | ||||
|  | ||||
| @ -16,9 +16,13 @@ yq eval-all 'select(fileIndex == 0) * select(fileIndex == 1)' file1.yaml file2.y | ||||
| ## Merge objects together, returning merged result only | ||||
| Given a sample.yml file of: | ||||
| ```yaml | ||||
| a: {field: me, fieldA: cat} | ||||
| b: {field: {g: wizz}, fieldB: dog} | ||||
| '': null | ||||
| a: | ||||
|   field: me | ||||
|   fieldA: cat | ||||
| b: | ||||
|   field: | ||||
|     g: wizz | ||||
|   fieldB: dog | ||||
| ``` | ||||
| then | ||||
| ```bash | ||||
| @ -26,15 +30,22 @@ yq eval '.a * .b' sample.yml | ||||
| ``` | ||||
| will output | ||||
| ```yaml | ||||
| {'': null} | ||||
| field: | ||||
|   g: wizz | ||||
| fieldA: cat | ||||
| fieldB: dog | ||||
| ``` | ||||
| 
 | ||||
| ## Merge objects together, returning parent object | ||||
| Given a sample.yml file of: | ||||
| ```yaml | ||||
| a: {field: me, fieldA: cat} | ||||
| b: {field: {g: wizz}, fieldB: dog} | ||||
| '': null | ||||
| a: | ||||
|   field: me | ||||
|   fieldA: cat | ||||
| b: | ||||
|   field: | ||||
|     g: wizz | ||||
|   fieldB: dog | ||||
| ``` | ||||
| then | ||||
| ```bash | ||||
| @ -42,7 +53,15 @@ yq eval '. * {"a":.b}' sample.yml | ||||
| ``` | ||||
| will output | ||||
| ```yaml | ||||
| '': null | ||||
| a: | ||||
|   field: | ||||
|     g: wizz | ||||
|   fieldA: cat | ||||
|   fieldB: dog | ||||
| b: | ||||
|   field: | ||||
|     g: wizz | ||||
|   fieldB: dog | ||||
| ``` | ||||
| 
 | ||||
| ## Merge keeps style of LHS | ||||
| @ -59,15 +78,22 @@ yq eval '. * {"a":.b}' sample.yml | ||||
| ``` | ||||
| will output | ||||
| ```yaml | ||||
| '': null | ||||
| a: {things: great, also: "me"} | ||||
| b: | ||||
|   also: "me" | ||||
| ``` | ||||
| 
 | ||||
| ## Merge arrays | ||||
| Given a sample.yml file of: | ||||
| ```yaml | ||||
| a: [1, 2, 3] | ||||
| b: [3, 4, 5] | ||||
| '': null | ||||
| a: | ||||
|   - 1 | ||||
|   - 2 | ||||
|   - 3 | ||||
| b: | ||||
|   - 3 | ||||
|   - 4 | ||||
|   - 5 | ||||
| ``` | ||||
| then | ||||
| ```bash | ||||
| @ -75,15 +101,31 @@ yq eval '. * {"a":.b}' sample.yml | ||||
| ``` | ||||
| will output | ||||
| ```yaml | ||||
| '': null | ||||
| a: | ||||
|   - 3 | ||||
|   - 4 | ||||
|   - 5 | ||||
| b: | ||||
|   - 3 | ||||
|   - 4 | ||||
|   - 5 | ||||
| ``` | ||||
| 
 | ||||
| ## Merge, appending arrays | ||||
| Given a sample.yml file of: | ||||
| ```yaml | ||||
| a: {array: [1, 2, {animal: dog}], value: coconut} | ||||
| b: {array: [3, 4, {animal: cat}], value: banana} | ||||
| '': null | ||||
| a: | ||||
|   array: | ||||
|     - 1 | ||||
|     - 2 | ||||
|     - animal: dog | ||||
|   value: coconut | ||||
| b: | ||||
|   array: | ||||
|     - 3 | ||||
|     - 4 | ||||
|     - animal: cat | ||||
|   value: banana | ||||
| ``` | ||||
| then | ||||
| ```bash | ||||
| @ -91,7 +133,14 @@ yq eval '.a *+ .b' sample.yml | ||||
| ``` | ||||
| will output | ||||
| ```yaml | ||||
| {'': null} | ||||
| array: | ||||
|   - 1 | ||||
|   - 2 | ||||
|   - animal: dog | ||||
|   - 3 | ||||
|   - 4 | ||||
|   - animal: cat | ||||
| value: banana | ||||
| ``` | ||||
| 
 | ||||
| ## Merge to prefix an element | ||||
| @ -99,7 +148,6 @@ Given a sample.yml file of: | ||||
| ```yaml | ||||
| a: cat | ||||
| b: dog | ||||
| '': null | ||||
| ``` | ||||
| then | ||||
| ```bash | ||||
| @ -107,16 +155,20 @@ yq eval '. * {"a": {"c": .a}}' sample.yml | ||||
| ``` | ||||
| will output | ||||
| ```yaml | ||||
| '': null | ||||
| a: | ||||
|   c: cat | ||||
| b: dog | ||||
| ``` | ||||
| 
 | ||||
| ## Merge with simple aliases | ||||
| Given a sample.yml file of: | ||||
| ```yaml | ||||
| a: &cat {c: frog} | ||||
| b: {f: *cat} | ||||
| c: {g: thongs} | ||||
| '': null | ||||
| a: &cat | ||||
|   c: frog | ||||
| b: | ||||
|   f: *cat | ||||
| c: | ||||
|   g: thongs | ||||
| ``` | ||||
| then | ||||
| ```bash | ||||
| @ -124,16 +176,19 @@ yq eval '.c * .b' sample.yml | ||||
| ``` | ||||
| will output | ||||
| ```yaml | ||||
| {'': null} | ||||
| g: thongs | ||||
| f: *cat | ||||
| ``` | ||||
| 
 | ||||
| ## Merge does not copy anchor names | ||||
| Given a sample.yml file of: | ||||
| ```yaml | ||||
| a: {c: &cat frog} | ||||
| b: {f: *cat} | ||||
| c: {g: thongs} | ||||
| '': null | ||||
| a: | ||||
|   c: &cat frog | ||||
| b: | ||||
|   f: *cat | ||||
| c: | ||||
|   g: thongs | ||||
| ``` | ||||
| then | ||||
| ```bash | ||||
| @ -141,7 +196,8 @@ yq eval '.c * .a' sample.yml | ||||
| ``` | ||||
| will output | ||||
| ```yaml | ||||
| {'': null} | ||||
| g: thongs | ||||
| c: frog | ||||
| ``` | ||||
| 
 | ||||
| ## Merge with merge anchors | ||||
| @ -157,13 +213,14 @@ bar: &bar | ||||
|   c: bar_c | ||||
| foobarList: | ||||
|   b: foobarList_b | ||||
|   !!merge <<: [*foo, *bar] | ||||
|   !!merge <<: | ||||
|     - *foo | ||||
|     - *bar | ||||
|   c: foobarList_c | ||||
| foobar: | ||||
|   c: foobar_c | ||||
|   !!merge <<: *foo | ||||
|   thing: foobar_thing | ||||
| '': null | ||||
| ``` | ||||
| then | ||||
| ```bash | ||||
| @ -171,6 +228,11 @@ yq eval '.foobar * .foobarList' sample.yml | ||||
| ``` | ||||
| will output | ||||
| ```yaml | ||||
| '': null | ||||
| c: foobarList_c | ||||
| <<: | ||||
|   - *foo | ||||
|   - *bar | ||||
| thing: foobar_thing | ||||
| b: foobarList_b | ||||
| ``` | ||||
| 
 | ||||
|  | ||||
| @ -5,8 +5,8 @@ You can get the key/index of matching nodes by using the `path` operator to retu | ||||
| ## Map path | ||||
| Given a sample.yml file of: | ||||
| ```yaml | ||||
| a: {b: cat} | ||||
| '': null | ||||
| a: | ||||
|   b: cat | ||||
| ``` | ||||
| then | ||||
| ```bash | ||||
| @ -21,8 +21,8 @@ will output | ||||
| ## Get map key | ||||
| Given a sample.yml file of: | ||||
| ```yaml | ||||
| a: {b: cat} | ||||
| '': null | ||||
| a: | ||||
|   b: cat | ||||
| ``` | ||||
| then | ||||
| ```bash | ||||
| @ -36,8 +36,9 @@ b | ||||
| ## Array path | ||||
| Given a sample.yml file of: | ||||
| ```yaml | ||||
| a: [cat, dog] | ||||
| '': null | ||||
| a: | ||||
|   - cat | ||||
|   - dog | ||||
| ``` | ||||
| then | ||||
| ```bash | ||||
| @ -52,8 +53,9 @@ will output | ||||
| ## Get array index | ||||
| Given a sample.yml file of: | ||||
| ```yaml | ||||
| a: [cat, dog] | ||||
| '': null | ||||
| a: | ||||
|   - cat | ||||
|   - dog | ||||
| ``` | ||||
| then | ||||
| ```bash | ||||
| @ -67,8 +69,10 @@ will output | ||||
| ## Print path and value | ||||
| Given a sample.yml file of: | ||||
| ```yaml | ||||
| a: [cat, dog, frog] | ||||
| '': null | ||||
| a: | ||||
|   - cat | ||||
|   - dog | ||||
|   - frog | ||||
| ``` | ||||
| then | ||||
| ```bash | ||||
| @ -76,7 +80,13 @@ yq eval '.a.[] | select(. == "*og") | [{"path":path, "value":.}]' sample.yml | ||||
| ``` | ||||
| will output | ||||
| ```yaml | ||||
| - '': null | ||||
| - '': null | ||||
| - path: | ||||
|     - a | ||||
|     - 1 | ||||
|   value: dog | ||||
| - path: | ||||
|     - a | ||||
|     - 2 | ||||
|   value: frog | ||||
| ``` | ||||
| 
 | ||||
|  | ||||
| @ -3,8 +3,8 @@ Pipe the results of an expression into another. Like the bash operator. | ||||
| ## Simple Pipe | ||||
| Given a sample.yml file of: | ||||
| ```yaml | ||||
| a: {b: cat} | ||||
| '': null | ||||
| a: | ||||
|   b: cat | ||||
| ``` | ||||
| then | ||||
| ```bash | ||||
| @ -21,7 +21,6 @@ Given a sample.yml file of: | ||||
| a: cow | ||||
| b: sheep | ||||
| c: same | ||||
| '': null | ||||
| ``` | ||||
| then | ||||
| ```bash | ||||
| @ -32,6 +31,5 @@ will output | ||||
| a: cat | ||||
| b: dog | ||||
| c: same | ||||
| '': null | ||||
| ``` | ||||
| 
 | ||||
|  | ||||
| @ -6,9 +6,9 @@ yq eval '.. style= "flow"' file.yaml | ||||
| ## Aliases are not traversed | ||||
| Given a sample.yml file of: | ||||
| ```yaml | ||||
| a: &cat {c: frog} | ||||
| a: &cat | ||||
|   c: frog | ||||
| b: *cat | ||||
| '': null | ||||
| ``` | ||||
| then | ||||
| ```bash | ||||
| @ -16,10 +16,13 @@ yq eval '[..]' sample.yml | ||||
| ``` | ||||
| will output | ||||
| ```yaml | ||||
| - a: &cat {c: frog} | ||||
| - a: &cat | ||||
|     c: frog | ||||
|   b: *cat | ||||
|   '': null | ||||
| - null | ||||
| - &cat | ||||
|   c: frog | ||||
| - frog | ||||
| - *cat | ||||
| ``` | ||||
| 
 | ||||
| ## Merge docs are not traversed | ||||
| @ -35,13 +38,14 @@ bar: &bar | ||||
|   c: bar_c | ||||
| foobarList: | ||||
|   b: foobarList_b | ||||
|   !!merge <<: [*foo, *bar] | ||||
|   !!merge <<: | ||||
|     - *foo | ||||
|     - *bar | ||||
|   c: foobarList_c | ||||
| foobar: | ||||
|   c: foobar_c | ||||
|   !!merge <<: *foo | ||||
|   thing: foobar_thing | ||||
| '': null | ||||
| ``` | ||||
| then | ||||
| ```bash | ||||
| @ -52,7 +56,8 @@ will output | ||||
| - c: foobar_c | ||||
|   !!merge <<: *foo | ||||
|   thing: foobar_thing | ||||
|   '': null | ||||
| - null | ||||
| - foobar_c | ||||
| - *foo | ||||
| - foobar_thing | ||||
| ``` | ||||
| 
 | ||||
|  | ||||
| @ -19,8 +19,10 @@ goat | ||||
| ## Select and update matching values in map | ||||
| Given a sample.yml file of: | ||||
| ```yaml | ||||
| a: {things: cat, bob: goat, horse: dog} | ||||
| '': null | ||||
| a: | ||||
|   things: cat | ||||
|   bob: goat | ||||
|   horse: dog | ||||
| ``` | ||||
| then | ||||
| ```bash | ||||
| @ -28,7 +30,9 @@ yq eval '(.a.[] | select(. == "*at")) |= "rabbit"' sample.yml | ||||
| ``` | ||||
| will output | ||||
| ```yaml | ||||
| a: {things: rabbit, bob: rabbit, horse: dog} | ||||
| '': null | ||||
| a: | ||||
|   things: rabbit | ||||
|   bob: rabbit | ||||
|   horse: dog | ||||
| ``` | ||||
| 
 | ||||
|  | ||||
| @ -14,7 +14,6 @@ Given a sample.yml file of: | ||||
| c: frog | ||||
| a: blah | ||||
| b: bing | ||||
| '': null | ||||
| ``` | ||||
| then | ||||
| ```bash | ||||
| @ -22,7 +21,6 @@ yq eval 'sortKeys(.)' sample.yml | ||||
| ``` | ||||
| will output | ||||
| ```yaml | ||||
| '': null | ||||
| a: blah | ||||
| b: bing | ||||
| c: frog | ||||
| @ -33,9 +31,19 @@ Note the array elements are left unsorted, but maps inside arrays are sorted | ||||
| 
 | ||||
| Given a sample.yml file of: | ||||
| ```yaml | ||||
| bParent: {c: dog, array: [3, 1, 2]} | ||||
| aParent: {z: donkey, x: [{c: yum, b: delish}, {b: ew, a: apple}]} | ||||
| '': null | ||||
| bParent: | ||||
|   c: dog | ||||
|   array: | ||||
|     - 3 | ||||
|     - 1 | ||||
|     - 2 | ||||
| aParent: | ||||
|   z: donkey | ||||
|   x: | ||||
|     - c: yum | ||||
|       b: delish | ||||
|     - b: ew | ||||
|       a: apple | ||||
| ``` | ||||
| then | ||||
| ```bash | ||||
| @ -43,8 +51,18 @@ yq eval 'sortKeys(..)' sample.yml | ||||
| ``` | ||||
| will output | ||||
| ```yaml | ||||
| '': null | ||||
| aParent: {z: donkey, x: [{c: yum, b: delish}, {b: ew, a: apple}]} | ||||
| bParent: {c: dog, array: [3, 1, 2]} | ||||
| aParent: | ||||
|   x: | ||||
|     - b: delish | ||||
|       c: yum | ||||
|     - a: apple | ||||
|       b: ew | ||||
|   z: donkey | ||||
| bParent: | ||||
|   array: | ||||
|     - 3 | ||||
|     - 1 | ||||
|     - 2 | ||||
|   c: dog | ||||
| ``` | ||||
| 
 | ||||
|  | ||||
| @ -6,7 +6,6 @@ a: cat | ||||
| b: 5 | ||||
| c: 3.2 | ||||
| e: true | ||||
| '': null | ||||
| ``` | ||||
| then | ||||
| ```bash | ||||
| @ -15,11 +14,10 @@ yq eval '.. style="tagged"' sample.yml | ||||
| will output | ||||
| ```yaml | ||||
| !!map | ||||
| a: cat | ||||
| b: 5 | ||||
| c: 3.2 | ||||
| e: true | ||||
| '': !!null null | ||||
| a: !!str cat | ||||
| b: !!int 5 | ||||
| c: !!float 3.2 | ||||
| e: !!bool true | ||||
| ``` | ||||
| 
 | ||||
| ## Set double quote style | ||||
| @ -29,7 +27,6 @@ a: cat | ||||
| b: 5 | ||||
| c: 3.2 | ||||
| e: true | ||||
| '': null | ||||
| ``` | ||||
| then | ||||
| ```bash | ||||
| @ -37,11 +34,10 @@ yq eval '.. style="double"' sample.yml | ||||
| ``` | ||||
| will output | ||||
| ```yaml | ||||
| a: cat | ||||
| b: 5 | ||||
| c: 3.2 | ||||
| e: true | ||||
| '': "null" | ||||
| a: "cat" | ||||
| b: "5" | ||||
| c: "3.2" | ||||
| e: "true" | ||||
| ``` | ||||
| 
 | ||||
| ## Set single quote style | ||||
| @ -51,7 +47,6 @@ a: cat | ||||
| b: 5 | ||||
| c: 3.2 | ||||
| e: true | ||||
| '': null | ||||
| ``` | ||||
| then | ||||
| ```bash | ||||
| @ -59,11 +54,10 @@ yq eval '.. style="single"' sample.yml | ||||
| ``` | ||||
| will output | ||||
| ```yaml | ||||
| a: cat | ||||
| b: 5 | ||||
| c: 3.2 | ||||
| e: true | ||||
| '': 'null' | ||||
| a: 'cat' | ||||
| b: '5' | ||||
| c: '3.2' | ||||
| e: 'true' | ||||
| ``` | ||||
| 
 | ||||
| ## Set literal quote style | ||||
| @ -73,7 +67,6 @@ a: cat | ||||
| b: 5 | ||||
| c: 3.2 | ||||
| e: true | ||||
| '': null | ||||
| ``` | ||||
| then | ||||
| ```bash | ||||
| @ -81,12 +74,14 @@ yq eval '.. style="literal"' sample.yml | ||||
| ``` | ||||
| will output | ||||
| ```yaml | ||||
| a: cat | ||||
| b: 5 | ||||
| c: 3.2 | ||||
| e: true | ||||
| '': |- | ||||
|   null | ||||
| a: |- | ||||
|   cat | ||||
| b: |- | ||||
|   5 | ||||
| c: |- | ||||
|   3.2 | ||||
| e: |- | ||||
|   true | ||||
| ``` | ||||
| 
 | ||||
| ## Set folded quote style | ||||
| @ -96,7 +91,6 @@ a: cat | ||||
| b: 5 | ||||
| c: 3.2 | ||||
| e: true | ||||
| '': null | ||||
| ``` | ||||
| then | ||||
| ```bash | ||||
| @ -104,12 +98,14 @@ yq eval '.. style="folded"' sample.yml | ||||
| ``` | ||||
| will output | ||||
| ```yaml | ||||
| a: cat | ||||
| b: 5 | ||||
| c: 3.2 | ||||
| e: true | ||||
| '': >- | ||||
|   null | ||||
| a: >- | ||||
|   cat | ||||
| b: >- | ||||
|   5 | ||||
| c: >- | ||||
|   3.2 | ||||
| e: >- | ||||
|   true | ||||
| ``` | ||||
| 
 | ||||
| ## Set flow quote style | ||||
| @ -119,7 +115,6 @@ a: cat | ||||
| b: 5 | ||||
| c: 3.2 | ||||
| e: true | ||||
| '': null | ||||
| ``` | ||||
| then | ||||
| ```bash | ||||
| @ -127,7 +122,7 @@ yq eval '.. style="flow"' sample.yml | ||||
| ``` | ||||
| will output | ||||
| ```yaml | ||||
| {a: cat, b: 5, c: 3.2, e: true, '': null} | ||||
| {a: cat, b: 5, c: 3.2, e: true} | ||||
| ``` | ||||
| 
 | ||||
| ## Pretty print | ||||
| @ -139,7 +134,6 @@ a: cat | ||||
| b: 5 | ||||
| c: 3.2 | ||||
| e: true | ||||
| '': null | ||||
| ``` | ||||
| then | ||||
| ```bash | ||||
| @ -151,7 +145,6 @@ a: cat | ||||
| b: 5 | ||||
| c: 3.2 | ||||
| e: true | ||||
| '': null | ||||
| ``` | ||||
| 
 | ||||
| ## Read style | ||||
| @ -166,6 +159,7 @@ yq eval '.. | style' sample.yml | ||||
| will output | ||||
| ```yaml | ||||
| flow | ||||
| 
 | ||||
| double | ||||
| single | ||||
| ``` | ||||
| 
 | ||||
|  | ||||
| @ -7,7 +7,6 @@ b: 5 | ||||
| c: 3.2 | ||||
| e: true | ||||
| f: [] | ||||
| '': null | ||||
| ``` | ||||
| then | ||||
| ```bash | ||||
| @ -16,7 +15,11 @@ yq eval '.. | tag' sample.yml | ||||
| will output | ||||
| ```yaml | ||||
| !!map | ||||
| !!null | ||||
| !!str | ||||
| !!int | ||||
| !!float | ||||
| !!bool | ||||
| !!seq | ||||
| ``` | ||||
| 
 | ||||
| ## Convert numbers to strings | ||||
| @ -26,7 +29,6 @@ a: cat | ||||
| b: 5 | ||||
| c: 3.2 | ||||
| e: true | ||||
| '': null | ||||
| ``` | ||||
| then | ||||
| ```bash | ||||
| @ -35,9 +37,8 @@ yq eval '(.. | select(tag == "!!int")) tag= "!!str"' sample.yml | ||||
| will output | ||||
| ```yaml | ||||
| a: cat | ||||
| b: 5 | ||||
| b: "5" | ||||
| c: 3.2 | ||||
| e: true | ||||
| '': null | ||||
| ``` | ||||
| 
 | ||||
|  | ||||
| @ -294,8 +294,8 @@ yq eval '.foobar.[]' sample.yml | ||||
| ``` | ||||
| will output | ||||
| ```yaml | ||||
| foobar_c | ||||
| *foo | ||||
| foo_c | ||||
| foo_a | ||||
| foobar_thing | ||||
| ``` | ||||
| 
 | ||||
| @ -360,9 +360,9 @@ yq eval '.foobarList.[]' sample.yml | ||||
| ``` | ||||
| will output | ||||
| ```yaml | ||||
| foobarList_b | ||||
| - *foo | ||||
| - *bar | ||||
| bar_b | ||||
| foo_a | ||||
| bar_thing | ||||
| foobarList_c | ||||
| ``` | ||||
| 
 | ||||
|  | ||||
| @ -17,7 +17,6 @@ Given a sample.yml file of: | ||||
| a: fieldA | ||||
| b: fieldB | ||||
| c: fieldC | ||||
| '': null | ||||
| ``` | ||||
| then | ||||
| ```bash | ||||
|  | ||||
| @ -58,7 +58,7 @@ func traverse(d *dataTreeNavigator, matchingNode *CandidateNode, operation *Oper | ||||
| 		if operation.Preferences != nil { | ||||
| 			followAlias = !operation.Preferences.(*TraversePreferences).DontFollowAlias | ||||
| 		} | ||||
| 		return traverseMap(matchingNode, operation.StringValue, followAlias) | ||||
| 		return traverseMap(matchingNode, operation.StringValue, followAlias, false) | ||||
| 
 | ||||
| 	case yaml.SequenceNode: | ||||
| 		log.Debug("its a sequence of %v things!", len(value.Content)) | ||||
| @ -135,26 +135,15 @@ func traverseArrayIndices(matchingNode *CandidateNode, indicesToTraverse []*yaml | ||||
| } | ||||
| 
 | ||||
| func traverseMapWithIndices(candidate *CandidateNode, indices []*yaml.Node, followAlias bool) (*list.List, error) { | ||||
| 
 | ||||
| 	node := UnwrapDoc(candidate.Node) | ||||
| 	var contents = node.Content | ||||
| 	var matchingNodeMap = list.New() | ||||
| 	if len(indices) == 0 { | ||||
| 		for index := 0; index < len(contents); index = index + 2 { | ||||
| 			key := contents[index] | ||||
| 			value := contents[index+1] | ||||
| 			matchingNodeMap.PushBack(&CandidateNode{ | ||||
| 				Node:     value, | ||||
| 				Path:     candidate.CreateChildPath(key.Value), | ||||
| 				Document: candidate.Document, | ||||
| 			}) | ||||
| 		} | ||||
| 		return matchingNodeMap, nil | ||||
| 		return traverseMap(candidate, "", followAlias, true) | ||||
| 	} | ||||
| 
 | ||||
| 	var matchingNodeMap = list.New() | ||||
| 
 | ||||
| 	for _, indexNode := range indices { | ||||
| 		log.Debug("traverseMapWithIndices: %v", indexNode.Value) | ||||
| 		newNodes, err := traverseMap(candidate, indexNode.Value, followAlias) | ||||
| 		newNodes, err := traverseMap(candidate, indexNode.Value, followAlias, false) | ||||
| 		if err != nil { | ||||
| 			return nil, err | ||||
| 		} | ||||
| @ -217,9 +206,9 @@ func keyMatches(key *yaml.Node, wantedKey string) bool { | ||||
| 	return Match(key.Value, wantedKey) | ||||
| } | ||||
| 
 | ||||
| func traverseMap(matchingNode *CandidateNode, key string, followAlias bool) (*list.List, error) { | ||||
| func traverseMap(matchingNode *CandidateNode, key string, followAlias bool, splat bool) (*list.List, error) { | ||||
| 	var newMatches = orderedmap.NewOrderedMap() | ||||
| 	err := doTraverseMap(newMatches, matchingNode, key, followAlias) | ||||
| 	err := doTraverseMap(newMatches, matchingNode, key, followAlias, splat) | ||||
| 
 | ||||
| 	if err != nil { | ||||
| 		return nil, err | ||||
| @ -248,7 +237,7 @@ func traverseMap(matchingNode *CandidateNode, key string, followAlias bool) (*li | ||||
| 	return results, nil | ||||
| } | ||||
| 
 | ||||
| func doTraverseMap(newMatches *orderedmap.OrderedMap, candidate *CandidateNode, wantedKey string, followAlias bool) error { | ||||
| func doTraverseMap(newMatches *orderedmap.OrderedMap, candidate *CandidateNode, wantedKey string, followAlias bool, splat bool) error { | ||||
| 	// 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 | ||||
| @ -265,11 +254,11 @@ func doTraverseMap(newMatches *orderedmap.OrderedMap, candidate *CandidateNode, | ||||
| 		//skip the 'merge' tag, find a direct match first | ||||
| 		if key.Tag == "!!merge" && followAlias { | ||||
| 			log.Debug("Merge anchor") | ||||
| 			err := traverseMergeAnchor(newMatches, candidate, value, wantedKey) | ||||
| 			err := traverseMergeAnchor(newMatches, candidate, value, wantedKey, splat) | ||||
| 			if err != nil { | ||||
| 				return err | ||||
| 			} | ||||
| 		} else if keyMatches(key, wantedKey) { | ||||
| 		} else if splat || keyMatches(key, wantedKey) { | ||||
| 			log.Debug("MATCHED") | ||||
| 			candidateNode := &CandidateNode{ | ||||
| 				Node:     value, | ||||
| @ -283,7 +272,7 @@ func doTraverseMap(newMatches *orderedmap.OrderedMap, candidate *CandidateNode, | ||||
| 	return nil | ||||
| } | ||||
| 
 | ||||
| func traverseMergeAnchor(newMatches *orderedmap.OrderedMap, originalCandidate *CandidateNode, value *yaml.Node, wantedKey string) error { | ||||
| func traverseMergeAnchor(newMatches *orderedmap.OrderedMap, originalCandidate *CandidateNode, value *yaml.Node, wantedKey string, splat bool) error { | ||||
| 	switch value.Kind { | ||||
| 	case yaml.AliasNode: | ||||
| 		candidateNode := &CandidateNode{ | ||||
| @ -291,10 +280,10 @@ func traverseMergeAnchor(newMatches *orderedmap.OrderedMap, originalCandidate *C | ||||
| 			Path:     originalCandidate.Path, | ||||
| 			Document: originalCandidate.Document, | ||||
| 		} | ||||
| 		return doTraverseMap(newMatches, candidateNode, wantedKey, true) | ||||
| 		return doTraverseMap(newMatches, candidateNode, wantedKey, true, splat) | ||||
| 	case yaml.SequenceNode: | ||||
| 		for _, childValue := range value.Content { | ||||
| 			err := traverseMergeAnchor(newMatches, originalCandidate, childValue, wantedKey) | ||||
| 			err := traverseMergeAnchor(newMatches, originalCandidate, childValue, wantedKey, splat) | ||||
| 			if err != nil { | ||||
| 				return err | ||||
| 			} | ||||
|  | ||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user