-
Notifications
You must be signed in to change notification settings - Fork 0
/
format-configs-all.sh
executable file
·73 lines (61 loc) · 1.73 KB
/
format-configs-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
#!/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/configs-format.sh"
dryRun="true"
dir=""
excludeRegex=""
regex=$(getGeneralConfigsFileRegex)
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
assertConfigsFormatVersion "3.0.0" "4.0.0"
printInfo "Formatting in '$dir with '$regex'."
else
printInfo "Dry-run formatting in '$dir' with '$regex'."
fi
parallelForDir formatConfigsFile \
"$dir" \
"$regex" \
"$excludeRegex" \
"$dryRun" || die "Configs format failed."
exit 0