2016-09-27 20:01:11 +02:00
|
|
|
#!/usr/bin/env bash
|
2021-10-14 17:20:25 +01:00
|
|
|
set -eo pipefail
|
2016-09-27 20:01:11 +02:00
|
|
|
|
2022-02-10 16:53:37 +01:00
|
|
|
# globals variables
|
2022-01-06 17:09:51 +02:00
|
|
|
# shellcheck disable=SC2155 # No way to assign to readonly variable in separate lines
|
2022-04-18 19:17:15 +03:00
|
|
|
readonly SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd -P)"
|
2022-01-06 17:09:51 +02:00
|
|
|
# shellcheck source=_common.sh
|
|
|
|
|
. "$SCRIPT_DIR/_common.sh"
|
|
|
|
|
|
2022-01-06 13:21:52 +02:00
|
|
|
function main {
|
2022-01-06 17:09:51 +02:00
|
|
|
common::initialize "$SCRIPT_DIR"
|
2022-01-06 13:21:52 +02:00
|
|
|
common::parse_cmdline "$@"
|
2022-07-06 15:41:28 +03:00
|
|
|
common::export_provided_env_vars "${ENV_VARS[@]}"
|
2022-04-26 13:33:58 +03:00
|
|
|
common::parse_and_export_env_vars
|
2022-07-06 15:34:13 +03:00
|
|
|
|
2024-01-17 00:44:43 +01:00
|
|
|
# Suppress tofu fmt color
|
2022-07-06 15:34:13 +03:00
|
|
|
if [ "$PRE_COMMIT_COLOR" = "never" ]; then
|
|
|
|
|
ARGS+=("-no-color")
|
|
|
|
|
fi
|
|
|
|
|
|
2022-01-06 17:09:51 +02:00
|
|
|
# shellcheck disable=SC2153 # False positive
|
2022-10-06 19:16:29 +03:00
|
|
|
common::per_dir_hook "$HOOK_ID" "${#ARGS[@]}" "${ARGS[@]}" "${FILES[@]}"
|
2021-10-14 17:20:25 +01:00
|
|
|
}
|
|
|
|
|
|
2022-01-11 15:54:42 +02:00
|
|
|
#######################################################################
|
|
|
|
|
# Unique part of `common::per_dir_hook`. The function is executed in loop
|
|
|
|
|
# on each provided dir path. Run wrapped tool with specified arguments
|
|
|
|
|
# Arguments:
|
|
|
|
|
# dir_path (string) PATH to dir relative to git repo root.
|
|
|
|
|
# Can be used in error logging
|
2023-05-08 11:32:06 -04:00
|
|
|
# change_dir_in_unique_part (string/false) Modifier which creates
|
|
|
|
|
# possibilities to use non-common chdir strategies.
|
|
|
|
|
# Availability depends on hook.
|
2022-10-06 19:16:29 +03:00
|
|
|
# args (array) arguments that configure wrapped tool behavior
|
2022-01-11 15:54:42 +02:00
|
|
|
# Outputs:
|
|
|
|
|
# If failed - print out hook checks status
|
|
|
|
|
#######################################################################
|
2022-01-06 13:21:52 +02:00
|
|
|
function per_dir_hook_unique_part {
|
2022-05-25 16:37:55 +03:00
|
|
|
# shellcheck disable=SC2034 # Unused var.
|
2022-10-06 19:16:29 +03:00
|
|
|
local -r dir_path="$1"
|
2023-05-08 11:32:06 -04:00
|
|
|
# shellcheck disable=SC2034 # Unused var.
|
|
|
|
|
local -r change_dir_in_unique_part="$2"
|
|
|
|
|
shift 2
|
2022-10-06 19:16:29 +03:00
|
|
|
local -a -r args=("$@")
|
2022-01-06 13:21:52 +02:00
|
|
|
|
|
|
|
|
# pass the arguments to hook
|
2024-01-17 00:44:43 +01:00
|
|
|
tofu fmt "${args[@]}"
|
2022-01-06 13:21:52 +02:00
|
|
|
|
|
|
|
|
# return exit code to common::per_dir_hook
|
|
|
|
|
local exit_code=$?
|
|
|
|
|
return $exit_code
|
|
|
|
|
}
|
2021-10-14 17:20:25 +01:00
|
|
|
|
2022-01-06 13:21:52 +02:00
|
|
|
[ "${BASH_SOURCE[0]}" != "$0" ] || main "$@"
|