Skip to content

Commit a941557

Browse files
committed
fix: Do not use undefined functions
1 parent 85360d1 commit a941557

File tree

2 files changed

+25
-15
lines changed

2 files changed

+25
-15
lines changed

pkg/src/public/bash-toml-quick.sh

Lines changed: 21 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,13 @@
11
# shellcheck shell=bash
22

33
toml.quick_string_get() {
4-
REPLY=
4+
unset REPLY; REPLY=
55
local toml_file="$1"
66
local key_name="$2"
77

88
if [ ! -f "$toml_file" ]; then
9-
bprint.fatal "File '$toml_file' not found"
9+
bash_toml.error "File '$toml_file' not found"
10+
return 1
1011
fi
1112

1213
local regex=$'^[ \t]*'${key_name}$'[ \t]*=[ \t]*[\047"](.*)[\047\"]'
@@ -32,7 +33,8 @@ toml.quick_string_get() {
3233
REPLY="${BASH_REMATCH[1]}"
3334
else
3435
# This should not happen due to the '[[ $line == *"$key_name"*=* ]]' check above
35-
bprint.fatal "Could not find key '$key_name' in file '$toml_file'"
36+
bash_toml.error "Could not find key '$key_name' in file '$toml_file'"
37+
return 1
3638
fi
3739
}
3840

@@ -45,7 +47,7 @@ toml.quick_array_get() {
4547
# ensure.nonzero 'key_name'
4648

4749
if [ ! -f "$toml_file" ]; then
48-
printf '%s\n' "Error: File '$toml_file' does not exist" >&2
50+
bash_toml.error "File '$toml_file' does not exist"
4951
return 2
5052
fi
5153

@@ -96,12 +98,12 @@ toml.quick_array_get() {
9698
if [[ ${REPLIES[$i]} =~ $regex ]]; then
9799
REPLIES[$i]="${BASH_REMATCH[1]}"
98100
else
99-
printf '%s\n' "Error: Key '$key_name' in file '$toml_file' is not valid" >&2
101+
bash_toml.error "Key '$key_name' in file '$toml_file' is not valid"
100102
return 2
101103
fi
102104
done
103105
else
104-
printf '%s\n' "Error: Key '$key_name' in file '$toml_file' must be set to an array that spans one line" >&2
106+
bash_toml.error "Key '$key_name' in file '$toml_file' must be set to an array that spans one line"
105107
return 2
106108
fi
107109
}
@@ -114,15 +116,16 @@ toml.quick_array_append() {
114116
# ensure.nonzero 'key_value'
115117

116118
if [ ! -f "$toml_file" ]; then
117-
bprint.fatal "File '$toml_file' does not exist"
119+
bash_toml.error "File '$toml_file' does not exist"
120+
return 2
118121
fi
119122

120123
if util.get_toml_array "$toml_file" 'dependencies'; then
121124
local name=
122125
for name in "${REPLIES[@]}"; do
123126
if [ "${name%@*}" = "${key_value%@*}" ]; then
124-
bprint.warn "A version of '${name%@*}' is already installed. Skipping"
125-
return
127+
bash_toml.error "A version of '${name%@*}' is already installed. Skipping"
128+
return 2
126129
fi
127130
done; unset name
128131

@@ -136,7 +139,8 @@ toml.quick_array_append() {
136139
rm "$toml_file.bak"
137140
fi
138141
else
139-
bprint.die "Key 'dependencies' not found in file '$toml_file'"
142+
bash_toml.error "Key 'dependencies' not found in file '$toml_file'"
143+
return 2
140144
fi
141145
}
142146

@@ -148,7 +152,8 @@ toml.quick_array_remove() {
148152
# ensure.nonzero 'key_value'
149153

150154
if [ ! -f "$toml_file" ]; then
151-
bprint.fatal "File '$toml_file' does not exist"
155+
bash_toml.error "File '$toml_file' does not exist"
156+
return 2
152157
fi
153158

154159
if util.get_toml_array "$toml_file" 'dependencies'; then
@@ -161,11 +166,11 @@ toml.quick_array_remove() {
161166
else
162167
dependency_array+=("$name")
163168
fi
164-
done; unset name
169+
done; unset -v name
165170

166171
if [ "$does_exist" != 'yes' ]; then
167-
bprint.die "The package '$key_value' is not currently a dependency"
168-
return
172+
bash_toml.error "The package '$key_value' is not currently a dependency"
173+
return 2
169174
fi
170175

171176
mv "$toml_file" "$toml_file.bak"
@@ -185,6 +190,7 @@ toml.quick_array_remove() {
185190
done < "$toml_file.bak" > "$toml_file"
186191
rm "$toml_file.bak"
187192
else
188-
bprint.die "Key 'dependencies' not found in file '$toml_file'"
193+
bash_toml.error "Key 'dependencies' not found in file '$toml_file'"
194+
return 2
189195
fi
190196
}

pkg/src/util/util.sh

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,3 +61,7 @@ bash_toml.parse_fail() {
6161
exit 1
6262
fi
6363
}
64+
65+
bash_toml.error() {
66+
printf '%s\n' "Error: $1" >&2
67+
}

0 commit comments

Comments
 (0)