Update document generation script

This commit is contained in:
Mike Farah
2021-11-03 22:37:07 +11:00
parent de90b3e85e
commit 0557439765
101 changed files with 4387 additions and 180 deletions
-1
View File
@@ -1 +0,0 @@
Deletes matching entries in maps or arrays.
-3
View File
@@ -1,3 +0,0 @@
# Keys
Use the `keys` operator to return map keys or array indices.
-1
View File
@@ -1 +0,0 @@
This operator is used to combine different results together.
@@ -1,3 +1,5 @@
# Anchor and Alias Operators
Use the `alias` and `anchor` operators to read and write yaml aliases and anchors. The `explode` operator normalises a yaml file (dereference (or expands) aliases and remove anchor names).
`yq` supports merge aliases (like `<<: *blah`) however this is no longer in the standard yaml spec (1.2) and so `yq` will automatically add the `!!merge` tag to these nodes as it is effectively a custom tag.
+2
View File
@@ -1,3 +1,5 @@
# Assign (Update)
This operator is used to update node values. It can be used in either the:
### plain form: `=`
@@ -1,3 +1,5 @@
# Boolean Operators
The `or` and `and` operators take two parameters and return a boolean result.
`not` flips a boolean from true to false, or vice versa.
+2 -2
View File
@@ -1,11 +1,11 @@
# Comment Operators
Use these comment operators to set or retrieve comments.
Like the `=` and `|=` assign operators, the same syntax applies when updating comments:
### plain form: `=`
This will assign the LHS nodes comments to the expression on the RHS. The RHS is run against the matching nodes in the pipeline
### relative form: `|=`
Similar to the plain form, however the RHS evaluates against each matching LHS node! This is useful if you want to set the comments as a relative expression of the node, for instance its value or path.
+3
View File
@@ -0,0 +1,3 @@
# Contains
This returns `true` if the context contains the passed in parameter, and false otherwise.
@@ -1 +1,3 @@
This is used to construct objects (or maps). This can be used against existing yaml, or to create fresh yaml documents.
# Create, Collect into Object
This is used to construct objects (or maps). This can be used against existing yaml, or to create fresh yaml documents.
+3
View File
@@ -0,0 +1,3 @@
# Delete
Deletes matching entries in maps or arrays.
@@ -1 +1,3 @@
Use the `documentIndex` operator (or the `di` shorthand) to select nodes of a particular document.
# Document Index
Use the `documentIndex` operator (or the `di` shorthand) to select nodes of a particular document.
@@ -1 +1,3 @@
Similar to the same named functions in `jq` these functions convert to/from an object and an array of key-value pairs. This is most useful for performing operations on keys of maps.
# Entries
Similar to the same named functions in `jq` these functions convert to/from an object and an array of key-value pairs. This is most useful for performing operations on keys of maps.
@@ -1,2 +1,3 @@
This operator is used to handle environment variables usage in path expressions. While environment variables can, of course, be passed in via your CLI with string interpolation, this often comes with complex quote escaping and can be tricky to write and read. Note that there are two forms, `env` which will parse the environment variable as a yaml (be it a map, array, string, number of boolean) and `strenv` which will always parse the argument as a string.
# Env Variable Operators
This operator is used to handle environment variables usage in path expressions. While environment variables can, of course, be passed in via your CLI with string interpolation, this often comes with complex quote escaping and can be tricky to write and read. Note that there are two forms, `env` which will parse the environment variable as a yaml (be it a map, array, string, number of boolean) and `strenv` which will always parse the argument as a string.
@@ -1,4 +1,6 @@
This is a boolean operator that will return ```true``` if the LHS is equal to the RHS and ``false`` otherwise.
# Equals
This is a boolean operator that will return `true` if the LHS is equal to the RHS and `false` otherwise.
```
.a == .b
@@ -9,4 +11,3 @@ It is most often used with the select operator to find particular nodes:
```
select(.a == .b)
```
@@ -1,3 +1,5 @@
# File Operators
File operators are most often used with merge when needing to merge specific files together. Note that when doing this, you will need to use `eval-all` to ensure all yaml documents are loaded into memory before performing the merge (as opposed to `eval` which runs the expression once per document).
Note that the `fileIndex` operator has a short alias of `fi`.
@@ -6,4 +8,4 @@ Note that the `fileIndex` operator has a short alias of `fi`.
Note the use of eval-all to ensure all documents are loaded into memory.
```bash
yq eval-all 'select(fi == 0) * select(filename == "file2.yaml")' file1.yaml file2.yaml
```
```
@@ -1 +1,3 @@
This is operation that returns true if the key exists in a map (or index in an array), false otherwise.
# Has
This is operation that returns true if the key exists in a map (or index in an array), false otherwise.
+3
View File
@@ -0,0 +1,3 @@
# Keys
Use the `keys` operator to return map keys or array indices.
@@ -1 +1,3 @@
# Length
Returns the lengths of the nodes. Length is defined according to the type of the node.
@@ -1,3 +1,5 @@
# Multiply (Merge)
Like the multiple operator in jq, depending on the operands, this multiply operator will do different things. Currently numbers, arrays and objects are supported.
## Objects and arrays - merging
@@ -1,3 +1,5 @@
# Path
The path operator can be used to get the traversal paths of matching nodes in an expression. The path is returned as an array, which if traversed in order will lead to the matching node.
You can get the key/index of matching nodes by using the `path` operator to return the path array then piping that through `.[-1]` to get the last element of that array, the key.
@@ -1 +1,3 @@
# Pipe
Pipe the results of an expression into another. Like the bash operator.
@@ -1,3 +1,5 @@
# Recursive Descent (Glob)
This operator recursively matches (or globs) all children nodes given of a particular element, including that node itself. This is most often used to apply a filter recursively against all matches. It can be used in either the
## match values form `..`
@@ -1,3 +1,5 @@
# Reduce
Reduce is a powerful way to process a collection of data into a new form.
```
@@ -18,4 +20,3 @@ On the RHS there is `<init>`, the starting value of the accumulator and `<block>
Reduce syntax in `yq` is a little different from `jq` - as `yq` (currently) isn't as sophisticated as `jq` and its only supports infix notation (e.g. a + b, where the operator is in the middle of the two parameters) - where as `jq` uses a mix of infix notation with _prefix_ notation (e.g. `reduce a b` is like writing `+ a b`).
To that end, the reduce operator is called `ireduce` for backwards compatability if a `jq` like prefix version of `reduce` is ever added.
@@ -1 +1,3 @@
Select is used to filter arrays and maps by a boolean expression.
# Select
Select is used to filter arrays and maps by a boolean expression.
@@ -1,3 +1,5 @@
# Sort Keys
The Sort Keys operator sorts maps by their keys (based on their string value). This operator does not do anything to arrays or scalars (so you can easily recursively apply it to all maps).
Sort is particularly useful for diffing two different yaml documents:
@@ -4,7 +4,7 @@
This uses golangs native regex functions under the hood - See https://github.com/google/re2/wiki/Syntax for the supported syntax.
# String blocks, bash and newlines
## String blocks, bash and newlines
Bash is notorious for chomping on precious trailing newline characters, making it tricky to set strings with newlines properly. In particular, the `$( exp )` _will trim trailing newlines_.
For instance to get this yaml:
@@ -41,4 +41,4 @@ Similarly, if you're trying to set the content from a file, and want a trailing
```
IFS= read -rd '' output < <(cat my_file)
output=$output ./yq e '.data.values = strenv(output)' first.yml
```
```
@@ -1 +1,3 @@
The style operator can be used to get or set the style of nodes (e.g. string style, yaml style)
# Style
The style operator can be used to get or set the style of nodes (e.g. string style, yaml style)
+3
View File
@@ -0,0 +1,3 @@
# Subtract
You can use subtract to subtract numbers, as well as removing elements from an array.
@@ -1 +1,3 @@
The tag operator can be used to get or set the tag of nodes (e.g. `!!str`, `!!int`, `!!bool`).
# Tag
The tag operator can be used to get or set the tag of nodes (e.g. `!!str`, `!!int`, `!!bool`).
@@ -1 +1,3 @@
This is the simplest (and perhaps most used) operator, it is used to navigate deeply into yaml structures.
# Traverse (Read)
This is the simplest (and perhaps most used) operator, it is used to navigate deeply into yaml structures.
+3
View File
@@ -0,0 +1,3 @@
# Union
This operator is used to combine different results together.
@@ -1 +1,3 @@
# Unique
This is used to filter out duplicated items in an array.
@@ -1,3 +1,5 @@
# Variable Operators
Like the `jq` equivalents, variables are sometimes required for the more complex expressions (or swapping values between fields).
Note that there is also an additional `ref` operator that holds a reference (instead of a copy) of the path, allowing you to make multiple changes to the same path.
@@ -1 +1,3 @@
# With
Use the `with` operator to conveniently make multiple updates to a deeply nested path, or to update array elements relatively to each other. The first argument expression sets the root context, and the second expression runs against that root context.