GitBook: [#212] poewrshell tips and tricks

This commit is contained in:
Mike Farah 2021-11-14 06:01:55 +00:00 committed by gitbook-bot
parent 3cdbfebe46
commit 76359d94c3
No known key found for this signature in database
GPG Key ID: 07D2180C7B12D0FF
3 changed files with 7 additions and 4 deletions

View File

@ -12,7 +12,7 @@
***
* Operators
* [Operators](operators/README.md)
* [Add](operators/add.md)
* [Alternative (Default value)](operators/alternative-default-value.md)
* [Anchor and Alias Operators](operators/anchor-and-alias-operators.md)

2
operators/README.md Normal file
View File

@ -0,0 +1,2 @@
# Operators

View File

@ -42,7 +42,7 @@ edit
## Set contents from another file
Use an environment variable with the `strenv` operator to inject the contents from an environment variable. 
Use an environment variable with the `strenv` operator to inject the contents from an environment variable.
```bash
LICENSE=$(cat LICENSE) yq eval -n '.a = strenv(LICENSE)'
@ -66,6 +66,8 @@ test: something
PS >
```
See [https://github.com/mikefarah/yq/issues/747](https://github.com/mikefarah/yq/issues/747) for more trickery.
## Merge / combine all documents into one
To merge all given yaml files into one, use the `reduce` operator with the `*` (multiply) operator. Note the use of `ea` or `eval-all` to load all files into memory so that they can be merged.
@ -116,7 +118,7 @@ In order to combine multiple yaml files into a single file (with `---` separator
yq e '.' somewhere/*.yaml
```
##  Multiple updates to the same path
## Multiple updates to the same path
You can use the [with](../operators/with.md) operator to set a nested context:
@ -131,4 +133,3 @@ The first argument expression sets the root context, and the second expression r
The merge functionality from yaml v1.1 (e.g. `<<:`has actually been removed in the 1.2 spec. Thankfully, `yq` underlying yaml parser still supports that tag - and it's extra nice in that it explicitly puts the `!!merge` tag on key of the map entry. This tag tells other yaml parsers that this entry is a merge entry, as opposed to a regular string key that happens to have a value of `<<:`. This is backwards compatible with the 1.1 spec of yaml, it's simply an explicit way of specifying the type (for instance, you can use a `!!str` tag to enforce a particular value to be a string.
Although this does affect the readability of the yaml to humans, it still works and processes fine with various yaml processors.