chore: Document functions (based on google style guide) (#317)

This commit is contained in:
Maksym Vlasov 2022-01-11 15:54:42 +02:00 committed by GitHub
commit 321fb16693
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
11 changed files with 190 additions and 8 deletions

View file

@ -15,6 +15,19 @@ function main {
terraform_validate_
}
#######################################################################
# Parse args and filenames passed to script and populate respective
# global variables with appropriate values
# Globals (init and populate):
# ARGS (array) arguments that configure wrapped tool behavior
# INIT_ARGS (array) arguments to `terraform init` command
# ENVS (array) environment variables that will be used with
# `terraform` commands
# FILES (array) filenames to check
# Arguments:
# $@ (array) all specified in `hooks.[].args` in
# `.pre-commit-config.yaml` and filenames.
#######################################################################
function parse_cmdline_ {
declare argv
argv=$(getopt -o e:i:a: --long envs:,init-args:,args: -- "$@") || return
@ -46,6 +59,24 @@ function parse_cmdline_ {
done
}
#######################################################################
# Wrapper around `terraform validate` tool that checks if code is valid
# 1. Export provided env var K/V pairs to environment
# 2. Because hook runs on whole dir, reduce file paths to uniq dir paths
# 3. In each dir that have *.tf files:
# 3.1. Check if `.terraform` dir exists and if not - run `terraform init`
# 3.2. Run `terraform validate`
# 3.3. If at least 1 check failed - change exit code to non-zero
# 4. Complete hook execution and return exit code
# Globals:
# ARGS (array) arguments that configure wrapped tool behavior
# INIT_ARGS (array) arguments for `terraform init` command`
# ENVS (array) environment variables that will be used with
# `terraform` commands
# FILES (array) filenames to check
# Outputs:
# If failed - print out hook checks status
#######################################################################
function terraform_validate_ {
# Setup environment variables