Skip to content

Commit a2be26d

Browse files
committed
misc: Cleanup
1 parent fc8c244 commit a2be26d

File tree

2 files changed

+15
-11
lines changed

2 files changed

+15
-11
lines changed

pkg/lib/traverse-set.sh

+14-10
Original file line numberDiff line numberDiff line change
@@ -121,11 +121,11 @@ bash_object.traverse-set() {
121121
return
122122
fi
123123
shift
124-
temp_var=("$@")
125-
final_value="$temp_var_name"
126-
elif [ "$final_value_type" == string ]; then
127-
local temp_var_name="__bash_object_${RANDOM}_$RANDOM"
128-
local -n temp_var="$temp_var_name"
124+
125+
final_value_ref=("$@")
126+
elif [ "$final_value_type" = string ]; then
127+
local final_value="__bash_object_${RANDOM}_$RANDOM"
128+
local -n final_value_ref="$final_value"
129129
if [ "$1" != -- ]; then
130130
bash_object.util.die 'ERROR_ARGUMENTS_INVALID' "Must pass '--' and the value when using --value"
131131
return
@@ -136,8 +136,7 @@ bash_object.traverse-set() {
136136
bash_object.util.die 'ERROR_ARGUMENTS_INVALID' "When passing --value with set-string, only one value must be passed after the '--'"
137137
return
138138
fi
139-
temp_var="$1"
140-
final_value="$temp_var_name"
139+
final_value_ref="$1"
141140
else
142141
bash_object.util.die 'ERROR_ARGUMENTS_INVALID' "Unexpected final_value_type '$final_value_type'"
143142
return
@@ -147,6 +146,11 @@ bash_object.traverse-set() {
147146
return
148147
fi
149148

149+
if [ -z "$final_value" ]; then
150+
bash_object.util.die 'ERROR_INTERNAL' "Variable 'final_value' is empty"
151+
return
152+
fi
153+
150154
if [ -n "${VERIFY_BASH_OBJECT+x}" ]; then
151155
# Ensure the root object exists, and is an associative array
152156
local root_object_type=
@@ -175,17 +179,17 @@ bash_object.traverse-set() {
175179
*) actual_final_value_type='other' ;;
176180
esac
177181

178-
if [ "$final_value_type" == object ]; then
182+
if [ "$final_value_type" = object ]; then
179183
if [ "$actual_final_value_type" != object ]; then
180184
bash_object.util.die 'ERROR_ARGUMENTS_INVALID_TYPE' "Argument 'set-$final_value_type' was specified, but a variable with type '$actual_final_value_type' was passed"
181185
return
182186
fi
183-
elif [ "$final_value_type" == array ]; then
187+
elif [ "$final_value_type" = array ]; then
184188
if [ "$actual_final_value_type" != array ]; then
185189
bash_object.util.die 'ERROR_ARGUMENTS_INVALID_TYPE' "Argument 'set-$final_value_type' was specified, but a variable with type '$actual_final_value_type' was passed"
186190
return
187191
fi
188-
elif [ "$final_value_type" == string ]; then
192+
elif [ "$final_value_type" = string ]; then
189193
if [ "$actual_final_value_type" != string ]; then
190194
bash_object.util.die 'ERROR_ARGUMENTS_INVALID_TYPE' "Argument 'set-$final_value_type' was specified, but a variable with type '$actual_final_value_type' was passed"
191195
return

tests/set-value.bats

+1-1
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ load './util/init.sh'
1919
bobject set-array --value 'OBJECT' '.uwu' -- one two three
2020

2121
bobject get-array --value 'OBJECT' '.uwu'
22-
assert [ "${#REPLY[@]}" -eq 3 ]
22+
assert [ ${#REPLY[@]} -eq 3 ]
2323
assert [ "${REPLY[0]}" = one ]
2424
assert [ "${REPLY[1]}" = two ]
2525
assert [ "${REPLY[2]}" = three ]

0 commit comments

Comments
 (0)