chore: Refactor all hooks (#310)

This commit is contained in:
Maksym Vlasov 2022-01-06 13:21:52 +02:00 committed by GitHub
commit 1f16f09c6f
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
10 changed files with 675 additions and 340 deletions

View file

@ -8,15 +8,14 @@ function main {
}
function common::colorify {
# Colors. Provided as first string to first arg of function.
# shellcheck disable=SC2034
local -r red="$(tput setaf 1)"
local -r red="\e[0m\e[31m"
# shellcheck disable=SC2034
local -r green="$(tput setaf 2)"
local -r green="\e[0m\e[32m"
# shellcheck disable=SC2034
local -r yellow="$(tput setaf 3)"
local -r yellow="\e[0m\e[33m"
# Color reset
local -r RESET="$(tput sgr0)"
local -r RESET="\e[0m"
# Params start #
local COLOR="${!1}"
@ -40,12 +39,11 @@ function common::initialize {
. "$SCRIPT_DIR/lib_getopt"
}
# common global arrays.
# Populated in `parse_cmdline` and can used in hooks functions
declare -a ARGS=()
declare -a HOOK_CONFIG=()
declare -a FILES=()
function common::parse_cmdline {
# common global arrays.
# Populated via `common::parse_cmdline` and can be used inside hooks' functions
declare -g -a ARGS=() FILES=() HOOK_CONFIG=()
local argv
argv=$(getopt -o a:,h: --long args:,hook-config: -- "$@") || return
eval "set -- $argv"
@ -180,4 +178,4 @@ function infracost_breakdown_ {
fi
}
[[ ${BASH_SOURCE[0]} != "$0" ]] || main "$@"
[ "${BASH_SOURCE[0]}" != "$0" ] || main "$@"