mirror of
				https://github.com/taigrr/yq
				synced 2025-01-18 04:53:17 -08:00 
			
		
		
		
	Added recurse examples
This commit is contained in:
		
							parent
							
								
									658006eb93
								
							
						
					
					
						commit
						529e88b630
					
				| @ -32,6 +32,48 @@ a: frog | |||||||
| frog | frog | ||||||
| ``` | ``` | ||||||
| 
 | 
 | ||||||
|  | ## Recursively find nodes with keys | ||||||
|  | Given a sample.yml file of: | ||||||
|  | ```yaml | ||||||
|  | a: | ||||||
|  |   name: frog | ||||||
|  |   b: | ||||||
|  |     name: blog | ||||||
|  |     age: 12 | ||||||
|  | ``` | ||||||
|  | then | ||||||
|  | ```bash | ||||||
|  | yq eval '.. | select(has("name"))' sample.yml | ||||||
|  | ``` | ||||||
|  | will output | ||||||
|  | ```yaml | ||||||
|  | name: frog | ||||||
|  | b: | ||||||
|  |   name: blog | ||||||
|  |   age: 12 | ||||||
|  | name: blog | ||||||
|  | age: 12 | ||||||
|  | ``` | ||||||
|  | 
 | ||||||
|  | ## Recursively find nodes with values | ||||||
|  | Given a sample.yml file of: | ||||||
|  | ```yaml | ||||||
|  | a: | ||||||
|  |   nameA: frog | ||||||
|  |   b: | ||||||
|  |     nameB: frog | ||||||
|  |     age: 12 | ||||||
|  | ``` | ||||||
|  | then | ||||||
|  | ```bash | ||||||
|  | yq eval '.. | select(. == "frog")' sample.yml | ||||||
|  | ``` | ||||||
|  | will output | ||||||
|  | ```yaml | ||||||
|  | frog | ||||||
|  | frog | ||||||
|  | ``` | ||||||
|  | 
 | ||||||
| ## Recurse map (values and keys) | ## Recurse map (values and keys) | ||||||
| Note that the map key appears in the results | Note that the map key appears in the results | ||||||
| 
 | 
 | ||||||
|  | |||||||
| @ -62,6 +62,24 @@ var recursiveDescentOperatorScenarios = []expressionScenario{ | |||||||
| 			"D0, P[a], (!!str)::frog\n", | 			"D0, P[a], (!!str)::frog\n", | ||||||
| 		}, | 		}, | ||||||
| 	}, | 	}, | ||||||
|  | 	{ | ||||||
|  | 		description: "Recursively find nodes with keys", | ||||||
|  | 		document:    `{a: {name: frog, b: {name: blog, age: 12}}}`, | ||||||
|  | 		expression:  `.. | select(has("name"))`, | ||||||
|  | 		expected: []string{ | ||||||
|  | 			"D0, P[a], (!!map)::{name: frog, b: {name: blog, age: 12}}\n", | ||||||
|  | 			"D0, P[a b], (!!map)::{name: blog, age: 12}\n", | ||||||
|  | 		}, | ||||||
|  | 	}, | ||||||
|  | 	{ | ||||||
|  | 		description: "Recursively find nodes with values", | ||||||
|  | 		document:    `{a: {nameA: frog, b: {nameB: frog, age: 12}}}`, | ||||||
|  | 		expression:  `.. | select(. == "frog")`, | ||||||
|  | 		expected: []string{ | ||||||
|  | 			"D0, P[a nameA], (!!str)::frog\n", | ||||||
|  | 			"D0, P[a b nameB], (!!str)::frog\n", | ||||||
|  | 		}, | ||||||
|  | 	}, | ||||||
| 	{ | 	{ | ||||||
| 		description:    "Recurse map (values and keys)", | 		description:    "Recurse map (values and keys)", | ||||||
| 		subdescription: "Note that the map key appears in the results", | 		subdescription: "Note that the map key appears in the results", | ||||||
|  | |||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user