mirror of
https://github.com/mikefarah/yq.git
synced 2024-12-19 20:19:04 +00:00
GitBook: [#212] poewrshell tips and tricks
This commit is contained in:
parent
3cdbfebe46
commit
76359d94c3
@ -12,7 +12,7 @@
|
|||||||
|
|
||||||
***
|
***
|
||||||
|
|
||||||
* Operators
|
* [Operators](operators/README.md)
|
||||||
* [Add](operators/add.md)
|
* [Add](operators/add.md)
|
||||||
* [Alternative (Default value)](operators/alternative-default-value.md)
|
* [Alternative (Default value)](operators/alternative-default-value.md)
|
||||||
* [Anchor and Alias Operators](operators/anchor-and-alias-operators.md)
|
* [Anchor and Alias Operators](operators/anchor-and-alias-operators.md)
|
||||||
|
2
operators/README.md
Normal file
2
operators/README.md
Normal file
@ -0,0 +1,2 @@
|
|||||||
|
# Operators
|
||||||
|
|
@ -42,7 +42,7 @@ edit
|
|||||||
|
|
||||||
## Set contents from another file
|
## 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
|
```bash
|
||||||
LICENSE=$(cat LICENSE) yq eval -n '.a = strenv(LICENSE)'
|
LICENSE=$(cat LICENSE) yq eval -n '.a = strenv(LICENSE)'
|
||||||
@ -66,6 +66,8 @@ test: something
|
|||||||
PS >
|
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
|
## 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.
|
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
|
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:
|
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.
|
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.
|
Although this does affect the readability of the yaml to humans, it still works and processes fine with various yaml processors.
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user