NAME
yamltidy - Reformat YAML files
ABSTRACT
DESCRIPTION
This script checks YAML files according to a configuration and automatically reformats them. It will output the formatted code on standard output, or edit the file directly.
EXAMPLES
- Tidy a file and print to stdout
-
% cat in.yaml --- a: b: c: d % yamltidy in.yaml --- a: b: c: d
- Tidy content from stdin
-
% echo '--- a: b: c: d' | yamltidy - --- a: b: c: d
- Tidy a file and save the result back
-
% yamltidy --inplace in.yaml % cat in.yaml --- a: b: c: d
- Process a list of files from stdin
-
# Tidy all .yaml files that are in git % git ls-files | grep '.yaml$' | yamltidy --inplace --batch - # short options % git ls-files | grep '.yaml$' | yamltidy -i -b - # Only tidy modified files % git ls-files --modified | grep '.yaml$' | yamltidy --inplace --batch -
In the future yamltidy can take a directory as an argument and process file name patterns from configuration.
- Use a certain configuration file
-
% yamltidy -c /path/to/yamltidy.yaml file.yaml
- Partial formatting
-
From within an editor you can pass only a part of the file on stdin. This is important for keeping the indentation of that part. Also it won't add a
---
header. Compare:% echo ' a: b: c' | yamltidy - --- a: b: c % echo ' a: b: c' | yamltidy --partial - a: b: c
Vim example configuration:
# :noremap <leader>yt :%!yamltidy -<CR> # :vnoremap <leader>yt :!yamltidy --partial -<CR>
GLOBAL OPTIONS
--config-file -c Config file
--config-data -d Configuration as a string
--inplace -i Edit file inplace (flag)
--debug Debugging output (flag)
--partial Input is only a part of a YAML file (flag)
--indent Override indentation spaces from config
--batch -b Tidy all files - currently requires parameter "-" for filenames passed via STDIN (flag)
--verbose Output information (flag)
--help -h print usage message and exit (flag)
--version Print version information (flag)