mirror of
https://github.com/mikefarah/yq.git
synced 2024-11-12 13:48:06 +00:00
Added File operators
This commit is contained in:
parent
d38caf6bc2
commit
e451119014
@ -1,13 +1,13 @@
|
||||
The file operator is used to filter based on filename. This is most often used with merge when needing to merge specific files together.
|
||||
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).
|
||||
|
||||
```bash
|
||||
yq eval 'filename == "file1.yaml" * fileIndex == 0' file1.yaml file2.yaml
|
||||
yq eval-all 'select(fileIndex == 0) * select(filename == "file2.yaml")' file1.yaml file2.yaml
|
||||
```
|
||||
## Examples
|
||||
### Get filename
|
||||
Given a sample.yml file of:
|
||||
```yaml
|
||||
'': null
|
||||
a: cat
|
||||
```
|
||||
then
|
||||
```bash
|
||||
@ -21,7 +21,7 @@ sample.yaml
|
||||
### Get file index
|
||||
Given a sample.yml file of:
|
||||
```yaml
|
||||
'': null
|
||||
a: cat
|
||||
```
|
||||
then
|
||||
```bash
|
||||
|
@ -1,5 +1,5 @@
|
||||
The file operator is used to filter based on filename. This is most often used with merge when needing to merge specific files together.
|
||||
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).
|
||||
|
||||
```bash
|
||||
yq eval 'filename == "file1.yaml" * fileIndex == 0' file1.yaml file2.yaml
|
||||
yq eval-all 'select(fileIndex == 0) * select(filename == "file2.yaml")' file1.yaml file2.yaml
|
||||
```
|
@ -18,8 +18,6 @@ type OperationType struct {
|
||||
|
||||
// operators TODO:
|
||||
// - get path operator (like doc index)
|
||||
// - get file index op (like doc index)
|
||||
// - get file name op (like doc index)
|
||||
// - write in place
|
||||
// - mergeAppend (merges and appends arrays)
|
||||
// - mergeEmpty (sets only if the document is empty, do I do that now?)
|
||||
|
@ -7,7 +7,7 @@ import (
|
||||
var fileOperatorScenarios = []expressionScenario{
|
||||
{
|
||||
description: "Get filename",
|
||||
document: `{}`,
|
||||
document: `{a: cat}`,
|
||||
expression: `filename`,
|
||||
expected: []string{
|
||||
"D0, P[], (!!str)::sample.yml\n",
|
||||
@ -15,7 +15,7 @@ var fileOperatorScenarios = []expressionScenario{
|
||||
},
|
||||
{
|
||||
description: "Get file index",
|
||||
document: `{}`,
|
||||
document: `{a: cat}`,
|
||||
expression: `fileIndex`,
|
||||
expected: []string{
|
||||
"D0, P[], (!!int)::0\n",
|
||||
|
Loading…
Reference in New Issue
Block a user