#!/bin/bash
#for i in $( cat 000TopLevel.yaml | tr ' ' '\n' | grep .yaml ); do
#  
#end
#
#
expandYaml () {
  for i in $( cat $1 |grep -hv ^[[:space:]]*# | tr ' ' '\n' | grep yaml | sed 's/^M$//'); do
    echo $i
    expandYaml $i
    #arr=("${arr[@]}" "$i")
#    cat $i >> expanded.yaml
  done
#  cat $1 >> expanded.yaml
  arr=("${arr[@]}" "$1")
  return 0
}

declare -a arr
rm -f merge.yaml

expandYaml 000TopLevel.yaml
#make sort for unique elements, don't change order
arr=($(echo ${arr[@]} | tr [:space:] '\n' | awk '!a[$0]++'))
for i in ${arr[@]}; do
  echo $i
  cat $i >> merge.yaml
done
python expand_yaml.py
