Skip to content

Commit

Permalink
Refactor/fixup terraform_tflint
Browse files Browse the repository at this point in the history
  • Loading branch information
robinbowes committed Jul 6, 2020
1 parent a7afaf6 commit 83bbdbf
Showing 1 changed file with 31 additions and 25 deletions.
56 changes: 31 additions & 25 deletions terraform_tflint.sh
Original file line number Diff line number Diff line change
@@ -1,31 +1,11 @@
#!/usr/bin/env bash

set -e

main() {
initialize_
declare argv
argv=$(getopt -o a: --long args: -- "$@") || return
eval "set -- $argv"

declare args
declare -a files

for argv; do
case $argv in
-a | --args)
shift
args="$1"
shift
;;
--)
shift
read -r -a files <<<"$@"
break
;;
esac
done

tflint_ "$args" "${files[@]}"
parse_cmdline_ "$@"
tflint_
}

initialize_() {
Expand All @@ -46,8 +26,30 @@ initialize_() {
. "$_SCRIPT_DIR/lib_getopt"
}

parse_cmdline_() {
declare argv
argv=$(getopt -o a: --long args: -- "$@") || return
eval "set -- $argv"

for argv; do
case $argv in
-a | --args)
shift
ARGS+=("$1")
shift
;;
--)
shift
FILES=("$@")
break
;;
esac
done
}

tflint_() {
for file_with_path in "${files[@]}"; do
local index=0
for file_with_path in "${FILES[@]}"; do
file_with_path="${file_with_path// /__REPLACED__SPACE__}"

paths[index]=$(dirname "$file_with_path")
Expand All @@ -59,9 +61,13 @@ tflint_() {
path_uniq="${path_uniq//__REPLACED__SPACE__/ }"

pushd "$path_uniq" > /dev/null
tflint "$args"
tflint "${ARGS[@]}"
popd > /dev/null
done
}

# global arrays
declare -a ARGS
declare -a FILES

[[ ${BASH_SOURCE[0]} != "$0" ]] || main "$@"

0 comments on commit 83bbdbf

Please sign in to comment.