[152623] contrib/mp-buildbot

larryv at macports.org larryv at macports.org
Tue Sep 13 07:25:38 PDT 2016


Revision: 152623
          https://trac.macports.org/changeset/152623
Author:   larryv at macports.org
Date:     2016-09-13 07:25:38 -0700 (Tue, 13 Sep 2016)
Log Message:
-----------
mpbb: Move parseopt to support library

Modified Paths:
--------------
    contrib/mp-buildbot/functions
    contrib/mp-buildbot/mpbb

Modified: contrib/mp-buildbot/functions
===================================================================
--- contrib/mp-buildbot/functions	2016-09-13 13:19:35 UTC (rev 152622)
+++ contrib/mp-buildbot/functions	2016-09-13 14:25:38 UTC (rev 152623)
@@ -9,6 +9,74 @@
 err() { msg error: "$@"; }
 warn() { msg warning: "$@"; }
 
+unset GETOPT_COMPATIBLE
+if getopt -T >/dev/null; then
+    # http://frodo.looijaard.name/project/getopt
+    err "Cannot find an enhanced getopt(1)"
+    return 3
+fi
+
+# TODO Documentation, obviously :)
+parseopt() {
+    # Be stricter about this than getopt(1) is.
+    if ! [[ ${1-} =~ ^[[:alnum:]-]+:{0,2}(,[[:alnum:]-]+:{0,2})*$ ]]; then
+        err 'Invalid argument given to parseopt'
+        return 3
+    fi
+
+    # Use "--options +" to prevent arguments from being rearranged.
+    local opts
+    opts=$(getopt --name "$0" --opt + --longopt "$1" -- "${@:2}")
+    case $? in
+        0)
+            ;;
+        1)
+            # getopt(1) will print the bad argument to standard error.
+            echo >&2 "Try \`$0 help' for more information."
+            return 2
+            ;;
+        *)
+            err 'getopt encountered an internal error'
+            return 3
+            ;;
+    esac
+    readonly opts
+
+    local -a validopts
+    IFS=, read -ra validopts <<<"$1"
+    readonly validopts=("${validopts[@]/#/--}")
+
+    eval set -- "$opts"
+
+    local opt validopt
+    # getopt(1) ensures that the options are always terminated with "--".
+    while [[ $1 != -- ]]; do
+        opt=$1
+        shift
+        # XXX Do NOT touch anything below unless you know exactly what
+        # you're doing (http://mywiki.wooledge.org/BashFAQ/006#eval).
+        for validopt in "${validopts[@]}"; do
+            if [[ $validopt == "$opt:" || $validopt == "$opt::" ]]; then
+                opt=${opt#--}
+                # $1 is null for omitted optional arguments.
+                eval option_"${opt//-/_}"'=$1'
+                shift
+                continue 2
+            fi
+            if [[ $validopt == "$opt" ]]; then
+                opt=${opt#--}
+                eval option_"${opt//-/_}"'=1'
+                continue 2
+            fi
+        done
+        # Unreachable unless there is a bug in this function or in getopt(1).
+        err 'parseopt encountered an internal error'
+        return 3
+    done
+    # shellcheck disable=SC2034
+    args=("${@:2}")
+}
+
 ## Compute a failcache hash for the given port
 #
 # Computes and prints a hash uniquely identifying a specific state of a port's

Modified: contrib/mp-buildbot/mpbb
===================================================================
--- contrib/mp-buildbot/mpbb	2016-09-13 13:19:35 UTC (rev 152622)
+++ contrib/mp-buildbot/mpbb	2016-09-13 14:25:38 UTC (rev 152623)
@@ -11,7 +11,7 @@
 # Load function library
 thisdir=$(cd "$(dirname "$0")" && pwd)
 # shellcheck source=functions
-. "$thisdir/functions"
+. "$thisdir/functions" || exit
 
 mpbb-usage() {
     # "prog" is defined in mpbb-help.
@@ -41,73 +41,6 @@
 EOF
 }
 
-# TODO Documentation, obviously :)
-parseopt() {
-    # Be stricter about this than getopt(1) is.
-    if ! [[ ${1-} =~ ^[[:alnum:]-]+:{0,2}(,[[:alnum:]-]+:{0,2})*$ ]]; then
-        err 'Invalid argument given to parseopt'
-        return 3
-    fi
-
-    # Use "--options +" to prevent arguments from being rearranged.
-    local opts
-    opts=$(getopt --name "$0" --opt + --longopt "$1" -- "${@:2}")
-    case $? in
-        0)
-            ;;
-        1)
-            # getopt(1) will print the bad argument to standard error.
-            echo >&2 "Try \`$0 help' for more information."
-            return 2
-            ;;
-        *)
-            err 'getopt encountered an internal error'
-            return 3
-            ;;
-    esac
-    readonly opts
-
-    local -a validopts
-    IFS=, read -ra validopts <<<"$1"
-    readonly validopts=("${validopts[@]/#/--}")
-
-    eval set -- "$opts"
-
-    local opt validopt
-    # getopt(1) ensures that the options are always terminated with "--".
-    while [[ $1 != -- ]]; do
-        opt=$1
-        shift
-        # XXX Do NOT touch anything below unless you know exactly what
-        # you're doing (http://mywiki.wooledge.org/BashFAQ/006#eval).
-        for validopt in "${validopts[@]}"; do
-            if [[ $validopt == "$opt:" || $validopt == "$opt::" ]]; then
-                opt=${opt#--}
-                # $1 is null for omitted optional arguments.
-                eval option_"${opt//-/_}"'=$1'
-                shift
-                continue 2
-            fi
-            if [[ $validopt == "$opt" ]]; then
-                opt=${opt#--}
-                eval option_"${opt//-/_}"'=1'
-                continue 2
-            fi
-        done
-        # Unreachable unless there is a bug in this function or in getopt(1).
-        err 'parseopt encountered an internal error'
-        return 3
-    done
-    args=("${@:2}")
-}
-
-unset GETOPT_COMPATIBLE
-if getopt -T >/dev/null; then
-    # http://frodo.looijaard.name/project/getopt
-    err "Cannot find an enhanced getopt(1)"
-    exit 3
-fi
-
 # Process options.
 parseopt prefix:,work-dir: "$@" || exit
 
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.macosforge.org/pipermail/macports-changes/attachments/20160913/6ef2f03e/attachment.html>


More information about the macports-changes mailing list