mirror of
https://github.com/mikefarah/yq.git
synced 2024-11-12 05:38:04 +00:00
Added load_base64
This commit is contained in:
parent
d9bca65626
commit
61978b34df
1
examples/base64.txt
Normal file
1
examples/base64.txt
Normal file
@ -0,0 +1 @@
|
||||
bXkgc2VjcmV0IGNoaWxsaSByZWNpcGUgaXMuLi4u
|
@ -13,20 +13,33 @@ You can load files of the following supported types:
|
||||
| Properties | load_props |
|
||||
| Plain String | load_str |
|
||||
|
||||
Lets say there is a file `../../examples/thing.yml`:
|
||||
## Samples files for tests:
|
||||
|
||||
### yaml
|
||||
|
||||
`../../examples/thing.yml`:
|
||||
|
||||
```yaml
|
||||
a: apple is included
|
||||
b: cool
|
||||
```
|
||||
and a file `small.xml`:
|
||||
|
||||
### xml
|
||||
`small.xml`:
|
||||
|
||||
```xml
|
||||
<this>is some xml</this>
|
||||
```
|
||||
|
||||
and `small.properties`:
|
||||
### properties
|
||||
`small.properties`:
|
||||
|
||||
```properties
|
||||
this.is = a properties file
|
||||
```
|
||||
|
||||
### base64
|
||||
`base64.txt`:
|
||||
```
|
||||
bXkgc2VjcmV0IGNoaWxsaSByZWNpcGUgaXMuLi4u
|
||||
```
|
||||
|
@ -13,24 +13,37 @@ You can load files of the following supported types:
|
||||
| Properties | load_props |
|
||||
| Plain String | load_str |
|
||||
|
||||
Lets say there is a file `../../examples/thing.yml`:
|
||||
## Samples files for tests:
|
||||
|
||||
### yaml
|
||||
|
||||
`../../examples/thing.yml`:
|
||||
|
||||
```yaml
|
||||
a: apple is included
|
||||
b: cool
|
||||
```
|
||||
and a file `small.xml`:
|
||||
|
||||
### xml
|
||||
`small.xml`:
|
||||
|
||||
```xml
|
||||
<this>is some xml</this>
|
||||
```
|
||||
|
||||
and `small.properties`:
|
||||
### properties
|
||||
`small.properties`:
|
||||
|
||||
```properties
|
||||
this.is = a properties file
|
||||
```
|
||||
|
||||
### base64
|
||||
`base64.txt`:
|
||||
```
|
||||
bXkgc2VjcmV0IGNoaWxsaSByZWNpcGUgaXMuLi4u
|
||||
```
|
||||
|
||||
{% hint style="warning" %}
|
||||
Note that versions prior to 4.18 require the 'eval/e' command to be specified. 
|
||||
|
||||
@ -169,3 +182,18 @@ this:
|
||||
cool: ay
|
||||
```
|
||||
|
||||
## Load from base64 encoded file
|
||||
Given a sample.yml file of:
|
||||
```yaml
|
||||
cool: things
|
||||
```
|
||||
then
|
||||
```bash
|
||||
yq '.more_stuff = load_base64("../../examples/base64.txt")' sample.yml
|
||||
```
|
||||
will output
|
||||
```yaml
|
||||
cool: things
|
||||
more_stuff: my secret chilli recipe is....
|
||||
```
|
||||
|
||||
|
@ -383,6 +383,8 @@ func initLexer() (*lex.Lexer, error) {
|
||||
lexer.Add([]byte(`load_xml`), opTokenWithPrefs(loadOpType, nil, loadPrefs{loadAsString: false, decoder: NewXMLDecoder(XMLPreferences.AttributePrefix, XMLPreferences.ContentName)}))
|
||||
lexer.Add([]byte(`loadxml`), opTokenWithPrefs(loadOpType, nil, loadPrefs{loadAsString: false, decoder: NewXMLDecoder(XMLPreferences.AttributePrefix, XMLPreferences.ContentName)}))
|
||||
|
||||
lexer.Add([]byte(`load_base64`), opTokenWithPrefs(loadOpType, nil, loadPrefs{loadAsString: false, decoder: NewBase64Decoder()}))
|
||||
|
||||
lexer.Add([]byte(`load_props`), opTokenWithPrefs(loadOpType, nil, loadPrefs{loadAsString: false, decoder: NewPropertiesDecoder()}))
|
||||
lexer.Add([]byte(`loadprops`), opTokenWithPrefs(loadOpType, nil, loadPrefs{loadAsString: false, decoder: NewPropertiesDecoder()}))
|
||||
|
||||
|
@ -65,6 +65,14 @@ var loadScenarios = []expressionScenario{
|
||||
"D0, P[], (!!map)::this:\n is: a properties file\n cool: ay\n",
|
||||
},
|
||||
},
|
||||
{
|
||||
description: "Load from base64 encoded file",
|
||||
document: "cool: things",
|
||||
expression: `.more_stuff = load_base64("../../examples/base64.txt")`,
|
||||
expected: []string{
|
||||
"D0, P[], (doc)::cool: things\nmore_stuff: my secret chilli recipe is....\n",
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
func TestLoadScenarios(t *testing.T) {
|
||||
|
Loading…
Reference in New Issue
Block a user