File tree Expand file tree Collapse file tree 3 files changed +13
-14
lines changed Expand file tree Collapse file tree 3 files changed +13
-14
lines changed Original file line number Diff line number Diff line change 77# Assigns `printf` transformations of its arguments to an array
88#
99# @go.pad_items
10- # Pads each string in an array to match the length of the longest element
10+ # Right-pads each string with spaces to match the length of the longest
1111#
1212# @go.zip_items
1313# Concatenates parallel elements from each input array
4444 @go.split " $__go_array_printf_delim " " $__tmp_go_array_printf " " $1 "
4545}
4646
47- # Right-pads each string in an array to match the length of the longest element
47+ # Right-pads each string with spaces to match the length of the longest
4848#
4949# Globals:
5050# _GO_ARRAY_PRINTF_DELIMITER: See the comments for `@go.array_printf`
5151#
5252# Arguments:
53- # items: Name of the input array in the caller's scope
5453# result: Name of the caller-declared output array
54+ # ...: Items to right-pad with spaces to match the longest one
5555@go.pad_items () {
56- @go.validate_identifier_or_die ' Result array name' " $2 "
57- local items_reference= " ${1} [@] "
58- local item
56+ @go.validate_identifier_or_die ' Result array name' " $1 "
57+ local __go_pad_items_items=( " ${@: 2} " )
58+ local __item
5959 local padding_size=0
6060
61- for item in " ${! items_reference } " ; do
62- while [[ " $padding_size " -lt " ${# item } " ]]; do
63- padding_size=" ${# item } "
61+ for __item in " ${__go_pad_items_items[@] } " ; do
62+ while [[ " $padding_size " -lt " ${# __item } " ]]; do
63+ padding_size=" ${# __item } "
6464 done
6565 done
66- @go.array_printf " $2 " " %-${padding_size} s" " ${! items_reference } "
66+ @go.array_printf " $1 " " %-${padding_size} s" " ${__go_pad_items_items[@] } "
6767}
6868
6969# Concatenates parallel elements from each input array
Original file line number Diff line number Diff line change @@ -154,7 +154,7 @@ _@go.modules_produce_listing() {
154154 local padded_modules=()
155155 local zipped_modules=()
156156
157- @go.pad_items modules padded_modules
157+ @go.pad_items padded_modules " ${modules[@]} "
158158 modules=(" ${padded_modules[@]} " )
159159
160160 case " $action " in
Original file line number Diff line number Diff line change @@ -25,9 +25,8 @@ run_array_printf_script() {
2525
2626run_pad_items_script () {
2727 create_go_format_script \
28- ' declare items=("$@")' \
2928 ' declare padded=()' \
30- ' @go.pad_items items padded' \
29+ ' @go.pad_items padded "$@" ' \
3130 ' IFS="|"' \
3231 ' printf "%s\n" "${padded[*]}"'
3332 run " $TEST_GO_SCRIPT " " $@ "
@@ -80,7 +79,7 @@ run_strip_formatting_codes_script() {
8079
8180@test " $SUITE : pad_items validates result array name" {
8281 create_test_go_script ' . "$_GO_USE_MODULES" format' \
83- ' @go.pad_items items "3foobar"'
82+ ' @go.pad_items "3foobar"'
8483 run " $TEST_GO_SCRIPT "
8584
8685 local err_msg=' Result array name "3foobar" for @go.pad_items '
You can’t perform that action at this time.
0 commit comments