reformat-yaml

command
v2.0.4 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Sep 25, 2020 License: Apache-2.0 Imports: 5 Imported by: 0

README

reformat-yaml

This directory contains the go code to reformat a single Spin Cycle v1.0 YAML request spec in compliance with Spin Cycle v2.0.

Building and running

To build the executable, run go build reformat.go (in this directory). The executable will be named reformat.

usage: reformat [input file path] [output file path]

run.sh is an example bash script that finds all request specs (files that end with extension .yaml) in the Spin Cycle repo and reformats them. Note that reformat cannot write to the same file it is reformatting, i.e. the input and output file paths cannot be the same. Thus, run.sh writes the reformatted file to a temporary file, then copies that file to the appropriate location.

Why is reformatting necessary?

See the release notes.

  • In cases where a job does not set any args, i.e. sets: [], the reformatter does nothing; this line passes through the reformatter as is.

  • This line:

    sets: [arg1, arg2, arg3] # comment
    

    becomes:

    sets: # comment
      - arg: arg1
      - arg: arg2
      - arg: arg3
    
  • These lines:

    sets: # comment
      - arg1
      - arg2 #comment2
      - arg3
    

    become:

    sets: # comment
      - arg: arg1
      - arg: arg2 #comment2
      - arg: arg3
    

As noted in the above examples, the reformatter preserves comments.

The reformatter infers the indent size from the sets: line.

Possible errors while reformatting

  • The reformatter expects any line containing a sets: definition to be have four (equal) indents, and will throw an error if this is not the case.

    • Four spaces before the sets: statement is valid.
    • Eight spaces before the sets: statement is valid.
    • Ten spaces before the sets: statement will throw an error.
    • Three spaces and a tab before the sets: statement will throw an error. (You also shouldn't be using tabs in a YAML file.)
  • If using sets: [...] notation, a closing bracket must be provided. Otherwise, the reformatter throws an error. (This is illegal YAML anyway.)

Limitations, and what the reformatter isn't

The reformatter will always recognize # as the start of a comment. (This only matters for sets: blocks.) So, sets: "string#" will parse incorrectly.

Similarly, "sets:" will always be considered the start of a sets: block. So, blah: "sets:" will parse incorrectly.

Note that the reformatter does not check syntax for any other part of the YAML file; any line not part of a sets block will pass through as is.

Documentation

The Go Gopher

There is no documentation for this package.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL