File tree Expand file tree Collapse file tree 1 file changed +28
-8
lines changed Expand file tree Collapse file tree 1 file changed +28
-8
lines changed Original file line number Diff line number Diff line change @@ -7,22 +7,40 @@ set -euo pipefail
77IFS=$' \n\t '
88
99# ---- args & checks ----
10- [ $# -ge 1 ] || { echo " Usage: $0 <version> [dir]" >&2 ; exit 1; }
10+ if [ $# -lt 1 ]; then
11+ echo " Usage: $0 <version> [dir]" >&2
12+ exit 1
13+ fi
14+
1115V=" $1 "
1216DIR=" ${2:- definitions} "
1317
14- command -v jq > /dev/null 2>&1 || { echo " jq is required" >&2 ; exit 1; }
15- [[ " $V " =~ ^[0-9]+ (\. [0-9]+)* $ ]] || { echo " Invalid version: $V " >&2 ; exit 1; }
16- [ -d " $DIR " ] || { echo " Folder not found: $DIR " >&2 ; exit 1; }
18+ if ! command -v jq > /dev/null 2>&1 ; then
19+ echo " jq is required" >&2
20+ exit 1
21+ fi
22+
23+ if [[ ! " $V " =~ ^[0-9]+ (\. [0-9]+)* $ ]]; then
24+ echo " Invalid version: $V " >&2
25+ exit 1
26+ fi
27+
28+ if [ ! -d " $DIR " ]; then
29+ echo " Folder not found: $DIR " >&2
30+ exit 1
31+ fi
1732
1833# ---- process ----
1934updated=0
2035skipped=0
36+
37+ # Disable exit-on-error inside loop so non-critical skips don’t abort the script
38+ set +e
2139while IFS= read -r -d ' ' f; do
2240 # Validate JSON first
2341 if ! jq -e . " $f " > /dev/null 2>&1 ; then
2442 echo " INVALID JSON (skipped): $f " >&2
25- (( skipped++ ))
43+ (( skipped+= 1 )) || true
2644 continue
2745 fi
2846
@@ -33,16 +51,18 @@ while IFS= read -r -d '' f; do
3351 if jq --arg v " $V " ' .version=$v' " $f " > " $tmp " ; then
3452 mv -f " $tmp " " $f "
3553 echo " updated: $f "
36- (( updated++ ))
54+ (( updated+= 1 )) || true
3755 else
3856 echo " ERROR processing: $f " >&2
3957 rm -f " $tmp "
40- (( skipped++ ))
58+ (( skipped+= 1 )) || true
4159 fi
4260 else
4361 echo " skipped (non-object): $f "
44- (( skipped++ ))
62+ (( skipped+= 1 )) || true
4563 fi
4664done < <( find " $DIR " -type f -name ' *.json' -print0)
65+ set -e
4766
4867echo " Done. Updated: $updated Skipped: $skipped "
68+ exit 0
You can’t perform that action at this time.
0 commit comments