commit:     e05ad5dc17a9501bf14e56652a42cf66a545e512
Author:     Michael Orlitzky <mjo <AT> gentoo <DOT> org>
AuthorDate: Fri Jan  8 16:32:30 2016 +0000
Commit:     Michael Orlitzky <mjo <AT> gentoo <DOT> org>
CommitDate: Fri Jan  8 16:32:30 2016 +0000
URL:        https://gitweb.gentoo.org/proj/eselect-php.git/commit/?id=e05ad5dc

Document and clean up the resolv_target function.

 src/php.eselect.in | 39 +++++++++++++++++++++++++++++++++------
 1 file changed, 33 insertions(+), 6 deletions(-)

diff --git a/src/php.eselect.in b/src/php.eselect.in
index d868082..72e6610 100644
--- a/src/php.eselect.in
+++ b/src/php.eselect.in
@@ -231,14 +231,41 @@ write_mod_php_conf() {
        EOF
 }
 
+
+# Resolve an index or target name for a given SAPI into the "display
+# name" of that target.
+#
+# INPUT:
+#
+# The first parameter is the name of a SAPI. The second parameter is
+# either a number (the index of a target), or a target name.
+#
+# OUTPUT:
+#
+# The "display name" of the given target for the given SAPI. For
+# example, if the first parameter is "cli" and the second parameter is
+# "1", then the output will be the display name of the first target
+# for the cli SAPI (e.g. "php5.6").
+#
+# If the index or target name is invalid (that is, does not correspond
+# to one of the valid targets for the given SAPI), then nothing is
+# output.
+#
 resolv_target() {
-       local targets=( $(find_sapi_targets $1) )
-       if is_number $2; then
-               if [[ $2 -le ${#targets[@]} && $2 -gt 0 ]] ; then
-                       echo "${targets[ $(( $2 - 1 )) ]}"
+       local sapi="${1}"
+       local target="${2}"
+
+       # $targets is an array of things like "php5.6" and "php7.0"
+       local targets=( $(find_sapi_targets "${sapi}") )
+
+       if is_number "${target}" ; then
+               if [[ $target -le ${#targets[@]} && $target -gt 0 ]] ; then
+                       # $target looks like an index into the $targets array.
+                       echo "${targets[ $(( $target - 1 )) ]}"
                fi
-       elif has $2 ${targets[@]}; then
-         echo $2
+       elif has "${target}" ${targets[@]} ; then
+               # $target is the *name* of a valid target for this SAPI.
+               echo "${target}"
        fi
 }
 

Reply via email to