Control the way lists/arrays are displayed #1085
-
|
I have a script to update a YAML config of a program I wrote. Given the following snippet (the config is slightly larger): pull_requests:
enabled: true
auth:
personal_access_token: XYZ
select: []When I run the yq -i e '.pull_requests.select += {"repo": "felipesere/dotfiles",}' config.yml
yq -i e '.pull_requests.select += {"repo": "felipesere/journal",}' config.ymlThen the output I get is: pull_requests:
enabled: true
auth:
personal_access_token: XYZ
select: [{repo: felipesere/dotfiles}, {repo: felipesere/journal}]This is fine and my program handles it perfectly well. pull_requests:
enabled: true
auth:
personal_access_token: XYZ
select:
- repo: felipesere/dotfiles
- repo: felipesere/journalIs there a flag I can set to get this output? |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 1 reply
-
|
Yep - you can use the style operator. yq e -i 'with(.pull_requests.select;
. style= "" |
. += {"repo": "felipesere/dotfiles"} |
. += {"repo": "felipesere/journal"}
)' config.ymlpull_requests:
enabled: true
auth:
personal_access_token: XYZ
select:
- repo: felipesere/dotfiles
- repo: felipesere/journal
For what it's worth - I think I will change this in future versions to assume the default |
Beta Was this translation helpful? Give feedback.
Yep - you can use the style operator.
For what it's worth -
yqdefaults to the current style of the nodes - and for empty arrays/objects this is necessarily the JSON style (as there's no way of specifying an empty list in bullet points).I think I will change this in future versions to assume the default
yamlstyle for empty arrays and objects.