@@ -54,7 +54,62 @@ bash_object.util.generate_vobject_name() {
5454 random_string=" ${RANDOM} _${RANDOM} _${RANDOM} _${RANDOM} _${RANDOM} "
5555 fi
5656
57- printf -v REPLY ' %q' " __bash_object_${root_object_name} _${root_object_query} _${random_string} "
57+ printf -v REPLY ' %q' " __bash_object_${root_object_name} ___${root_object_query} _${random_string} "
58+ }
59+
60+ # @description Prints the contents of a particular variable
61+ # or vobject
62+ bash_object.util.print_hierarchy () {
63+ local object_name=" $1 "
64+ local current_indent=" $2 "
65+
66+ if object_type=" $( declare -p " $object_name " 2> /dev/null) " ; then : ; else
67+ bash_object.util.die ' ERROR_NOT_FOUND' " The variable '$object_name ' does not exist"
68+ return
69+ fi
70+ object_type=" ${object_type# declare -} "
71+
72+ local -n _object=" $object_name "
73+ if [ " ${object_type:: 1} " = ' A' ]; then
74+ for object_key in " ${! _object[@]} " ; do
75+ local object_value=" ${_object[$object_key]} "
76+ if [ " ${object_value:: 2} " = $' \x1C\x1D ' ]; then
77+ # object_value is a vobject
78+ bash_object.parse_virtual_object " $object_value "
79+ local virtual_object_name=" $REPLY1 "
80+ local vmd_dtype=" $REPLY2 "
81+
82+ printf ' %*s' " $current_indent " ' '
83+ printf ' %s\n' " |__ $object_key ($virtual_object_name )"
84+
85+ bash_object.util.print_hierarchy " $virtual_object_name " $(( current_indent+ 3 ))
86+ else
87+ # object_value is a string
88+ printf ' %*s' " $current_indent " ' '
89+ printf ' %s\n' " |__ $object_key "
90+ fi
91+ done ; unset object_key
92+ elif [ " ${object_type:: 1} " = ' a' ]; then
93+ for object_value in " ${_object[@]} " ; do
94+ # object_value is a vobject
95+ if [ " ${object_value:: 2} " = $' \x1C\x1D ' ]; then
96+ bash_object.parse_virtual_object " $object_value "
97+ local virtual_object_name=" $REPLY1 "
98+ local vmd_dtype=" $REPLY2 "
99+
100+ printf ' %*s' " $current_indent " ' '
101+ printf ' %s\n' " |- $object_value ($virtual_object_name )"
102+
103+ bash_object.util.print_hierarchy " $virtual_object_name " $(( current_indent+ 2 ))
104+ else
105+ printf ' %*s' " $current_indent " ' '
106+ printf ' %s\n' " |- $object_value "
107+ fi
108+ done
109+ else
110+ bash_object.util.die ' ERROR_ARGUMENTS_INVALID_TYPE' " The type of the named object ($object_name ) is neither an array nor an object"
111+ return
112+ fi
58113}
59114
60115# @description A stringified version of the querytree
0 commit comments