@@ -70,7 +70,7 @@ require_bin() {
70
70
local version
71
71
72
72
if ! command -v " $name " & > /dev/null; then
73
- echo " This script needs $name , but it isn't in \$ PATH"
73
+ echo " This script needs $name , but it isn't in \$ PATH" >&2
74
74
missing_bin=1
75
75
return
76
76
fi
@@ -79,14 +79,14 @@ require_bin() {
79
79
version=$( " $name " --version | grep -oP " \d+\.\d+\.?\d*" | head -n1)
80
80
81
81
if ! printf ' %s\n%s\n' " $min_version " " $version " | sort -V -C; then
82
- echo " $name version $version is too old. Version $min_version or newer is required."
82
+ echo " $name version $version is too old. Version $min_version or newer is required." >&2
83
83
missing_bin=1
84
84
return
85
85
fi
86
86
87
87
if [ -n " $max_version " ]; then
88
88
if ! printf ' %s\n%s\n' " $version " " $max_version " | sort -V -C; then
89
- echo " $name version $version is too new. Version less than $max_version is required."
89
+ echo " $name version $version is too new. Version less than $max_version is required." >&2
90
90
missing_bin=1
91
91
return
92
92
fi
109
109
exit_code=0
110
110
111
111
cmake_formatting () {
112
- echo " Formatting CMake files..."
112
+ echo " Formatting CMake files..." >&2
113
113
114
114
readarray -t files < <( git ls-files ' *.cmake' ' CMakeLists.txt' ' **/CMakeLists.txt' )
115
115
@@ -127,21 +127,42 @@ cmake_formatting() {
127
127
fi
128
128
}
129
129
130
+ track_progress () {
131
+ # Don't output the progress bar if stderr isn't a terminal, just eat all the input
132
+ [ -t 2 ] || {
133
+ cat > /dev/null
134
+ return
135
+ }
136
+
137
+ local total=$1
138
+ local current=0
139
+
140
+ while IFS= read -r _; do
141
+ (( current++ )) || :
142
+ percent=$(( current * 100 / total))
143
+ printf ' \rProgress: [%-50s] %d%%' " $( printf ' #%.0s' $( seq 1 $(( percent / 2 )) ) ) " " $percent " >&2
144
+ done
145
+ echo >&2
146
+ }
147
+
130
148
cpp_formatting () {
131
- echo " Formatting cpp files..."
149
+ echo " Formatting cpp files..." >&2
132
150
133
151
readarray -t files < <( git ls-files ' *.cpp' ' *.hpp' ' *.c' ' *.h' ' :!external/**' )
134
152
153
+ # The progress reporting is a bit sneaky, we use `--verbose` with xargs which
154
+ # prints a line to stderr for each command, and we simply count these...
155
+
135
156
if [ " $check_only " -eq 1 ]; then
136
157
local tmpdir
137
158
tmpdir=$( mktemp -d)
138
159
trap ' rm -rf "$tmpdir"' EXIT
139
160
140
- printf ' %s\n' " ${files[@]} " | xargs -P " $( nproc) " -I{} bash -c "
161
+ printf ' %s\n' " ${files[@]} " | xargs --verbose - P " $( nproc) " -I{} bash -c "
141
162
mkdir -p \"\$ (dirname \" $tmpdir /{}\" )\"
142
- diff -u --color=always --label \" {}\" --label \" {}\" \" {}\" <(clang-format \" {}\" ) > \" $tmpdir /{}\"
163
+ diff -u --color=always --label \" {}\" --label \" {}\" \" {}\" <(clang-format \" {}\" ) > \" $tmpdir /{}\"
143
164
:
144
- "
165
+ " | & track_progress ${ # files[@]}
145
166
146
167
for file in " ${files[@]} " ; do
147
168
if [ -s " $tmpdir /$file " ]; then
@@ -150,12 +171,13 @@ cpp_formatting() {
150
171
fi
151
172
done
152
173
else
153
- printf ' %s\n' " ${files[@]} " | xargs -n1 -P " $( nproc) " clang-format -i
174
+ printf ' %s\n' " ${files[@]} " | xargs --verbose -n1 -P " $( nproc) " clang-format -i | &
175
+ track_progress ${# files[@]}
154
176
fi
155
177
}
156
178
157
179
yaml_json_formatting () {
158
- echo " Formatting yaml and json files..."
180
+ echo " Formatting yaml and json files..." >&2
159
181
160
182
readarray -t files < <( git ls-files " *.yaml" " *.yml" " *.json" ' :!external/**' )
161
183
@@ -170,12 +192,12 @@ yaml_json_formatting() {
170
192
fi
171
193
done
172
194
else
173
- prettier --write " ${files[@]} " | grep -v ' (unchanged)' || :
195
+ prettier --write " ${files[@]} " | grep -v ' (unchanged)' >&2 || :
174
196
fi
175
197
}
176
198
177
199
sh_formatting () {
178
- echo " Formatting sh files..."
200
+ echo " Formatting sh files..." >&2
179
201
180
202
readarray -t files < <( git ls-files " *.sh" )
181
203
@@ -191,9 +213,9 @@ sh_formatting() {
191
213
fi
192
214
}
193
215
216
+ (( run_all || run_sh)) && sh_formatting
194
217
(( run_all || run_cmake)) && cmake_formatting
195
- (( run_all || run_cpp)) && cpp_formatting
196
218
(( run_all || run_yaml)) && yaml_json_formatting
197
- (( run_all || run_sh )) && sh_formatting
219
+ (( run_all || run_cpp )) && cpp_formatting
198
220
199
221
exit $exit_code
0 commit comments