|
1 | 1 | #!/usr/bin/env bash |
2 | 2 | set -eo pipefail |
3 | 3 |
|
| 4 | +####################################################################### |
| 5 | +# Init arguments parser |
| 6 | +# Arguments: |
| 7 | +# script_dir - absolute path to hook dir location |
| 8 | +####################################################################### |
4 | 9 | function common::initialize { |
5 | 10 | local -r script_dir=$1 |
6 | 11 | # source getopt function |
7 | | - # shellcheck source=lib_getopt |
| 12 | + # shellcheck source=../lib_getopt |
8 | 13 | . "$script_dir/../lib_getopt" |
9 | 14 | } |
10 | 15 |
|
| 16 | +####################################################################### |
| 17 | +# Parse provided to script args and filenames and populate each to |
| 18 | +# appropriate Global |
| 19 | +# Globals (init and populate): |
| 20 | +# ARGS (array) arguments that configure wrapped tool behavior |
| 21 | +# HOOK_CONFIG (array) arguments that configure hook behavior |
| 22 | +# FILES (array) filenames to check |
| 23 | +# Arguments: |
| 24 | +# $@ (array) all specified in `hooks.[].args` in |
| 25 | +# `.pre-commit-config.yaml` and filenames. |
| 26 | +####################################################################### |
11 | 27 | function common::parse_cmdline { |
12 | 28 | # common global arrays. |
13 | 29 | # Populated via `common::parse_cmdline` and can be used inside hooks' functions |
@@ -39,6 +55,17 @@ function common::parse_cmdline { |
39 | 55 | done |
40 | 56 | } |
41 | 57 |
|
| 58 | +####################################################################### |
| 59 | +# Hook execution boilerplate logic that common for hooks, that run on |
| 60 | +# per dir basis. |
| 61 | +# 1. Because hook run on whole dir, reduce file paths to uniq dir paths |
| 62 | +# 2. Run for each dir `per_dir_hook_unique_part`, on all paths |
| 63 | +# 2.1. If at least 1 check failed - change exit code to non-zero |
| 64 | +# 3. Complete hook execution and return exit code |
| 65 | +# Arguments: |
| 66 | +# args (string with array) arguments that configure wrapped tool behavior |
| 67 | +# files (array) filenames to check |
| 68 | +####################################################################### |
42 | 69 | function common::per_dir_hook { |
43 | 70 | local -r args="$1" |
44 | 71 | shift 1 |
@@ -82,6 +109,16 @@ function common::per_dir_hook { |
82 | 109 | exit $final_exit_code |
83 | 110 | } |
84 | 111 |
|
| 112 | +####################################################################### |
| 113 | +# Colorify provided string and print out it to stdout |
| 114 | +# Environment variables: |
| 115 | +# PRE_COMMIT_COLOR (string) If set to `never` - do not colorify string |
| 116 | +# Arguments: |
| 117 | +# COLOR (string) Color name that will be used for colorify |
| 118 | +# TEXT (string) |
| 119 | +# Outputs: |
| 120 | +# Print out provided text to stdout |
| 121 | +####################################################################### |
85 | 122 | function common::colorify { |
86 | 123 | # shellcheck disable=SC2034 |
87 | 124 | local -r red="\e[0m\e[31m" |
|
0 commit comments