Scroll to navigation

yamltidy(3) User Contributed Perl Documentation yamltidy(3)

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

    % cat in.yaml
    ---
    a:
        b:
            c: d
    % yamltidy in.yaml
    ---
    a:
      b:
        c: d
    
    % echo '---
    a:
        b:
            c: d' | yamltidy -
    ---
    a:
      b:
        c: d
    
    % yamltidy --inplace in.yaml
    % cat in.yaml
    ---
    a:
      b:
        c: d
    
    # 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.

    % yamltidy -c /path/to/yamltidy.yaml file.yaml
    
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)

SUBCOMMANDS

2024-02-02 perl v5.38.2