Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[WiP] Add options to manipulate style #148

Merged
merged 2 commits into from
Oct 23, 2024

Conversation

gabriel-samfira
Copy link
Member

@gabriel-samfira gabriel-samfira commented Oct 23, 2024

Two new options were added:

  • UseFlowStyle - Will output the entire yaml using Flow style instead of block
  • UseSequenceFlowStyle - Will output only sequences using the Flow style

Example:

PS /> $TestYaml = 'networkMapping: {"test_net_1": {"external": true}, "test_net_2": {"external": true}, "test_net_3": {"external": true}, "aNull": null}'
PS /> $x = ConvertFrom-Yaml $TestYaml                                                                                                                    
PS /> ConvertTo-Yaml -Options UseFlowStyle $x
{networkMapping: {test_net_1: {external: true}, test_net_2: {external: true}, aNull: "", test_net_3: {external: true}}}

# Chain more options like OmitNullValues if needed
PS /> ConvertTo-Yaml -Options UseFlowStyle,OmitNullValues $x
{networkMapping: {test_net_1: {external: true}, test_net_2: {external: true}, test_net_3: {external: true}}}

To only output sequences as Flow:

PS /> $testYaml = 'testing: {"aMapping": "test", "aSequence":[1,2,3,4]}'
PS /> $x = ConvertFrom-Yaml $TestYaml                                   
PS /> ConvertTo-Yaml -Options UseSequenceFlowStyle $x
testing:
  aSequence: [1, 2, 3, 4]
  aMapping: test

Fixes: #147

This option allows the output of sequences and mapping using the
Flow style instead of the Block style.

Signed-off-by: Gabriel Adrian Samfira <[email protected]>
This option uses the Flow style only for sequences.

Signed-off-by: Gabriel Adrian Samfira <[email protected]>
@gabriel-samfira gabriel-samfira changed the title [WiP] Add a new UseFlowStyle option [WiP] Add options to manipulate style Oct 23, 2024
@gabriel-samfira
Copy link
Member Author

CC @RokeJulianLockhart

@gabriel-samfira gabriel-samfira merged commit 2333d5e into cloudbase:master Oct 23, 2024
7 checks passed
@gabriel-samfira gabriel-samfira deleted the add-flow-style branch October 23, 2024 13:42
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add a flag to output a single line in ConvertTo-YAML.
1 participant