Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/freebsd/poudriere.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBryan Drewery <bryan@shatow.net>2022-09-15 21:54:08 +0300
committerBryan Drewery <bryan@shatow.net>2022-11-05 18:47:57 +0300
commitb9afffe13ff5826cb77a9624b07ef4d7c7349c6d (patch)
treed0f785560d8b13cc934172498e3237102dcce6e9
parentffefb5706663204f56271bad77621022abfdd9cf (diff)
display: Support using column(1)
-rw-r--r--src/share/poudriere/include/display.sh28
-rw-r--r--test/display.sh69
2 files changed, 92 insertions, 5 deletions
diff --git a/src/share/poudriere/include/display.sh b/src/share/poudriere/include/display.sh
index ff17c5f3..2ad18631 100644
--- a/src/share/poudriere/include/display.sh
+++ b/src/share/poudriere/include/display.sh
@@ -28,6 +28,7 @@ EX_DATAERR=65
EX_SOFTWARE=70
DISPLAY_SEP=$'\002'
+DISPLAY_USE_COLUMN=0
DISPLAY_DYNAMIC_FORMAT_DEFAULT="%%-%ds"
DISPLAY_TRIM_TRAILING_FIELD=1
@@ -51,6 +52,13 @@ display_setup() {
unset IFS
}
+_display_cleanup() {
+ unset _DISPLAY_DATA _DISPLAY_FORMAT \
+ _DISPLAY_COLUMN_SORT \
+ _DISPLAY_LINES _DISPLAY_COLS \
+ _DISPLAY_FOOTER _DISPLAY_HEADER
+}
+
display_add() {
[ $# -gt 0 ] || eargs display_add col [col...]
local IFS
@@ -213,6 +221,20 @@ display_output() {
sort -t "${DISPLAY_SEP}" ${_DISPLAY_COLUMN_SORT})"
fi
+ if [ "${DISPLAY_USE_COLUMN}" -eq 1 ]; then
+ {
+ if [ "${quiet}" -eq 0 ]; then
+ echo "${_DISPLAY_HEADER}"
+ fi
+ echo "${_DISPLAY_DATA}"
+ if [ -n "${_DISPLAY_FOOTER}" ]; then
+ echo "${_DISPLAY_FOOTER}"
+ fi
+ } | column -t -s "${DISPLAY_SEP}"
+ _display_cleanup
+ return
+ fi
+
# Determine optimal format from filtered data
_display_check_lengths "${_DISPLAY_HEADER}"
_display_check_lengths "${_DISPLAY_FOOTER}"
@@ -292,9 +314,5 @@ display_output() {
unset IFS
printf "${format}\n" "$@"
fi
-
- unset _DISPLAY_DATA _DISPLAY_FORMAT \
- _DISPLAY_COLUMN_SORT \
- _DISPLAY_LINES _DISPLAY_COLS \
- _DISPLAY_FOOTER _DISPLAY_HEADER
+ _display_cleanup
}
diff --git a/test/display.sh b/test/display.sh
index 709ba03a..feafdedd 100644
--- a/test/display.sh
+++ b/test/display.sh
@@ -84,6 +84,75 @@ alias assert_file='_assert_file "$0:$LINENO"'
assert_file "${expected}" "${outfile}"
}
+{
+ # Basic test
+ old="${DISPLAY_USE_COLUMN}"
+ DISPLAY_USE_COLUMN=1
+ display_setup "%%-%ds %%-%ds" "-k2,2V -k1,1d"
+ display_add "Name" "Release"
+ display_add "blah" "11.2-RELEASE-p1"
+ display_add "blah" "10.0-RELEASE"
+ display_add "blah" "10.2-RELEASE"
+ display_add "blah" "10.2-RELEASE-p10"
+ display_add "blah2" "10.2-RELEASE-p1"
+ display_add "blah" "10.2-RELEASE-p1"
+ display_add "blah" "9.3-RELEASE-p10"
+ display_add "blah" "9.3-RELEASE-p1"
+ display_add "blah" "8.2-RELEASE-p1"
+ outfile=$(mktemp -t outfile)
+ display_output > "${outfile}"
+ expected=$(mktemp -t expected)
+ cat > "${expected}" <<-EOF
+ Name Release
+ blah 8.2-RELEASE-p1
+ blah 9.3-RELEASE-p1
+ blah 9.3-RELEASE-p10
+ blah 10.0-RELEASE
+ blah 10.2-RELEASE
+ blah 10.2-RELEASE-p1
+ blah2 10.2-RELEASE-p1
+ blah 10.2-RELEASE-p10
+ blah 11.2-RELEASE-p1
+ EOF
+ assert_file "${expected}" "${outfile}"
+ DISPLAY_USE_COLUMN="${old}"
+}
+
+{
+ # Basic test
+ old="${DISPLAY_USE_COLUMN}"
+ DISPLAY_USE_COLUMN=1
+ display_setup "%%-%ds %%-%ds" "-k2,2V -k1,1d"
+ display_add "Name" "Release"
+ display_add "blah" "11.2-RELEASE-p1"
+ display_add "blah" "10.0-RELEASE"
+ display_add "blah" "10.2-RELEASE"
+ display_add "blah" "10.2-RELEASE-p10"
+ display_add "blah2" "10.2-RELEASE-p1"
+ display_add "blah" "10.2-RELEASE-p1"
+ display_add "blah" "9.3-RELEASE-p10"
+ display_add "blah" "9.3-RELEASE-p1"
+ display_add "blah" "8.2-RELEASE-p1"
+ outfile=$(mktemp -t outfile)
+ display_output "Name" "Release" > "${outfile}"
+ expected=$(mktemp -t expected)
+ cat > "${expected}" <<-EOF
+ Name Release
+ blah 8.2-RELEASE-p1
+ blah 9.3-RELEASE-p1
+ blah 9.3-RELEASE-p10
+ blah 10.0-RELEASE
+ blah 10.2-RELEASE
+ blah 10.2-RELEASE-p1
+ blah2 10.2-RELEASE-p1
+ blah 10.2-RELEASE-p10
+ blah 11.2-RELEASE-p1
+ EOF
+ assert_file "${expected}" "${outfile}"
+ DISPLAY_USE_COLUMN="${old}"
+}
+
+{
# Basic test without trimming trailing field
old="${DISPLAY_TRIM_TRAILING_FIELD}"
DISPLAY_TRIM_TRAILING_FIELD=0