1
1
# shellcheck shell=bash
2
2
3
3
toml.quick_string_get () {
4
- REPLY=
4
+ unset REPLY ; REPLY=
5
5
local toml_file=" $1 "
6
6
local key_name=" $2 "
7
7
8
8
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
10
11
fi
11
12
12
13
local regex=$' ^[ \t ]*' ${key_name} $' [ \t ]*=[ \t ]*[\047 "](.*)[\047 \"]'
@@ -32,7 +33,8 @@ toml.quick_string_get() {
32
33
REPLY=" ${BASH_REMATCH[1]} "
33
34
else
34
35
# 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
36
38
fi
37
39
}
38
40
@@ -45,7 +47,7 @@ toml.quick_array_get() {
45
47
# ensure.nonzero 'key_name'
46
48
47
49
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"
49
51
return 2
50
52
fi
51
53
@@ -96,12 +98,12 @@ toml.quick_array_get() {
96
98
if [[ ${REPLIES[$i]} =~ $regex ]]; then
97
99
REPLIES[$i ]=" ${BASH_REMATCH[1]} "
98
100
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"
100
102
return 2
101
103
fi
102
104
done
103
105
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"
105
107
return 2
106
108
fi
107
109
}
@@ -114,15 +116,16 @@ toml.quick_array_append() {
114
116
# ensure.nonzero 'key_value'
115
117
116
118
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
118
121
fi
119
122
120
123
if util.get_toml_array " $toml_file " ' dependencies' ; then
121
124
local name=
122
125
for name in " ${REPLIES[@]} " ; do
123
126
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
126
129
fi
127
130
done ; unset name
128
131
@@ -136,7 +139,8 @@ toml.quick_array_append() {
136
139
rm " $toml_file .bak"
137
140
fi
138
141
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
140
144
fi
141
145
}
142
146
@@ -148,7 +152,8 @@ toml.quick_array_remove() {
148
152
# ensure.nonzero 'key_value'
149
153
150
154
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
152
157
fi
153
158
154
159
if util.get_toml_array " $toml_file " ' dependencies' ; then
@@ -161,11 +166,11 @@ toml.quick_array_remove() {
161
166
else
162
167
dependency_array+=(" $name " )
163
168
fi
164
- done ; unset name
169
+ done ; unset -v name
165
170
166
171
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
169
174
fi
170
175
171
176
mv " $toml_file " " $toml_file .bak"
@@ -185,6 +190,7 @@ toml.quick_array_remove() {
185
190
done < " $toml_file .bak" > " $toml_file "
186
191
rm " $toml_file .bak"
187
192
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
189
195
fi
190
196
}
0 commit comments