#!/bin/sh

if [ -f values.yaml ]; then
    VALUES="values.yaml"
elif [ -f values-chart.yaml ]; then
    VALUES="values-chart.yaml"
elif [ -f chart/values.yaml ]; then
    VALUES="chart/values.yaml"
else
    cat << EOF
[{
    "name": "helm-parameters",
    "title": "Helm Parameters",
    "collectionType": "map",
    "map": { "replicaCount": "1" }
}]
EOF
    exit 0
fi

yq e -o=p "${VALUES}" | jq --slurp --raw-input '
  [{
    name: "helm-parameters",
    title: "Helm Parameters",
    collectionType: "map",
    map: split("\n") | map(capture("(?<key>.*) = (?<value>.*)")) | from_entries
  }]'

