Skip to content

Commit

Permalink
Preserve multiline strings (#12)
Browse files Browse the repository at this point in the history
  • Loading branch information
giograno authored Nov 20, 2024
1 parent ea09503 commit 8fb67ff
Showing 1 changed file with 14 additions and 0 deletions.
14 changes: 14 additions & 0 deletions bin/update-aws-spec.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,20 @@

import click


def str_presenter(dumper, data):
"""
Reading multiline yaml strings (with the `|` indicator) results in newlines added when dumping the YAML.
This function helps to preserve the original multiline formatting.
"""
if '\n' in data:
return dumper.represent_scalar('tag:yaml.org,2002:str', data, style='|')
return dumper.represent_scalar('tag:yaml.org,2002:str', data)


yaml.add_representer(str, str_presenter)


@click.command()
@click.option('--latest', is_flag=True, default=False, help='If enabled, sets the version of the spec to latest.')
def update_aws_spec(latest: bool) -> None:
Expand Down

0 comments on commit 8fb67ff

Please sign in to comment.