@@ -14,6 +14,40 @@ set -euo pipefail
14
14
OLD_IFS=" ${IFS} "
15
15
IFS=$' \n '
16
16
17
+ function error() {
18
+ local message
19
+ message=" $* "
20
+
21
+ if [[ " ${GITHUB_ACTIONS:= false} " == ' true' ]]
22
+ then
23
+ # Echoing to GitHub.
24
+ echo " ::error::${message} "
25
+ elif [[ -t 1 ]]
26
+ then
27
+ # Echoing to a terminal.
28
+ echo -e " \e[1m$( basename " $0 " ) : \e[31merror:\e[0m ${message} " >&2
29
+ else
30
+ # Echoing to a pipe.
31
+ echo " $( basename " $0 " ) : error: ${message} " >&2
32
+ fi
33
+ }
34
+
35
+ # Exit codes.
36
+ # The code of 1 is returned by ktlint in the event of failure.
37
+ declare -ir ERROR_JAVA_NOT_FOUND=2
38
+ declare -ir ERROR_DOWNLOAD_FAILURE=3
39
+ declare -ir ERROR_UNSUPPORTED_FLAG=4
40
+ declare -ir ERROR_DIKTAT_JAR_NOT_FOUND=5
41
+ declare -ir ERROR_OPTION_REQUIRES_ARGUMENT=6
42
+ declare -ir ERROR_NO_INPUT_FILES_FOUND=7
43
+ declare -ir ERROR_INCOMPATIBLE_BASH_VERSION=8
44
+
45
+ if (( BASH_VERSINFO[0 ] < 4 ))
46
+ then
47
+ error " bash version ${BASH_VERSION} is too old, version 4+ is required"
48
+ exit ${ERROR_INCOMPATIBLE_BASH_VERSION}
49
+ fi
50
+
17
51
# Default flag values.
18
52
declare -i COLOR=0
19
53
declare -i DEBUG=0
@@ -57,15 +91,6 @@ declare -r OPTION_REPORTER_LONG='--reporter'
57
91
declare -r OPTION_OUTPUT_SHORT=' -o'
58
92
declare -r OPTION_OUTPUT_LONG=' --output'
59
93
60
- # Exit codes.
61
- # The code of 1 is returned by ktlint in the event of failure.
62
- declare -ir ERROR_JAVA_NOT_FOUND=2
63
- declare -ir ERROR_DOWNLOAD_FAILURE=3
64
- declare -ir ERROR_UNSUPPORTED_FLAG=4
65
- declare -ir ERROR_DIKTAT_JAR_NOT_FOUND=5
66
- declare -ir ERROR_OPTION_REQUIRES_ARGUMENT=6
67
- declare -ir ERROR_NO_INPUT_FILES_FOUND=7
68
-
69
94
# Error messages.
70
95
declare -r MESSAGE_UNSUPPORTED_FLAG=' unsupported flag'
71
96
declare -r MESSAGE_OPTION_REQUIRES_ARGUMENT=' option requires an argument'
@@ -126,24 +151,6 @@ THE SOFTWARE.
126
151
EOF
127
152
}
128
153
129
- function error() {
130
- local message
131
- message=" $* "
132
-
133
- if [[ " ${GITHUB_ACTIONS:= false} " == ' true' ]]
134
- then
135
- # Echoing to GitHub.
136
- echo " ::error::${message} "
137
- elif [[ -t 1 ]]
138
- then
139
- # Echoing to a terminal.
140
- echo -e " \e[1m$( basename " $0 " ) : \e[31merror:\e[0m ${message} " >&2
141
- else
142
- # Echoing to a pipe.
143
- echo " $( basename " $0 " ) : error: ${message} " >&2
144
- fi
145
- }
146
-
147
154
# Locates Java, preferring JAVA_HOME.
148
155
#
149
156
# The 1st variable expansion prevents the "unbound variable" error if JAVA_HOME
0 commit comments