mirror of
https://github.com/mikefarah/yq.git
synced 2026-09-01 14:14:52 +08:00
Added support for load_props, added missing load_xml tests
This commit is contained in:
@@ -1,10 +1,17 @@
|
||||
# Load
|
||||
|
||||
The `load`/`strload` operator allows you to load in content from another file referenced in your yaml document.
|
||||
The load operators allows you to load in content from another file.
|
||||
|
||||
Note that you can use string operators like `+` and `sub` to modify the value in the yaml file to a path that exists in your system.
|
||||
|
||||
Use `strload` to load text based content as a string block, and `load` to interpret the file as yaml.
|
||||
You can load files of the following supported types:
|
||||
|
||||
|Format | Load Operator |
|
||||
| --- | --- |
|
||||
| Yaml | load |
|
||||
| XML | load_xml |
|
||||
| Properties | load_props |
|
||||
| Plain String | load_str |
|
||||
|
||||
Lets say there is a file `../../examples/thing.yml`:
|
||||
|
||||
@@ -12,3 +19,14 @@ Lets say there is a file `../../examples/thing.yml`:
|
||||
a: apple is included
|
||||
b: cool
|
||||
```
|
||||
and a file `small.xml`:
|
||||
|
||||
```xml
|
||||
<this>is some xml</this>
|
||||
```
|
||||
|
||||
and `small.properties`:
|
||||
|
||||
```properties
|
||||
this.is = a properties file
|
||||
```
|
||||
|
||||
@@ -1,10 +1,17 @@
|
||||
# Load
|
||||
|
||||
The `load`/`strload` operator allows you to load in content from another file referenced in your yaml document.
|
||||
The load operators allows you to load in content from another file.
|
||||
|
||||
Note that you can use string operators like `+` and `sub` to modify the value in the yaml file to a path that exists in your system.
|
||||
|
||||
Use `strload` to load text based content as a string block, and `load` to interpret the file as yaml.
|
||||
You can load files of the following supported types:
|
||||
|
||||
|Format | Load Operator |
|
||||
| --- | --- |
|
||||
| Yaml | load |
|
||||
| XML | load_xml |
|
||||
| Properties | load_props |
|
||||
| Plain String | load_str |
|
||||
|
||||
Lets say there is a file `../../examples/thing.yml`:
|
||||
|
||||
@@ -12,6 +19,17 @@ Lets say there is a file `../../examples/thing.yml`:
|
||||
a: apple is included
|
||||
b: cool
|
||||
```
|
||||
and a file `small.xml`:
|
||||
|
||||
```xml
|
||||
<this>is some xml</this>
|
||||
```
|
||||
|
||||
and `small.properties`:
|
||||
|
||||
```properties
|
||||
this.is = a properties file
|
||||
```
|
||||
|
||||
{% hint style="warning" %}
|
||||
Note that versions prior to 4.18 require the 'eval/e' command to be specified. 
|
||||
@@ -89,7 +107,7 @@ something:
|
||||
```
|
||||
then
|
||||
```bash
|
||||
yq '.something |= strload("../../examples/" + .file)' sample.yml
|
||||
yq '.something |= load_str("../../examples/" + .file)' sample.yml
|
||||
```
|
||||
will output
|
||||
```yaml
|
||||
@@ -98,3 +116,56 @@ something: |-
|
||||
b: cool.
|
||||
```
|
||||
|
||||
## Load from XML
|
||||
Given a sample.yml file of:
|
||||
```yaml
|
||||
cool: things
|
||||
```
|
||||
then
|
||||
```bash
|
||||
yq '.more_stuff = load_xml("../../examples/small.xml")' sample.yml
|
||||
```
|
||||
will output
|
||||
```yaml
|
||||
cool: things
|
||||
more_stuff:
|
||||
this: is some xml
|
||||
```
|
||||
|
||||
## Load from Properties
|
||||
Given a sample.yml file of:
|
||||
```yaml
|
||||
cool: things
|
||||
```
|
||||
then
|
||||
```bash
|
||||
yq '.more_stuff = load_props("../../examples/small.properties")' sample.yml
|
||||
```
|
||||
will output
|
||||
```yaml
|
||||
cool: things
|
||||
more_stuff:
|
||||
this:
|
||||
is: a properties file
|
||||
```
|
||||
|
||||
## Merge from properties
|
||||
This can be used as a convenient way to update a yaml document
|
||||
|
||||
Given a sample.yml file of:
|
||||
```yaml
|
||||
this:
|
||||
is: from yaml
|
||||
cool: ay
|
||||
```
|
||||
then
|
||||
```bash
|
||||
yq '. *= load_props("../../examples/small.properties")' sample.yml
|
||||
```
|
||||
will output
|
||||
```yaml
|
||||
this:
|
||||
is: a properties file
|
||||
cool: ay
|
||||
```
|
||||
|
||||
|
||||
Reference in New Issue
Block a user