| gio | c916187 | 2024-04-21 10:46:35 +0400 | [diff] [blame] | 1 | #!/bin/bash |
| 2 | |
| 3 | # Outputs the generated helm configurations after templating. |
| 4 | |
| 5 | yaml_output=/tmp/op-hc-yaml-output.txt |
| 6 | error_output=/tmp/op-hc-error-output.txt |
| 7 | section_output=/tmp/op-hc-section-output.yml |
| 8 | vimrc=/tmp/op-hc-vim-rc |
| 9 | |
| 10 | rm $yaml_output $error_output $section_output $vimrc &>/dev/null |
| 11 | |
| 12 | helm template --debug "$@" . 1> $yaml_output 2> $error_output |
| 13 | |
| 14 | if [ $? -gt 0 ]; then |
| 15 | section=`cat $error_output | grep 'Error: YAML parse error on' | cut -d: -f2 | cut -d' ' -f6-` |
| 16 | |
| 17 | if [ -n "$section" ]; then |
| 18 | cat $yaml_output | sed -e "0,/\# Source: ${section//\//\\/}/d" | tail -n+2 | sed -e '/---/,$d' > $section_output |
| 19 | |
| 20 | line=`cat $error_output | grep line | head -n1 | perl -nle 'm/line (\d+)/; print $1'` |
| 21 | |
| 22 | if [ -n "$line" ]; then |
| 23 | echo "autocmd VimEnter * echo '`cat $error_output | grep line | head -n1`'" > $vimrc |
| 24 | vim +$line -u $vimrc $section_output |
| 25 | else |
| 26 | echo |
| 27 | echo "Template error: " |
| 28 | echo |
| 29 | echo --- |
| 30 | cat $section_output |
| 31 | cat $error_output |
| 32 | fi |
| 33 | else |
| 34 | echo |
| 35 | echo "Template error: " |
| 36 | echo |
| 37 | echo --- |
| 38 | cat $yaml_output |
| 39 | cat $error_output |
| 40 | fi |
| 41 | else |
| 42 | cat $yaml_output |
| 43 | |
| 44 | echo |
| 45 | echo "Syntax ok" |
| 46 | fi |