diff options
author | Bryan Drewery <bryan@shatow.net> | 2022-09-10 01:59:56 +0300 |
---|---|---|
committer | Bryan Drewery <bryan@shatow.net> | 2022-11-05 18:47:57 +0300 |
commit | 5db589c7476248b4e1ce5a3e595d2dea4a23055a (patch) | |
tree | 4c906f2c78fe8b82bf0f02e1b22c25cad9af09a5 | |
parent | 273e277f6a62b989ee89a460a76f6f9ecbffb074 (diff) |
display: Support a manual display_footer()
-rw-r--r-- | src/share/poudriere/include/display.sh | 27 | ||||
-rw-r--r-- | test/display.sh | 54 |
2 files changed, 80 insertions, 1 deletions
diff --git a/src/share/poudriere/include/display.sh b/src/share/poudriere/include/display.sh index 42bf09ab..d313dab0 100644 --- a/src/share/poudriere/include/display.sh +++ b/src/share/poudriere/include/display.sh @@ -29,6 +29,7 @@ display_setup() { _DISPLAY_DATA= _DISPLAY_FORMAT="$1" _DISPLAY_COLUMN_SORT="${2-}" + _DISPLAY_FOOTER= } display_add() { @@ -52,6 +53,23 @@ display_add() { return 0 } +display_footer() { + local arg line tab + + unset line + tab=$'\t' + # Ensure blank arguments and spaced-arguments are respected. + for arg do + if [ -z "${arg}" ]; then + arg=" " + fi + line="${line:+${line}${tab}}${arg}" + done + # Add in newline + _DISPLAY_FOOTER="${line}" + return 0 +} + display_output() { local cnt lengths length format arg flag quiet line n local header header_format @@ -102,6 +120,7 @@ display_output() { done done <<-EOF ${_DISPLAY_DATA} + ${_DISPLAY_FOOTER} EOF # Set format lengths if format is dynamic width @@ -147,7 +166,13 @@ display_output() { unset IFS printf "${format}\n" "$@" done + if [ -n "${_DISPLAY_FOOTER}" ]; then + IFS=$'\t' + set -- ${_DISPLAY_FOOTER} + unset IFS + printf "${format}\n" "$@" + fi unset _DISPLAY_DATA _DISPLAY_FORMAT \ - _DISPLAY_COLUMN_SORT + _DISPLAY_COLUMN_SORT _DISPLAY_FOOTER } diff --git a/test/display.sh b/test/display.sh index db61bfe5..56256016 100644 --- a/test/display.sh +++ b/test/display.sh @@ -53,6 +53,60 @@ alias assert_file='_assert_file "$0:$LINENO"' } { + display_setup "%%-%ds %%%ds" "-k2,2V -k1,1d" + display_add "Name" "Memory" + display_add "foo" "10" + display_add "blah" "5" + display_footer "" "15 G" + outfile=$(mktemp -t outfile) + display_output > "${outfile}" + expected=$(mktemp -t expected) + cat > "${expected}" <<-EOF + Name Memory + blah 5 + foo 10 + 15 G + EOF + assert_file "${expected}" "${outfile}" +} + +{ + display_setup "%%-%ds %%-%ds" "-k2,2V -k1,1d" + display_add "Name" "Memory" + display_add "foo" "10" + display_add "blah" "5" + display_footer "" "15 G" + outfile=$(mktemp -t outfile) + display_output > "${outfile}" + expected=$(mktemp -t expected) + cat > "${expected}" <<-EOF + Name Memory + blah 5 + foo 10 + 15 G + EOF + assert_file "${expected}" "${outfile}" +} + +{ + display_setup "%%-%ds %%-%ds %%-%ds" "-k2,2V -k1,1d" + display_add "Name" "Mem" "Blah" + display_add "foo" "10" "0" + display_add "blah" "5" "0" + display_footer "" "15 GiB" "0" + outfile=$(mktemp -t outfile) + display_output > "${outfile}" + expected=$(mktemp -t expected) + cat > "${expected}" <<-EOF + Name Mem Blah + blah 5 0 + foo 10 0 + 15 GiB 0 + EOF + assert_file "${expected}" "${outfile}" +} + +{ display_setup "%%-%ds %%-%ds" "-k2,2V -k1,1d" display_add "Name" "Release" display_add "" "11.2-RELEASE-p1" |