Giter VIP home page Giter VIP logo

yamlfmt's Introduction

yamlfmt

A simple opionated yaml formatter that keeps your comments!

yamlfmt is just a cli wrapper around the ruamel.yaml python library, which happens to have the unique quality of keeping comments.

Usage

Note: The formatting used is subject to change without notice. Once a format seems to stick v1.0 will be tagged and the format will not change.

❯ yamlfmt -h
usage: yamlfmt [-h] [-w] [-i INDENT] [file [file ...]]

positional arguments:
  file         file to parse

optional arguments:
  -h, --help   show this help message and exit
  -w, --write  write formatted outpout to (source) file instead of stdout
  -i, --indent set indent for formatted output

Examples

Lets see yamlfmt in action:

Simple example from ruamel.yaml docs

❯ yamlfmt <<EOF
# example
name:
  # details
  family: Smith   # very common
  given: Alice    # one of the siblings
EOF
# example
name:
  # details
  family: Smith   # very common
  given: Alice    # one of the siblings

Travis-CI nodejs example

❯ yamlfmt <<EOF
language: node_js

# test on two node.js versions: 0.6 and 0.8
node_js:
  - 0.6
  - 0.8

# configure notifications (email, IRC, campfire etc)
# please update this section to your needs!
notifications:
  irc: "irc.freenode.org#travis"
EOF
language: node_js

# test on two node.js versions: 0.6 and 0.8
node_js:
- 0.6
- 0.8

# configure notifications (email, IRC, campfire etc)
# please update this section to your needs!
notifications:
  irc: irc.freenode.org#travis

Complex example from ruamel.yaml docs

❯ yamlfmt <<EOF
- &CENTER {x: 1, y: 2}
- &LEFT {x: 0, y: 2}
- &BIG {r: 10}
- &SMALL {r: 1}
# All the following maps are equal:
# Explicit keys
- x: 1
  y: 2
  r: 10
  label: center/big
# Merge one map
- <<: *CENTER
  r: 10
  label: center/big
# Merge multiple maps
- <<: [*CENTER, *BIG]
  label: center/big
# Override
- <<: [*BIG, *LEFT, *SMALL]
  x: 1
  label: center/big
EOF
- &CENTER {x: 1, y: 2}
- &LEFT {x: 0, y: 2}
- &BIG {r: 10}
- &SMALL {r: 1}
# All the following maps are equal:
# Explicit keys
- x: 1
  y: 2
  r: 10
  label: center/big
# Merge one map
- <<: *CENTER
  r: 10
  label: center/big
# Merge multiple maps
- <<: [*CENTER, *BIG]
  label: center/big
# Override
- <<: [*BIG, *LEFT, *SMALL]
  x: 1
  label: center/big

yamlfmt's People

Contributors

avdn avatar mithun avatar mmlb avatar nikitabugrovsky avatar

Watchers

 avatar

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.