Skip to content

Commit 5cf0982

Browse files
author
Thomas G.
committed
fix: 🐛 end of lines and colors
1 parent ed13668 commit 5cf0982

3 files changed

Lines changed: 90 additions & 92 deletions

File tree

src/common-utils/_normalize-json.sh

Lines changed: 29 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ help
2020

2121
# Check if JSON exists and is readable
2222
if test -z "$json" && test ! -f "$json"; then
23-
echo -e "${Red}JSON is missing${End}"
23+
echo "${Red}JSON is missing${End}" >&2
2424
exit 1
2525
fi
2626

@@ -106,14 +106,14 @@ get_path() {
106106
gsub("\\["; ".") | gsub("\\]"; "") | split(".") | map(
107107
select(length > 0) | gsub("^\"|\"$";"") | if test("^[0-9]+$") then tonumber else . end
108108
);
109-
getpath($path | split_path)'
109+
getpath($path | split_path)' 2>/dev/null
110110
}
111111

112112
# Function to get remove comments from JSON.
113113
# Do not remove comments inside strings.
114114
load_json() {
115115
local file=${1:--}
116-
sed -e 's:^[[:blank:]]*//.*$::g' $file
116+
sed -e 's:^[[:blank:]]*//.*$::g' $file 2>/dev/null
117117
}
118118

119119
load_json_schema() {
@@ -165,7 +165,7 @@ get_schema_json() {
165165
curl -s $url | load_json_schema $url -
166166

167167
if [ $? -ne 0 ]; then
168-
echo -e "${Red}Unable to download schema file $schema${End}" >&2
168+
echo "${Red}Unable to download schema file $schema${End}" >&2
169169
exit 1
170170
fi
171171
}
@@ -190,7 +190,7 @@ get_schema() {
190190

191191
# if schema is not a valid JSON, return error
192192
if ! is_json <<<"$schema"; then
193-
echo -e "${Red}Invalid schema${End}" >&2
193+
echo "${Red}Invalid schema${End}" >&2
194194
exit 1
195195
fi
196196

@@ -255,7 +255,7 @@ validate() {
255255

256256
# if schema is not a valid JSON, return error
257257
if ! is_json <<<"$json"; then
258-
echo -e "${Red}Invalid json${End}" >&2
258+
echo "${Red}Invalid json${End}" >&2
259259
exit 1
260260
fi
261261

@@ -286,7 +286,7 @@ validate() {
286286
fi
287287

288288
# Log
289-
echo -e "${lvl}${Blue}Parsing schema <${path:-.}> == <${real:-.}>${None} at level <$level>\r" >&2
289+
echo -e "${lvl}${Blue}Parsing schema <${path:-.}> == <${real:-.}>${None} at level <$level>${End}" >&2
290290

291291
# get 1st level entry points (oneOf, allOf, anyOf, properties) and loop through them
292292
for entry in '"$id"' '"not"' '"oneOf"' '"allOf"' '"anyOf"' '"type"' '"required"' '"$ref"' '"properties"' '"items"' '"additionalProperties"'; do
@@ -296,7 +296,7 @@ validate() {
296296
continue
297297
fi
298298

299-
echo -e "${lvl}- Processing <${Blue}${path}:$entry${None}>\r" >&2
299+
echo -e "${lvl}- Processing <${Blue}${path}:$entry${None}>${End}" >&2
300300

301301
case $entry in
302302

@@ -318,32 +318,32 @@ validate() {
318318
local ref=$(get_path "$path.$entry" <<<"$schema")
319319

320320
if test "$ref" == "null" || test -z "$ref"; then
321-
echo -e "${Red}Reference not found for $path.$entry${End}" >&2
321+
echo "${Red}Reference not found for $path.$entry${End}" >&2
322322
exit 1
323323
fi
324324

325325
echo -e "${lvl}- Ref is ${Yellow}${ref}${End}" >&2
326-
echo -e "${lvl} From ${Yellow}${id}${None}...\r" >&2
326+
echo -e "${lvl} From ${Yellow}${id}${None}...${End}" >&2
327327

328328
# separate uri before # from fragment after #
329329
local uri=$(echo $ref | awk -F '#' '{print $1}')
330330
local fgt=$(echo $ref | awk -F '#' '{print $2}')
331331

332332
# if ref is a url, download it and use it as schema
333333
if test -n "$(echo $uri | grep -E '^http')"; then
334-
echo -e "${lvl}- Loading ${Yellow}${uri}${None}...\r" >&2
334+
echo -e "${lvl}- Loading ${Yellow}${uri}${None}...${End}" >&2
335335
schema=$(get_schema_json $uri)
336336
elif test -n "$uri"; then
337337
# check if file exists
338338
if test -f "$uri"; then
339-
echo -e "${lvl}- Loading ${Yellow}${uri}${None}...\r" >&2
339+
echo -e "${lvl}- Loading ${Yellow}${uri}${None}...${End}" >&2
340340
schema=$(load_json_schema $uri)
341341
elif test -n "$id"; then
342342
# load schema from file
343-
echo -e "${lvl}- Loading ${Yellow}$(dirname $id)/$uri${None}...\r" >&2
343+
echo -e "${lvl}- Loading ${Yellow}$(dirname $id)/$uri${None}...${End}" >&2
344344
schema=$(get_schema_json $(dirname $id)/$uri)
345345
else
346-
echo -e "${Red}Unable to resolve reference $ref with $id${End}" >&2
346+
echo "${Red}Unable to resolve reference $ref with $id${End}" >&2
347347
exit 1
348348
fi
349349

@@ -373,7 +373,7 @@ validate() {
373373
\"oneOf\" | \"allOf\" | \"anyOf\")
374374

375375
if ! is_json_array "$path.$entry" <<<"$schema"; then
376-
echo -e "${Red}Invalid $entry schema${End}" >&2
376+
echo "${Red}Invalid $entry schema${End}" >&2
377377
exit 1
378378
fi
379379

@@ -504,20 +504,20 @@ validate() {
504504
props=$(get_keys "$path.$entry" <<<"$schema" | tr "\n" " ")
505505

506506
# Log
507-
#echo -e "${lvl}- Properties are ${Purple}$props${End}" >&2
507+
#echo "${lvl}- Properties are ${Purple}$props${End}" >&2
508508

509509
# Loop through properties
510510
for prop in $props; do
511511

512-
#echo -e "${lvl}- Processing property ${Purple}$prop${End}" >&2
512+
#echo "${lvl}- Processing property ${Purple}$prop${End}" >&2
513513
if $not is_existing_path "$real.$prop" <<<"$json"; then
514514

515515
# Log
516-
echo -e "${lvl}- Processing <${Purple}$prop${None}>\r" >&2
516+
echo -e "${lvl}- Processing <${Purple}$prop${None}>${End}" >&2
517517

518518
# Parse sub schema
519519
if ! validate "$json" "$schema" "$path.$entry.$prop" "$real.$prop" "$path.$entry.$prop" "$not" "$level"; then
520-
echo -e "${Red}Property $prop is present but invalid${Red}" >&2
520+
echo "${Red}Property $prop is present but invalid${Red}" >&2
521521
return 1
522522
fi
523523
else
@@ -526,7 +526,7 @@ validate() {
526526
fi
527527
done
528528

529-
echo -e "${real:-.}"
529+
echo "${real:-.}"
530530
;;
531531

532532
\"additionalProperties\")
@@ -539,10 +539,10 @@ validate() {
539539
for prop in $(get_keys "$real" <<<"$json" | sort); do
540540

541541
if ! grep -q "$prop" <<<"$props"; then
542-
echo -e "${lvl}- Adding additional property <${Purple}$real.$prop${None}>\r" >&2
542+
echo -e "${lvl}- Adding additional property <${Purple}$real.$prop${None}>${End}" >&2
543543

544544
# Keep track of validated path
545-
echo -e "$real.$prop"
545+
echo "$real.$prop"
546546
fi
547547
done
548548
fi
@@ -564,7 +564,7 @@ if [ -n "$local" ]; then
564564
schema=$local/_$type.schema.json
565565

566566
# log
567-
echo -e "${Yellow}Infering schema from local folder for ${UYellow}$json${End}" >&2
567+
echo "${Yellow}Infering schema from local folder for ${UYellow}$json${End}" >&2
568568
fi
569569

570570
# Check if schema file exists, and if not and import allowed, download it from schema store
@@ -576,7 +576,7 @@ if [ -n "$import" ] && [ ! -f "$schema" ]; then
576576
schema=$(get_schema_url $search)
577577

578578
# log
579-
echo -e "${Yellow}Infering schema from schema store for ${UYellow}$search${Yellow} ${schema:+"found!"}${End}" >&2
579+
echo "${Yellow}Infering schema from schema store for ${UYellow}$search${Yellow} ${schema:+"found!"}${End}" >&2
580580
fi
581581

582582
# if schema file does not exist, use fallback schema
@@ -591,17 +591,17 @@ if [ -n "$fallback" ] && [ -z "$schema" ]; then
591591
elif [ -f "$fallback" ]; then
592592
schema=$fallback
593593
else
594-
echo -e "${Red}Fallback schema $fallback not found${End}" >&2
594+
echo "${Red}Fallback schema $fallback not found${End}" >&2
595595
exit 1
596596
fi
597597

598598
# log
599-
echo -e "${Yellow}Using fallback schema ${UYellow}$schema${End}" >&2
599+
echo "${Yellow}Using fallback schema ${UYellow}$schema${End}" >&2
600600
fi
601601

602602
# Check if schema is readable
603603
if test -z "$schema"; then
604-
echo -e "${Red}Schema is missing${End}" >&2
604+
echo "${Red}Schema is missing${End}" >&2
605605
exit 1
606606
fi
607607

@@ -611,9 +611,9 @@ schema=$(get_schema "$schema" "" "$allow")
611611
# Strip comments from JSON and go through normalization
612612
# if parse "$json" "$schema" >/dev/null; then ## Uncomment this line to enable debug output
613613
if validate "$json" "$schema"; then
614-
echo -e "${Green}JSON is valid and normalized${End}" >&2
614+
echo "${Green}JSON is valid and normalized${End}" >&2
615615
else
616-
echo -e "${Red}JSON is empty or invalid${End}" >&2
616+
echo "${Red}JSON is empty or invalid${End}" >&2
617617
exit 1
618618
fi >/tmp/$$.json
619619

src/common-utils/_zz_colors.sh

Lines changed: 58 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -1,73 +1,73 @@
11
# Reset
2-
export None='\033[0m' # Text Reset
3-
export End='\033[0m\n' # Text Reset
2+
export None='\033[0m' # Text Reset
3+
export End='\033[0m\r' # Text Reset
44

55
# Regular Colors
6-
export Black='\033[0;30m' # Black
7-
export Red='\033[0;31m' # Red
8-
export Green='\033[0;32m' # Green
9-
export Yellow='\033[0;33m' # Yellow
10-
export Blue='\033[0;34m' # Blue
11-
export Purple='\033[0;35m' # Purple
12-
export Cyan='\033[0;36m' # Cyan
13-
export White='\033[0;37m' # White
6+
export Black='\033[0;30m' # Black
7+
export Red='\033[0;31m' # Red
8+
export Green='\033[0;32m' # Green
9+
export Yellow='\033[0;33m' # Yellow
10+
export Blue='\033[0;34m' # Blue
11+
export Purple='\033[0;35m' # Purple
12+
export Cyan='\033[0;36m' # Cyan
13+
export White='\033[0;37m' # White
1414

1515
# Bold
16-
export BBlack='\033[1;30m' # Black
17-
export BRed='\033[1;31m' # Red
18-
export BGreen='\033[1;32m' # Green
19-
export BYellow='\033[1;33m' # Yellow
20-
export BBlue='\033[1;34m' # Blue
21-
export BPurple='\033[1;35m' # Purple
22-
export BCyan='\033[1;36m' # Cyan
23-
export BWhite='\033[1;37m' # White
16+
export BBlack='\033[1;30m' # Black
17+
export BRed='\033[1;31m' # Red
18+
export BGreen='\033[1;32m' # Green
19+
export BYellow='\033[1;33m' # Yellow
20+
export BBlue='\033[1;34m' # Blue
21+
export BPurple='\033[1;35m' # Purple
22+
export BCyan='\033[1;36m' # Cyan
23+
export BWhite='\033[1;37m' # White
2424

2525
# Underline
26-
export UBlack='\033[4;30m' # Black
27-
export URed='\033[4;31m' # Red
28-
export UGreen='\033[4;32m' # Green
29-
export UYellow='\033[4;33m' # Yellow
30-
export UBlue='\033[4;34m' # Blue
31-
export UPurple='\033[4;35m' # Purple
32-
export UCyan='\033[4;36m' # Cyan
33-
export UWhite='\033[4;37m' # White
26+
export UBlack='\033[4;30m' # Black
27+
export URed='\033[4;31m' # Red
28+
export UGreen='\033[4;32m' # Green
29+
export UYellow='\033[4;33m' # Yellow
30+
export UBlue='\033[4;34m' # Blue
31+
export UPurple='\033[4;35m' # Purple
32+
export UCyan='\033[4;36m' # Cyan
33+
export UWhite='\033[4;37m' # White
3434

3535
# Background
36-
export On_Black='\033[40m' # Black
37-
export On_Red='\033[41m' # Red
38-
export On_Green='\033[42m' # Green
39-
export On_Yellow='\033[43m' # Yellow
40-
export On_Blue='\033[44m' # Blue
41-
export On_Purple='\033[45m' # Purple
42-
export On_Cyan='\033[46m' # Cyan
43-
export On_White='\033[47m' # White
36+
export On_Black='\033[40m' # Black
37+
export On_Red='\033[41m' # Red
38+
export On_Green='\033[42m' # Green
39+
export On_Yellow='\033[43m' # Yellow
40+
export On_Blue='\033[44m' # Blue
41+
export On_Purple='\033[45m' # Purple
42+
export On_Cyan='\033[46m' # Cyan
43+
export On_White='\033[47m' # White
4444

4545
# High Intensity
46-
export IBlack='\033[0;90m' # Black
47-
export IRed='\033[0;91m' # Red
48-
export IGreen='\033[0;92m' # Green
49-
export IYellow='\033[0;93m' # Yellow
50-
export IBlue='\033[0;94m' # Blue
51-
export IPurple='\033[0;95m' # Purple
52-
export ICyan='\033[0;96m' # Cyan
53-
export IWhite='\033[0;97m' # White
46+
export IBlack='\033[0;90m' # Black
47+
export IRed='\033[0;91m' # Red
48+
export IGreen='\033[0;92m' # Green
49+
export IYellow='\033[0;93m' # Yellow
50+
export IBlue='\033[0;94m' # Blue
51+
export IPurple='\033[0;95m' # Purple
52+
export ICyan='\033[0;96m' # Cyan
53+
export IWhite='\033[0;97m' # White
5454

5555
# Bold High Intensity
56-
export BIBlack='\033[1;90m' # Black
57-
export BIRed='\033[1;91m' # Red
58-
export BIGreen='\033[1;92m' # Green
59-
export BIYellow='\033[1;93m' # Yellow
60-
export BIBlue='\033[1;94m' # Blue
61-
export BIPurple='\033[1;95m' # Purple
62-
export BICyan='\033[1;96m' # Cyan
63-
export BIWhite='\033[1;97m' # White
56+
export BIBlack='\033[1;90m' # Black
57+
export BIRed='\033[1;91m' # Red
58+
export BIGreen='\033[1;92m' # Green
59+
export BIYellow='\033[1;93m' # Yellow
60+
export BIBlue='\033[1;94m' # Blue
61+
export BIPurple='\033[1;95m' # Purple
62+
export BICyan='\033[1;96m' # Cyan
63+
export BIWhite='\033[1;97m' # White
6464

6565
# High Intensity backgrounds
66-
export On_IBlack='\033[0;100m' # Black
67-
export On_IRed='\033[0;101m' # Red
68-
export On_IGreen='\033[0;102m' # Green
69-
export On_IYellow='\033[0;103m' # Yellow
70-
export On_IBlue='\033[0;104m' # Blue
71-
export On_IPurple='\033[0;105m' # Purple
72-
export On_ICyan='\033[0;106m' # Cyan
73-
export On_IWhite='\033[0;107m' # White
66+
export On_IBlack='\033[0;100m' # Black
67+
export On_IRed='\033[0;101m' # Red
68+
export On_IGreen='\033[0;102m' # Green
69+
export On_IYellow='\033[0;103m' # Yellow
70+
export On_IBlue='\033[0;104m' # Blue
71+
export On_IPurple='\033[0;105m' # Purple
72+
export On_ICyan='\033[0;106m' # Cyan
73+
export On_IWhite='\033[0;107m' # White

src/common-utils/devcontainer-feature.json

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,12 @@
11
{
22
"name": "Common Utils",
3-
"version": "3.3.12",
3+
"version": "3.3.14",
44
"description": "Common utils for tomgrv/devcontainer-features",
55
"dependsOn": {
66
"ghcr.io/devcontainers/features/common-utils": {}
77
},
88
"id": "common-utils",
9-
"installsAfter": [
10-
"ghcr.io/devcontainers/features/common-utils"
11-
],
9+
"installsAfter": ["ghcr.io/devcontainers/features/common-utils"],
1210
"options": {
1311
"utils": {
1412
"type": "string",
@@ -51,4 +49,4 @@
5149
]
5250
}
5351
}
54-
}
52+
}

0 commit comments

Comments
 (0)