--- r:\jakarta-ant\jakarta-ant\src\main\org\apache\tools\ant\Main.java	Sun Jul 16 01:39:58 2000
+++ R:\jakarta-ant\src\main\org\apache\tools\ant\Main.java	Mon Aug 14 15:04:38 2000
@@ -95,6 +95,13 @@
      */
     private boolean readyToRun = false;
 
+//MS:begin
+    /**
+     * Indicates we should only parse and display the current buildfile's targets
+     */
+    private boolean parseNdisplayTargets = false;
+//MS:end
+
     /**
      * Command line entry point. This method kicks off the building
      * of a project object and executes a build using either a given
@@ -190,6 +197,11 @@
                     value = args[++i];
 
                 definedProps.put(name, value);
+//MS:begin
+            } else if (arg.equals("-targets")) {
+                // set the flag to display the targets and quit
+                parseNdisplayTargets = true;
+//MS:end
             } else if (arg.startsWith("-")) {
                 // we don't have any more args to recognize!
                 String msg = "Unknown arg: " + arg;
@@ -244,7 +256,6 @@
         try {
             addBuildListeners(project);
             project.fireBuildStarted();
-            
             project.init();
 
             // set user-define properties
@@ -274,9 +285,14 @@
             if (targets.size() == 0) {
                 targets.addElement(project.getDefaultTarget());
             }
-
-            // actually do some work
-            project.executeTargets(targets);
+//MS:begin
+            if (parseNdisplayTargets) {
+                printTargets(project);
+            } else {
+                // actually do some work
+                project.executeTargets(targets);
+            }
+//MS:end
         }
         catch(RuntimeException exc) {
             error = exc;
@@ -332,6 +348,9 @@
         msg.append("  -listener <classname>  add an instance of class as a project listener" + lSep);
         msg.append("  -buildfile <file>      use given buildfile" + lSep);
         msg.append("  -D<property>=<value>   use value for given property" + lSep);
+//MS:begin
+        msg.append("  -targets               list the available targets" + lSep);
+//MS:end
         System.out.println(msg.toString());
     }
 
@@ -358,4 +377,50 @@
             System.err.println("Could not load the version information.");
         }
     }
+
+//MS:begin
+    /**
+     * Print out a list of all targets in the current buildfile
+     */
+    private static void printTargets(Project project) {
+        // find the target with the longest name and
+        // filter out the targets with no description
+        int maxLength = 0;
+        Enumeration ptargets = project.getTargets().elements();
+        String targetName;
+        String targetDescription;
+        Target currentTarget;
+        Vector names = new Vector();
+        Vector descriptions = new Vector();
+
+        while (ptargets.hasMoreElements()) {
+          currentTarget = (Target)ptargets.nextElement();
+          targetName = currentTarget.getName();
+          targetDescription = currentTarget.getDescription();
+          if (targetDescription != null) {
+            names.addElement(targetName);
+            descriptions.addElement(targetDescription);
+            if (targetName.length() > maxLength) {
+              maxLength = targetName.length();
+            }
+          }
+        }
+
+        // now, start printing the targets and their descriptions
+        String lSep = System.getProperty("line.separator");
+        // got a bit annoyed that I couldn't find a pad function
+        String spaces = "    ";
+        while (spaces.length()<maxLength) {
+          spaces += spaces;
+        }
+        StringBuffer msg = new StringBuffer();
+        msg.append("Targets: " + lSep);
+        for (int i=0; i<names.size(); i++) {
+          msg.append(" -"+names.elementAt(i));
+          msg.append(spaces.substring(0, maxLength - ((String)names.elementAt(i)).length() + 2));
+          msg.append(descriptions.elementAt(i)+lSep);
+        }
+        System.out.println(msg.toString());
+    }
+//MS:end
 }
