-
Notifications
You must be signed in to change notification settings - Fork 159
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
terraform-fmt updates files, optionally skipped via flags #53
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,11 +7,43 @@ set -e | |
# workaround to allow GitHub Desktop to work, add this (hopefully harmless) setting here. | ||
export PATH=$PATH:/usr/local/bin | ||
|
||
write_changes=true | ||
FILES=() | ||
|
||
parse_arguments() { | ||
while (($# > 0)); do | ||
# Grab param and value splitting on " " or "=" with parameter expansion | ||
local PARAMETER="${1%[ =]*}" | ||
local VALUE="${1#*[ =]}" | ||
if [[ "$PARAMETER" == "$VALUE" ]]; then VALUE="$2"; fi | ||
shift | ||
case "$PARAMETER" in | ||
--no-autofix) | ||
write_changes=false | ||
;; | ||
-*) | ||
echo "Error: Unknown option: $PARAMETER" >&2 | ||
exit 1 | ||
;; | ||
*) | ||
FILES+=("$PARAMETER") | ||
;; | ||
esac | ||
done | ||
} | ||
|
||
parse_arguments "$@" | ||
|
||
# Store and return last failure from fmt so this can validate every directory passed before exiting | ||
FMT_ERROR=0 | ||
|
||
for file in "$@"; do | ||
terraform fmt -diff -check "$file" || FMT_ERROR=$? | ||
for file in "$FILES"; do | ||
file=$(dirname "$file") | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is required to be able to run the hook outside the repo folder. For example, |
||
if [ "$write_changes" = true ]; then | ||
terraform fmt "$file" || FMT_ERROR=$? | ||
else | ||
terraform fmt -diff -check "$file" || FMT_ERROR=$? | ||
fi | ||
done | ||
|
||
exit ${FMT_ERROR} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Inspired on
shellcheck.sh
's version:pre-commit/hooks/shellcheck.sh
Line 13 in e9250bd