Skip to content

Commit f5c43d5

Browse files
committed
refactor: Move generating stack string to function
1 parent c48d5bc commit f5c43d5

File tree

3 files changed

+16
-13
lines changed

3 files changed

+16
-13
lines changed

pkg/lib/traverse-get.sh

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -48,12 +48,6 @@ bash_object.traverse-get() {
4848
local key="${REPLIES[$i]}"
4949
filter_stack+=("$key")
5050

51-
# TODO: redo filter_stack string, and use stdlib.arrayprint TODO
52-
local oldIFS="$IFS"
53-
IFS='_'
54-
local filter_stack_string="${filter_stack[*]}"
55-
IFS="$oldIFS"
56-
5751
bash_object.trace_loop
5852

5953
local is_index_of_array='no'
@@ -64,7 +58,7 @@ bash_object.traverse-get() {
6458

6559
# If 'key' is not a member of object or index of array, error
6660
if [ -z "${current_object["$key"]+x}" ]; then
67-
bash_object.util.die 'ERROR_VALUE_NOT_FOUND' "Key or index '$key' is not in '$filter_stack_string'"
61+
bash_object.util.die 'ERROR_VALUE_NOT_FOUND' "Key or index '$key' (filter index '$i') does not exist"
6862
return
6963
# If 'key' is a member of an object or index of array
7064
else

pkg/lib/traverse-set.sh

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -122,19 +122,16 @@ bash_object.traverse-set() {
122122
for ((i=0; i<${#REPLIES[@]}; i++)); do
123123
local key="${REPLIES[$i]}"
124124
filter_stack+=("$key")
125-
126-
local oldIFS="$IFS"
127-
IFS='_'
128-
local filter_stack_string="${filter_stack[*]}"
129-
IFS="$oldIFS"
125+
bash_object.util.generate_filter_stack_string
126+
local filter_stack_string="$REPLY"
130127

131128
bash_object.trace_loop
132129

133130
# If 'key' is not a member of object or index of array, error
134131
if [ -z "${current_object["$key"]+x}" ]; then
135132
# If we are before the last element in the query, then error
136133
if ((i+1 < ${#REPLIES[@]})); then
137-
bash_object.util.die 'ERROR_VALUE_NOT_FOUND' "Key or index '$key' is not in '$filter_stack_string'"
134+
bash_object.util.die 'ERROR_VALUE_NOT_FOUND' "Key or index '$key' (filter index '$i') does not exist"
138135
return
139136
# If we are at the last element in the query
140137
elif ((i+1 == ${#REPLIES[@]})); then

pkg/lib/util/util.sh

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,18 @@ bash_object.util.generate_vobject_name() {
5757
REPLY="__bash_object_${root_object_name}_${root_object_query}_${random_string}"
5858
}
5959

60+
# @description A stringified version of the filter
61+
# stack. This is used when generating objects to prevent
62+
# conflicts
63+
bash_object.util.generate_filter_stack_string() {
64+
unset REPLY
65+
66+
local oldIFS="$IFS"
67+
IFS='_'
68+
REPLY="${filter_stack[*]}"
69+
IFS="$oldIFS"
70+
}
71+
6072
# TODO
6173
stdtrace.log() {
6274
local level="$1"

0 commit comments

Comments
 (0)