Code Monkey home page Code Monkey logo

yaml-sort's Introduction

Node.js CI npm version

About

yaml-sort sorts YAML files alphabetically.

This tool is basically a tiny wrapper around js-yaml.

(Inspired by yml-sorter)

Installation

npm install -g yaml-sort

Usage

Usage: yaml-sort [options]

Options:
  -i, --input         The YAML file(s) which needs to be sorted  [array] [default: "-"]
  -o, --output        The YAML file to output sorted content to  [string]
  -s, --stdout        Output the proposed sort to STDOUT only  [boolean]
  -k, --check         Check if the given file(s) is already sorted  [boolean]
      --indent, --id  Indentation width to use (in spaces)  [number] [default: 2]
  -e, --encoding      Input encoding  [choices: "ascii", "utf8", "utf16le"] [default: "utf8"]
  -q, --quotingStyle  Strings will be quoted using this quoting style  [choices: "single", "double"] [default: "single"]
  -w, --lineWidth     Wrap line width (-1 for unlimited width)  [number] [default: 80]
  -h, --help          Show help  [boolean]
      --version       Show version number  [boolean]

Examples:
  yaml-sort --input config.yml                                 Sorts alphabetically and overwrites the file config.yml
  yaml-sort --input config.yml --lineWidth 100 --stdout        Sorts the file config.yml and output result to STDOUT wrapped to 100 columns
  yaml-sort --input config.yml --indent 4 --output sorted.yml  Indents with 4 spaces and outputs result to file sorted.yml
  cat config.yml | yaml-sort                                   Sorts alphabetically from STDIN

yaml-sort's People

Contributors

ddebin avatar dependabot[bot] avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

yaml-sort's Issues

support stdin

due to NodeJS lacking support for process substitution in some environments, sending data directly to yaml-sort via something like yaml-sort -i <(echo "test:stuff") -s is not always currently possible (and does not work for me in Windows). Adding support to read from stdin would make this much more useful in scripts, allowing it to be used in pipelines, e.g. cat original.yaml | yq ".paths./customers.get.parameters" | grep -v "^\s*x-position" | yaml-sort to return a sorted list of parameters for an endpoint in an OpenAPI file after removing NSwag's x-position extension property.

Bug when sorting yaml with double quotes

Description

Sometimes when I use the yaml-sort command with pre-commit it messes up two lines that are double-quoted.

In the screen below you can see a composition of the yaml file I have.
image

The k8s-name-input key has a value that starts and ends with double quotes but also includes single quotes in the middle.

When I edit the value of the hide key from Hide read-only fields to e.g. Hide all fields and then use git add and git commit... commands, the value of the k8s-name-input messes up to:

image

As you can see, the the k8s-name-input value is single-quoted and includes more single-quotes inside.

It happens from time to time, there are situations when it doesn't break the k8s-name-input.

The yaml-sort command I use:
yaml-sort --lineWidth=-1 -i

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.