about summary refs log tree commit diff
diff options
context:
space:
mode:
authorOliver Kiddle <opk@users.sourceforge.net>2002-08-19 14:54:13 +0000
committerOliver Kiddle <opk@users.sourceforge.net>2002-08-19 14:54:13 +0000
commit664395e56f162e15336abd386e1f0f7dc9dc0c11 (patch)
tree45222bef40c276b3b027a2eb662b1cdba5d1ab63
parent578c2582646c4932a72f23661b6f6c26e0fd4ca1 (diff)
downloadzsh-664395e56f162e15336abd386e1f0f7dc9dc0c11.tar.gz
zsh-664395e56f162e15336abd386e1f0f7dc9dc0c11.tar.xz
zsh-664395e56f162e15336abd386e1f0f7dc9dc0c11.zip
users/5266: with the call-command style parse ant -projecthelp to get targets
-rw-r--r--ChangeLog8
-rw-r--r--Completion/Unix/Command/_ant79
2 files changed, 76 insertions, 11 deletions
diff --git a/ChangeLog b/ChangeLog
index 650675ccc..eeed3c481 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,11 @@
+2002-08-19  Oliver Kiddle  <opk@zsh.org>
+
+	* users/5260 (Bill Burton), users/5266: Completion/Unix/Command/_ant:
+	with the call-command style parse ant -projecthelp to get targets
+
+	* unposted: Completion/X/Command/_nedit, Completion/Unix/Command/_mail:
+	nedit 5.3 adds a -version option and complete for nail with _mail
+
 2002-08-18  Felix Rosencrantz <f_rosencrantz@yahoo.com>
 
 	* 17562: Completion/Unix/Command/_valgrind: Function for
diff --git a/Completion/Unix/Command/_ant b/Completion/Unix/Command/_ant
index c1baf6f69..717fa9ea4 100644
--- a/Completion/Unix/Command/_ant
+++ b/Completion/Unix/Command/_ant
@@ -1,8 +1,9 @@
 #compdef ant -value-,ANT_ARGS,-default-
 
 typeset -A opt_args
-local state line curcontext="$curcontext"
+local buildfile tmp state line curcontext="$curcontext"
 local target='*:target:->target'
+#local CLASSPATH="$ANT_HOME/lib/*.jar"
 
 if [[ $service = *ANT_ARGS* ]]; then
   compset -q
@@ -22,17 +23,73 @@ _arguments -C \
   '-emacs[produce logging information without adornments]' \
   '(-l -logfile)'{-l,-logfile}'[use specified file for log]:logfile:_files' \
   '-logger[the class which is to perform logging]:classname:_java_class' \
-  '-listener[add an instance of class as a project listener]:classname:_java_class' \
-  '(-f -file -buildfile)'{-f,-file,-buildfile}'[use specified build file]:build file:_files' \
-  '*-D[specify property with value to use]:property' \
+  '*-listener[add an instance of class as a project listener]:classname:_java_class' \
+  '(-f -file -buildfile -find)'{-f,-file,-buildfile}'[use specified build file]:build file:_files' \
+  '*-D[specify property with value to use]:property:->property' \
   '-propertyfile[load properties from specfied file]:property file:_files' \
   '-inputhandler[specify class which will handle input requests]:class:_java_class' \
-  '-find[search for buildfile]:file:_files' \
+  '(-f -file -buildfile)-find[search for build file towards the root of filesystem]:build file:(build.xml)' \
   $target && return
 
-if [[ -n $state ]]; then
-  targets=( $(sed -n 's/ *<target name="\([^"]*\)".*/\1/p' < build.xml) )
-  # ant can be used to get a list of targets for us like this but it is slow
-  # targets=( ${${(M)${(f)"$(_call_program targets $words[1] -projecthelp)"}:# *}# } )
-  _wanted targets expl target compadd -a targets
-fi
+case $state in
+  property)
+    if compset -P '*='; then
+      _default
+    else
+      _message -e properties 'property name'
+    fi
+  ;;
+  target)
+    if zstyle -t ":completion:${curcontext}:targets" call-command; then
+      # Run ant -projecthelp also passing any of -find, -buildfile or -f options.
+      # Parse output into an array of the format "target:description".
+      # For the array to be set with correct argument boundaries, the entire
+      # set statement needs to be eval'd.  On Cygwin, need to kill \r's output
+      # from Java or parsing will fail.
+      eval set -A tmp "${$(_call_program targets "$words[1]" $buildxml -projecthelp |
+	while read target desc
+	do
+          # This loop reads ant -projecthelp output from versions 1.3 to 1.5
+          ln="${target}${desc:+:$desc}"
+          [[ $target = "" ]] && continue  # skip blank lines
+          case $ln in
+              (Buildfile:*)
+                  buildfile=$desc
+              ;;
+              (Default:target:*)
+                  # with version 1.5, target is on the same line
+                  default_target="${${desc/target:/}# }"
+                  # versions 1.3 and 1.4 with default target on a separate line
+                  if [[ -z $default_target ]]; then
+                      read junk
+                      read default_target junk
+                  fi
+                  # Output target again indicating its the default one.
+                  print -n "'${default_target}:(Default target) ' "
+              ;;
+              (Searching:*|Main:targets:|Subtargets:|BUILD:SUCCESSFUL|Total:time:
+	      *)
+              ;;
+              (*)
+                  # Return target and description
+                  print -n "'$ln' "
+              ;;
+          esac
+	done
+      )//$'\015'}"
+      _describe 'target' tmp
+    else
+      if [[ -n $opt_args[-find] ]]; then
+	buildfile=( (../)#${opt_args[-find]:-build.xml}(N[-1]) )
+      else
+	buildfile=${(v)opt_args[(I)(-f|-file|-buildfile)]:-build.xml}
+      fi
+      if [[ -f $buildfile ]]; then
+	targets=( $(sed -n 's/ *<target name="\([^"]*\)".*/\1/p' < $buildfile) )
+	_wanted targets expl target compadd -a targets
+      else
+	_message -e targets target
+      fi
+    fi
+  ;;
+esac