Created
October 5, 2016 21:02
-
-
Save raek/be9a1d9d095ce2462d8df36729ce768b to your computer and use it in GitHub Desktop.
YAML reformatting
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# to install yaml: | |
# sudo pip install pyyaml | |
import argparse | |
import yaml | |
import sys | |
parser = argparse.ArgumentParser(description="normalize YAML formatting") | |
parser.add_argument("--mode", help="how to pretty-print innermost nodes", | |
choices=["flow", "block"], required=True) | |
parser.add_argument("input", help="input YAML (or JSON) file") | |
parser.add_argument("output", help="output YAML file") | |
args = parser.parse_args() | |
use_flow = args.mode == "flow" | |
with open(args.input, "r") as f: | |
data = yaml.load(f) | |
with open(args.output, "w") as f: | |
yaml.dump(data, f, default_flow_style=use_flow) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment