commit:     a3091c3b9dcae38cc1b6a78f8f963e2cbc3144be
Author:     Michael Orlitzky <mjo <AT> gentoo <DOT> org>
AuthorDate: Sun Dec 20 00:06:47 2015 +0000
Commit:     Michael Orlitzky <mjo <AT> gentoo <DOT> org>
CommitDate: Sun Dec 20 00:06:47 2015 +0000
URL:        https://gitweb.gentoo.org/proj/eselect-php.git/commit/?id=a3091c3b

Consolidate all list_foo actions into one new list_sapi() function.

This follows in the same vein as the other recent refactorings. With
the machinery in place, list_cli, list_cgi, etc. are all replaced by
one function list_sapi() taking a SAPI name as an argument.

 src/php.eselect.in | 70 +++++++++++++++++++-----------------------------------
 1 file changed, 24 insertions(+), 46 deletions(-)

diff --git a/src/php.eselect.in b/src/php.eselect.in
index a377116..9a1d628 100644
--- a/src/php.eselect.in
+++ b/src/php.eselect.in
@@ -249,69 +249,47 @@ check_module() {
 
 ## Actual actions
 
-list_apache2() {
-       local targets
-       local a
-       targets=( $(find_sapi_targets apache2) )
-       a=$(get_sapi_active_target apache2)
+# Perform the "list" action for the given SAPI.
+#
+# INPUT:
+#
+# The SAPI name.
+#
+# OUTPUT:
+#
+# A numbered and decorated list of targets for the given SAPI.
+#
+list_sapi() {
+       local sapi="${1}"
+       local targets=( $(find_sapi_targets "${sapi}") )
+       local active=$(get_sapi_active_target "${sapi}")
+
        for (( i = 0; i < ${#targets[@]}; i++ )) ; do
-               if [[ $a == ${targets[i]} ]] ; then
+               if [[ $active == ${targets[i]} ]] ; then
                        targets[i]=$(highlight_marker "${targets[i]}")
                fi
        done
        write_numbered_list -m "(none found)" "${targets[@]}"
 }
 
+list_apache2() {
+       list_sapi apache2
+}
+
 list_cli() {
-       local targets
-       local a
-       targets=( $(find_sapi_targets cli) )
-       a=$(get_sapi_active_target cli)
-       for (( i = 0; i < ${#targets[@]}; i++ )) ; do
-               if [[ $a == ${targets[i]} ]] ; then
-                       targets[i]=$(highlight_marker "${targets[i]}")
-               fi
-       done
-       write_numbered_list -m "(none found)" "${targets[@]}"
+       list_sapi cli
 }
 
 list_cgi() {
-       local targets
-       local a
-       targets=( $(find_sapi_targets cgi) )
-       a=$(get_sapi_active_target cgi)
-       for (( i = 0; i < ${#targets[@]}; i++ )) ; do
-               if [[ $a == ${targets[i]} ]] ; then
-                       targets[i]=$(highlight_marker "${targets[i]}")
-               fi
-       done
-       write_numbered_list -m "(none found)" "${targets[@]}"
+       list_sapi cgi
 }
 
 list_fpm() {
-       local targets
-       local a
-       targets=( $(find_sapi_targets fpm) )
-       a=$(get_sapi_active_target fpm)
-       for (( i = 0; i < ${#targets[@]}; i++ )) ; do
-               if [[ $a == ${targets[i]} ]] ; then
-                       targets[i]=$(highlight_marker "${targets[i]}")
-               fi
-       done
-       write_numbered_list -m "(none found)" "${targets[@]}"
+       list_sapi fpm
 }
 
 list_phpdbg() {
-       local targets
-       local a
-       targets=( $(find_sapi_targets dbg) )
-       a=$(get_sapi_active_target dbg)
-       for (( i = 0; i < ${#targets[@]}; i++ )) ; do
-               if [[ $a == ${targets[i]} ]] ; then
-                       targets[i]=$(highlight_marker "${targets[i]}")
-               fi
-       done
-       write_numbered_list -m "(none found)" "${targets[@]}"
+       list_sapi dbg
 }
 
 set_apache2() {

Reply via email to