-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcheck-shell-all.sh
executable file
·80 lines (68 loc) · 1.93 KB
/
check-shell-all.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
#!/usr/bin/env bash
# shellcheck disable=SC1090,SC1091
set -u
set -e
DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" &>/dev/null && pwd)"
. "$DIR/../common/log.sh"
. "$DIR/../common/parallel.sh"
. "$DIR/../common/shell-check.sh"
dryRun="true"
dir=""
excludeRegex=""
regex=$(getGeneralShellFileRegex)
function help() {
printError "Usage:" \
" [--force] : Force the format." \
" [--exclude <regex> ] : Exclude file with this regex." \
" [--include <pattern>] : Regex pattern to include files." \
" --dir <path> : In which directory to check files."
}
function parseArgs() {
local prev=""
for p in "$@"; do
if [ "$p" = "--force" ]; then
dryRun="false"
elif [ "$p" = "--help" ]; then
help
return 1
elif [ "$p" = "--dir" ]; then
true
elif [ "$prev" = "--dir" ]; then
dir="$p"
elif [ "$p" = "--exclude" ]; then
true
elif [ "$prev" = "--exclude" ]; then
excludeRegex="$p"
elif [ "$p" = "--include" ]; then
true
elif [ "$prev" = "--include" ]; then
regex="$p"
else
printError "! Unknown argument \`$p\`"
help
return 1
fi
prev="$p"
done
}
parseArgs "$@"
[ -d "$dir" ] || die "Directory '$dir' does not exist."
if [ "$dryRun" = "false" ]; then
assertShellCheckVersion "0.8.0" "0.10.0"
printInfo "Formatting shell files in dir '$dir'."
else
printInfo "Dry-run formatting shell files in dir '$dir'."
fi
# Format with no config -> search directory tree upwards.
parallelForDir checkShellFile \
"$dir" \
"$regex" \
"$excludeRegex" \
"$dryRun" ||
die "Checking in '$dir' with '$regex'."
parallelForDir checkShellMistakesFile \
"$dir" \
"$regex" \
"$excludeRegex" \
"$dryRun" ||
die "Checking in '$dir' with '$regex'."