mirror of
https://github.com/mikefarah/yq.git
synced 2026-09-06 18:24:57 +08:00
Update document generation script
This commit is contained in:
@@ -3,68 +3,50 @@
|
||||
This is used to construct objects (or maps). This can be used against existing yaml, or to create fresh yaml documents.
|
||||
|
||||
## Collect empty object
|
||||
|
||||
Running
|
||||
|
||||
```bash
|
||||
yq eval --null-input '{}'
|
||||
```
|
||||
|
||||
will output
|
||||
|
||||
```yaml
|
||||
{}
|
||||
```
|
||||
|
||||
## Wrap (prefix) existing object
|
||||
|
||||
Given a sample.yml file of:
|
||||
|
||||
```yaml
|
||||
name: Mike
|
||||
```
|
||||
|
||||
then
|
||||
|
||||
```bash
|
||||
yq eval '{"wrap": .}' sample.yml
|
||||
```
|
||||
|
||||
will output
|
||||
|
||||
```yaml
|
||||
wrap:
|
||||
name: Mike
|
||||
```
|
||||
|
||||
## Using splat to create multiple objects
|
||||
|
||||
Given a sample.yml file of:
|
||||
|
||||
```yaml
|
||||
name: Mike
|
||||
pets:
|
||||
- cat
|
||||
- dog
|
||||
```
|
||||
|
||||
then
|
||||
|
||||
```bash
|
||||
yq eval '{.name: .pets.[]}' sample.yml
|
||||
```
|
||||
|
||||
will output
|
||||
|
||||
```yaml
|
||||
Mike: cat
|
||||
Mike: dog
|
||||
```
|
||||
|
||||
## Working with multiple documents
|
||||
|
||||
Given a sample.yml file of:
|
||||
|
||||
```yaml
|
||||
name: Mike
|
||||
pets:
|
||||
@@ -76,15 +58,11 @@ pets:
|
||||
- monkey
|
||||
- sheep
|
||||
```
|
||||
|
||||
then
|
||||
|
||||
```bash
|
||||
yq eval '{.name: .pets.[]}' sample.yml
|
||||
```
|
||||
|
||||
will output
|
||||
|
||||
```yaml
|
||||
Mike: cat
|
||||
Mike: dog
|
||||
@@ -93,15 +71,12 @@ Rosey: sheep
|
||||
```
|
||||
|
||||
## Creating yaml from scratch
|
||||
|
||||
Running
|
||||
|
||||
```bash
|
||||
yq eval --null-input '{"wrap": "frog"}'
|
||||
```
|
||||
|
||||
will output
|
||||
|
||||
```yaml
|
||||
wrap: frog
|
||||
```
|
||||
|
||||
|
||||
Reference in New Issue
Block a user