Zsh Mailing List Archive
Messages sorted by: Reverse Date, Date, Thread, Author

PATCH: _initctl: only define helper functions once



---
 Completion/Unix/Command/_initctl |   69 ++++++++++++++++++++------------------
 1 files changed, 36 insertions(+), 33 deletions(-)

diff --git a/Completion/Unix/Command/_initctl b/Completion/Unix/Command/_initctl
index 08145b1..850064d 100644
--- a/Completion/Unix/Command/_initctl
+++ b/Completion/Unix/Command/_initctl
@@ -2,29 +2,6 @@
 # Written by Bernhard Tittelbach
 # based on completion script by Mildred
 
-local -a common_args
-common_args=(
-  '--session[use D-Bus session bus to connect to init daemon (for testing)]'
-  '--system[talk via DBUS system bus instead of socket]'
-  '(-q --quiet)'{-q,--quiet}'[reduce output to errors only]'
-  '(-v --verbose)'{-v,--verbose}'[increase output to include informational messages]'
-  '--dest=[D-Bus name for init, defaults to com.ubuntu.Upstart]'
-  '--help[display help and exit]'
-  '--version[output version information and exit]'
-)
-
-# don't overwrite work that we might have already done
-if (( ${+_initctl_events_list} + ${+_initctl_eventargs_list} != 2 )); then
-  typeset -g -a -U _initctl_events_list _initctl_eventargs_list
-fi
-
-# map each initctl function to a completion function
-local -A cmd_completion_funcs
-cmd_completion_funcs=( start startstop stop startstop restart startstop reload startstop show-config show-config status argjob emit emit check-config check-config )
-
-# define fallback completion function
-local cmd_completion_default=basic
-
 # run show-config -e and if possible parse out all events and KEY= argumnts
 # otherwise provide some common values
 _initctl_fillarray_events_args ()
@@ -169,13 +146,39 @@ _initctl_check-config()
         '*::'
 }
 
-# depending on which command was used, call different completion funtions
-case $service in
-  initctl)
-    _arguments "${common_args[@]}" '*::Initctl Commands:_initctl_command'
-  ;;
-  start|stop|restart|reload|status)
-    _call_function ret _initctl_${cmd_completion_funcs[${service}]-${cmd_completion_default}}
-  ;;
-  *)  return 1  ;;
-esac
+_initctl()
+{
+  local -a common_args
+  common_args=(
+    '--session[use D-Bus session bus to connect to init daemon (for testing)]'
+    '--system[talk via DBUS system bus instead of socket]'
+    '(-q --quiet)'{-q,--quiet}'[reduce output to errors only]'
+    '(-v --verbose)'{-v,--verbose}'[increase output to include informational messages]'
+    '--dest=[D-Bus name for init, defaults to com.ubuntu.Upstart]'
+    '--help[display help and exit]'
+    '--version[output version information and exit]'
+  )
+
+  # don't overwrite work that we might have already done
+  if (( ${+_initctl_events_list} + ${+_initctl_eventargs_list} != 2 )); then
+    typeset -g -a -U _initctl_events_list _initctl_eventargs_list
+  fi
+
+  # map each initctl function to a completion function
+  local -A cmd_completion_funcs
+  cmd_completion_funcs=( start startstop stop startstop restart startstop reload startstop show-config show-config status argjob emit emit check-config check-config )
+
+  # define fallback completion function
+  local cmd_completion_default=basic
+
+  # depending on which command was used, call different completion funtions
+  case $service in
+    initctl)
+      _arguments "${common_args[@]}" '*::Initctl Commands:_initctl_command'
+    ;;
+    start|stop|restart|reload|status)
+      _call_function ret _initctl_${cmd_completion_funcs[${service}]-${cmd_completion_default}}
+    ;;
+    *)  return 1  ;;
+  esac
+}
-- 
1.7.4-rc1



Messages sorted by: Reverse Date, Date, Thread, Author