commit:     18e702eb8d32695dc503fc272d23e21cad7a6b12
Author:     Kerin Millar <kfm <AT> plushkava <DOT> net>
AuthorDate: Sat May 18 16:03:46 2024 +0000
Commit:     Sam James <sam <AT> gentoo <DOT> org>
CommitDate: Sat May 18 16:06:45 2024 +0000
URL:        
https://gitweb.gentoo.org/proj/gentoo-functions.git/commit/?id=18e702eb

Separate some edo() code into a _print_args() helper function

Further, make test-functions use _print_args() and jettison the inferior
print_args() function that it was previously using.

Signed-off-by: Kerin Millar <kfm <AT> plushkava.net>
Signed-off-by: Sam James <sam <AT> gentoo.org>

 functions.sh   | 33 +++++++++++++++++++--------------
 test-functions | 18 +++++++++---------
 2 files changed, 28 insertions(+), 23 deletions(-)

diff --git a/functions.sh b/functions.sh
index db3314a..462db97 100644
--- a/functions.sh
+++ b/functions.sh
@@ -93,20 +93,7 @@ ebegin()
 # be made to exit by calling the die function.
 #
 edo() {
-       # Approximate the effect of ${param@Q} bash expansion.
-       genfun_cmd=$(
-               awk -v q=\' -f - -- "$@" <<-'EOF'
-                       BEGIN {
-                               argc = ARGC
-                               ARGC = 1
-                               for (i = 1; i < argc; i++) {
-                                       arg = ARGV[i]
-                                       gsub(q, q "\\" q q, arg)
-                                       printf("'%s' ", arg)
-                               }
-                       }
-               EOF
-       )
+       genfun_cmd=$(_print_args "$@")
        einfo "${genfun_cmd% }"
        "$@" || die "Failed to run command: ${genfun_cmd% }"
 }
@@ -539,6 +526,24 @@ _is_visible()
        ! case $1 in *[[:graph:]]*) false ;; esac
 }
 
+#
+# Prints the positional parameters in a manner that approximates the behaviour
+# of the ${*@Q} expansion in bash.
+#
+_print_args() {
+       awk -v q=\' -f - -- "$@" <<-'EOF'
+               BEGIN {
+                       argc = ARGC
+                       ARGC = 1
+                       for (i = 1; i < argc; i++) {
+                               arg = ARGV[i]
+                               gsub(q, q "\\" q q, arg)
+                               printf("'%s' ", arg)
+                       }
+               }
+       EOF
+}
+
 #
 # Determines whether the terminal on STDIN is able to report its dimensions.
 # Upon success, the number of columns shall be stored in genfun_cols.

diff --git a/test-functions b/test-functions
index 0c0bb45..24a7527 100755
--- a/test-functions
+++ b/test-functions
@@ -41,7 +41,7 @@ test_chdir() {
 
        callback() {
                shift
-               test_description="chdir $(print_args "$@")"
+               test_description="chdir $(_print_args "$@")"
                if [ "$BASH" ]; then
                        # shellcheck disable=3044
                        shopt -s cdable_vars
@@ -60,7 +60,7 @@ test_chdir_noop() {
 
        callback() {
                shift
-               test_description="chdir $(print_args "$@")"
+               test_description="chdir $(_print_args "$@")"
                chdir "$@" \
                && test "$PWD" = "$OLDPWD" \
                || { cd - >/dev/null; false; }
@@ -195,7 +195,7 @@ test_is_older_than() {
 
        callback() {
                shift
-               test_description="is_older_than $(print_args "$@")"
+               test_description="is_older_than $(_print_args "$@")"
                is_older_than "$@"
        }
 
@@ -221,7 +221,7 @@ test_get_bootparam() {
        callback() {
                cmdline=$2
                shift 2
-               test_description="get_bootparam $(print_args "$@")"
+               test_description="get_bootparam $(_print_args "$@")"
                printf '%s\n' "${cmdline}" | get_bootparam "$@"
        }
 
@@ -246,7 +246,7 @@ test_esyslog() {
                should_log=$2
                shift 2
                logged=0
-               test_description="esyslog $(print_args "$@")"
+               test_description="esyslog $(_print_args "$@")"
                EINFO_LOG=1 esyslog "$@" 2>/dev/null
                case $? in
                        0)
@@ -308,7 +308,7 @@ test_is_identifier() {
 
                callback() {
                        shift
-                       test_description="is_identifier $(print_args "$@")"
+                       test_description="is_identifier $(_print_args "$@")"
                        is_identifier "$@"
                }
 
@@ -333,7 +333,7 @@ test_is_int() {
 
                callback() {
                        shift
-                       test_description="is_int $(print_args "$@")"
+                       test_description="is_int $(_print_args "$@")"
                        is_int "$@"
                }
 
@@ -353,7 +353,7 @@ test_is_visible() {
 
                callback() {
                        shift
-                       test_description="_is_visible $(print_args "$@")"
+                       test_description="_is_visible $(_print_args "$@")"
                        _is_visible "$@"
                }
 
@@ -392,7 +392,7 @@ test_yesno() {
 
                callback() {
                        shift
-                       test_description="yesno $(print_args "$@")"
+                       test_description="yesno $(_print_args "$@")"
                        yesno "$@"
                }
 

Reply via email to