mirror of
https://github.com/mikefarah/yq.git
synced 2026-07-06 13:25:42 +00:00
Updating style docs
This commit is contained in:
parent
461bb9c5fe
commit
2346332e86
@ -1,6 +1,8 @@
|
|||||||
# Style
|
# Style
|
||||||
|
|
||||||
The style operator can be used to get or set the style of nodes (e.g. string style, yaml style)
|
The style operator can be used to get or set the style of nodes (e.g. string style, yaml style).
|
||||||
|
Use this to control the formatting of the document in yaml.
|
||||||
|
|
||||||
|
|
||||||
## Update and set style of a particular node (simple)
|
## Update and set style of a particular node (simple)
|
||||||
Given a sample.yml file of:
|
Given a sample.yml file of:
|
||||||
@ -45,6 +47,12 @@ a: cat
|
|||||||
b: 5
|
b: 5
|
||||||
c: 3.2
|
c: 3.2
|
||||||
e: true
|
e: true
|
||||||
|
f:
|
||||||
|
- 1
|
||||||
|
- 2
|
||||||
|
- 3
|
||||||
|
g:
|
||||||
|
something: cool
|
||||||
```
|
```
|
||||||
then
|
then
|
||||||
```bash
|
```bash
|
||||||
@ -57,6 +65,12 @@ a: !!str cat
|
|||||||
b: !!int 5
|
b: !!int 5
|
||||||
c: !!float 3.2
|
c: !!float 3.2
|
||||||
e: !!bool true
|
e: !!bool true
|
||||||
|
f: !!seq
|
||||||
|
- !!int 1
|
||||||
|
- !!int 2
|
||||||
|
- !!int 3
|
||||||
|
g: !!map
|
||||||
|
something: !!str cool
|
||||||
```
|
```
|
||||||
|
|
||||||
## Set double quote style
|
## Set double quote style
|
||||||
@ -66,6 +80,12 @@ a: cat
|
|||||||
b: 5
|
b: 5
|
||||||
c: 3.2
|
c: 3.2
|
||||||
e: true
|
e: true
|
||||||
|
f:
|
||||||
|
- 1
|
||||||
|
- 2
|
||||||
|
- 3
|
||||||
|
g:
|
||||||
|
something: cool
|
||||||
```
|
```
|
||||||
then
|
then
|
||||||
```bash
|
```bash
|
||||||
@ -77,6 +97,12 @@ a: "cat"
|
|||||||
b: "5"
|
b: "5"
|
||||||
c: "3.2"
|
c: "3.2"
|
||||||
e: "true"
|
e: "true"
|
||||||
|
f:
|
||||||
|
- "1"
|
||||||
|
- "2"
|
||||||
|
- "3"
|
||||||
|
g:
|
||||||
|
something: "cool"
|
||||||
```
|
```
|
||||||
|
|
||||||
## Set double quote style on map keys too
|
## Set double quote style on map keys too
|
||||||
@ -86,6 +112,12 @@ a: cat
|
|||||||
b: 5
|
b: 5
|
||||||
c: 3.2
|
c: 3.2
|
||||||
e: true
|
e: true
|
||||||
|
f:
|
||||||
|
- 1
|
||||||
|
- 2
|
||||||
|
- 3
|
||||||
|
g:
|
||||||
|
something: cool
|
||||||
```
|
```
|
||||||
then
|
then
|
||||||
```bash
|
```bash
|
||||||
@ -97,6 +129,12 @@ will output
|
|||||||
"b": "5"
|
"b": "5"
|
||||||
"c": "3.2"
|
"c": "3.2"
|
||||||
"e": "true"
|
"e": "true"
|
||||||
|
"f":
|
||||||
|
- "1"
|
||||||
|
- "2"
|
||||||
|
- "3"
|
||||||
|
"g":
|
||||||
|
"something": "cool"
|
||||||
```
|
```
|
||||||
|
|
||||||
## Set single quote style
|
## Set single quote style
|
||||||
@ -106,6 +144,12 @@ a: cat
|
|||||||
b: 5
|
b: 5
|
||||||
c: 3.2
|
c: 3.2
|
||||||
e: true
|
e: true
|
||||||
|
f:
|
||||||
|
- 1
|
||||||
|
- 2
|
||||||
|
- 3
|
||||||
|
g:
|
||||||
|
something: cool
|
||||||
```
|
```
|
||||||
then
|
then
|
||||||
```bash
|
```bash
|
||||||
@ -117,6 +161,12 @@ a: 'cat'
|
|||||||
b: '5'
|
b: '5'
|
||||||
c: '3.2'
|
c: '3.2'
|
||||||
e: 'true'
|
e: 'true'
|
||||||
|
f:
|
||||||
|
- '1'
|
||||||
|
- '2'
|
||||||
|
- '3'
|
||||||
|
g:
|
||||||
|
something: 'cool'
|
||||||
```
|
```
|
||||||
|
|
||||||
## Set literal quote style
|
## Set literal quote style
|
||||||
@ -126,6 +176,12 @@ a: cat
|
|||||||
b: 5
|
b: 5
|
||||||
c: 3.2
|
c: 3.2
|
||||||
e: true
|
e: true
|
||||||
|
f:
|
||||||
|
- 1
|
||||||
|
- 2
|
||||||
|
- 3
|
||||||
|
g:
|
||||||
|
something: cool
|
||||||
```
|
```
|
||||||
then
|
then
|
||||||
```bash
|
```bash
|
||||||
@ -141,6 +197,16 @@ c: |-
|
|||||||
3.2
|
3.2
|
||||||
e: |-
|
e: |-
|
||||||
true
|
true
|
||||||
|
f:
|
||||||
|
- |-
|
||||||
|
1
|
||||||
|
- |-
|
||||||
|
2
|
||||||
|
- |-
|
||||||
|
3
|
||||||
|
g:
|
||||||
|
something: |-
|
||||||
|
cool
|
||||||
```
|
```
|
||||||
|
|
||||||
## Set folded quote style
|
## Set folded quote style
|
||||||
@ -150,6 +216,12 @@ a: cat
|
|||||||
b: 5
|
b: 5
|
||||||
c: 3.2
|
c: 3.2
|
||||||
e: true
|
e: true
|
||||||
|
f:
|
||||||
|
- 1
|
||||||
|
- 2
|
||||||
|
- 3
|
||||||
|
g:
|
||||||
|
something: cool
|
||||||
```
|
```
|
||||||
then
|
then
|
||||||
```bash
|
```bash
|
||||||
@ -165,6 +237,16 @@ c: >-
|
|||||||
3.2
|
3.2
|
||||||
e: >-
|
e: >-
|
||||||
true
|
true
|
||||||
|
f:
|
||||||
|
- >-
|
||||||
|
1
|
||||||
|
- >-
|
||||||
|
2
|
||||||
|
- >-
|
||||||
|
3
|
||||||
|
g:
|
||||||
|
something: >-
|
||||||
|
cool
|
||||||
```
|
```
|
||||||
|
|
||||||
## Set flow quote style
|
## Set flow quote style
|
||||||
@ -174,6 +256,12 @@ a: cat
|
|||||||
b: 5
|
b: 5
|
||||||
c: 3.2
|
c: 3.2
|
||||||
e: true
|
e: true
|
||||||
|
f:
|
||||||
|
- 1
|
||||||
|
- 2
|
||||||
|
- 3
|
||||||
|
g:
|
||||||
|
something: cool
|
||||||
```
|
```
|
||||||
then
|
then
|
||||||
```bash
|
```bash
|
||||||
@ -181,7 +269,7 @@ yq '.. style="flow"' sample.yml
|
|||||||
```
|
```
|
||||||
will output
|
will output
|
||||||
```yaml
|
```yaml
|
||||||
{a: cat, b: 5, c: 3.2, e: true}
|
{a: cat, b: 5, c: 3.2, e: true, f: [1, 2, 3], g: {something: cool}}
|
||||||
```
|
```
|
||||||
|
|
||||||
## Reset style - or pretty print
|
## Reset style - or pretty print
|
||||||
@ -189,10 +277,7 @@ Set empty (default) quote style, note the usage of `...` to match keys too. Note
|
|||||||
|
|
||||||
Given a sample.yml file of:
|
Given a sample.yml file of:
|
||||||
```yaml
|
```yaml
|
||||||
a: cat
|
{a: cat, "b": 5, 'c': 3.2, "e": true, f: [1,2,3], "g": { something: "cool"} }
|
||||||
"b": 5
|
|
||||||
'c': 3.2
|
|
||||||
"e": true
|
|
||||||
```
|
```
|
||||||
then
|
then
|
||||||
```bash
|
```bash
|
||||||
@ -204,6 +289,12 @@ a: cat
|
|||||||
b: 5
|
b: 5
|
||||||
c: 3.2
|
c: 3.2
|
||||||
e: true
|
e: true
|
||||||
|
f:
|
||||||
|
- 1
|
||||||
|
- 2
|
||||||
|
- 3
|
||||||
|
g:
|
||||||
|
something: cool
|
||||||
```
|
```
|
||||||
|
|
||||||
## Set style relatively with assign-update
|
## Set style relatively with assign-update
|
||||||
|
|||||||
@ -104,3 +104,19 @@ owner:
|
|||||||
suburb: nice
|
suburb: nice
|
||||||
```
|
```
|
||||||
|
|
||||||
|
## Parse: Empty Table
|
||||||
|
Given a sample.toml file of:
|
||||||
|
```toml
|
||||||
|
|
||||||
|
[dependencies]
|
||||||
|
|
||||||
|
```
|
||||||
|
then
|
||||||
|
```bash
|
||||||
|
yq -oy '.' sample.toml
|
||||||
|
```
|
||||||
|
will output
|
||||||
|
```yaml
|
||||||
|
dependencies: {}
|
||||||
|
```
|
||||||
|
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user