mirror of
https://github.com/mikefarah/yq.git
synced 2026-09-07 02:48:27 +08:00
Update document generation script
This commit is contained in:
+2
-18
@@ -3,24 +3,18 @@
|
||||
This is operation that returns true if the key exists in a map (or index in an array), false otherwise.
|
||||
|
||||
## Has map key
|
||||
|
||||
Given a sample.yml file of:
|
||||
|
||||
```yaml
|
||||
- a: yes
|
||||
- a: ~
|
||||
- a:
|
||||
- b: nope
|
||||
```
|
||||
|
||||
then
|
||||
|
||||
```bash
|
||||
yq eval '.[] | has("a")' sample.yml
|
||||
```
|
||||
|
||||
will output
|
||||
|
||||
```yaml
|
||||
true
|
||||
true
|
||||
@@ -29,11 +23,9 @@ false
|
||||
```
|
||||
|
||||
## Select, checking for existence of deep paths
|
||||
|
||||
Simply pipe in parent expressions into `has`
|
||||
|
||||
Given a sample.yml file of:
|
||||
|
||||
```yaml
|
||||
- a:
|
||||
b:
|
||||
@@ -42,15 +34,11 @@ Given a sample.yml file of:
|
||||
b:
|
||||
d: dog
|
||||
```
|
||||
|
||||
then
|
||||
|
||||
```bash
|
||||
yq eval '.[] | select(.a.b | has("c"))' sample.yml
|
||||
```
|
||||
|
||||
will output
|
||||
|
||||
```yaml
|
||||
a:
|
||||
b:
|
||||
@@ -58,25 +46,20 @@ a:
|
||||
```
|
||||
|
||||
## Has array index
|
||||
|
||||
Given a sample.yml file of:
|
||||
|
||||
```yaml
|
||||
- []
|
||||
- [1]
|
||||
- [1, 2]
|
||||
- [1, null]
|
||||
- [1, 2, 3]
|
||||
|
||||
```
|
||||
|
||||
then
|
||||
|
||||
```bash
|
||||
yq eval '.[] | has(1)' sample.yml
|
||||
```
|
||||
|
||||
will output
|
||||
|
||||
```yaml
|
||||
false
|
||||
false
|
||||
@@ -84,3 +67,4 @@ true
|
||||
true
|
||||
true
|
||||
```
|
||||
|
||||
|
||||
Reference in New Issue
Block a user