git.iko.soy/typeable/compaREST
on master help sign in
35 lines 576 B history raw
1#!/usr/bin/env bash
2set -e
4# Normalise YAML files passed as inputs, then run diff on them.
6check_util() {
7 local util=$1
9 if [ -z $util ]; then
10 echo "Error: $util not found in PATH"
11 exit 1
12 fi
15DIFF=`which diff`
16check_util $DIFF
18YQ=`which yq`
19check_util $YQ
21# Only normalise YAML files.
22# Print anything else as is.
23normalise() {
24 local file=$1
25 local contents=($YQ -y -S '.' $file)
27 # if $contents contains actual YAML data, print it
28 if [[ $? == 0 ]]; then
29 echo $contents
30 else
31 cat $file
32 fi
35$DIFF -u <(normalise $1) <(normalise $2)