commit:     dc9fac81f559a79b660bccc89e105afb314dd3e0
Author:     Ulrich Müller <ulm <AT> gentoo <DOT> org>
AuthorDate: Thu Jun  5 11:16:32 2014 +0000
Commit:     Ulrich Müller <ulm <AT> gentoo <DOT> org>
CommitDate: Thu Jun  5 11:16:32 2014 +0000
URL:        
http://git.overlays.gentoo.org/gitweb/?p=proj/eselect.git;a=commit;h=dc9fac81

Always parse global options. Respect "--".

* bin/eselect.in: Parse global options even if we are invoked
as something-config or similar. Respect "--" to indicate end
of options.

---
 ChangeLog      |  6 ++++++
 bin/eselect.in | 64 ++++++++++++++++++++++++++++++++--------------------------
 2 files changed, 41 insertions(+), 29 deletions(-)

diff --git a/ChangeLog b/ChangeLog
index 03fe042..c3f0061 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,9 @@
+2014-06-05  Ulrich Müller  <[email protected]>
+
+       * bin/eselect.in: Parse global options even if we are invoked
+       as something-config or similar. Respect "--" to indicate end
+       of options.
+
 2014-05-24  Ulrich Müller  <[email protected]>
 
        * configure.ac: Update version to 1.4.2.

diff --git a/bin/eselect.in b/bin/eselect.in
index 70e1c20..e2f29ea 100755
--- a/bin/eselect.in
+++ b/bin/eselect.in
@@ -126,34 +126,40 @@ if [[ -z ${action} ]]; then
        unset binname prefix
 fi
 
-if [[ -z ${action} ]] && [[ -n ${1##--} ]]; then
-       while [[ ${1##--} != "$1" ]]; do
-               case ${1##--} in
-                       brief)
-                               set_output_mode brief
-                               ;;
-                       colour=*|color=*|colour|color)
-                               # accept all arguments that are valid for ls or 
emerge
-                               case ${1#*=} in
-                                       yes|y|always|force|$1) colour=yes ;;
-                                       no|n|never|none) colour=no ;;
-                                       auto|tty|if-tty) colour="" ;;
-                                       *) die -q "Invalid argument for 
${1%%=*} option" ;;
-                               esac
-                               ;;
-                       help|version)
-                               action=${1##--}
-                               ;;
-                       *)
-                               die -q "Unknown option $1"
-                               ;;
-               esac
-               shift
-       done
-       if [[ -z ${action} ]]; then
-               action=$1
-               shift
-       fi
+# parse global options
+while [[ ${1##--} != "$1" ]]; do
+       case ${1##--} in
+               brief)
+                       set_output_mode brief
+                       ;;
+               colour=*|color=*|colour|color)
+                       # accept all arguments that are valid for ls or emerge
+                       case ${1#*=} in
+                               yes|y|always|force|$1) colour=yes ;;
+                               no|n|never|none) colour=no ;;
+                               auto|tty|if-tty) colour="" ;;
+                               *) die -q "Invalid argument for ${1%%=*} 
option" ;;
+                       esac
+                       ;;
+               help|version)
+                       [[ -z ${action} ]] || die -q "Too many parameters"
+                       action=${1##--}
+                       ;;
+               "")
+                       # -- indicates end of options
+                       shift
+                       break
+                       ;;
+               *)
+                       die -q "Unknown option $1"
+                       ;;
+       esac
+       shift
+done
+
+if [[ -z ${action} && $# -gt 0 ]]; then
+       action=$1
+       shift
 fi
 
 # enable colour output and get width of terminal iff stdout is a tty
@@ -167,7 +173,7 @@ unset colour
 
 if [[ -n ${action} ]]; then
        if is_function "es_do_${action}"; then
-               [[ $# -gt 0 ]] && die -q "Too many parameters"
+               [[ $# -eq 0 ]] || die -q "Too many parameters"
                es_do_${action}
        else
                do_action "${action}" "$@"

Reply via email to