directory-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From elecha...@apache.org
Subject svn commit: r406558 - /directory/branches/elecharny/apacheds/server-tools/src/main/java/org/apache/directory/server/tools/BaseCommand.java
Date Mon, 15 May 2006 06:49:05 GMT
Author: elecharny
Date: Sun May 14 23:49:04 2006
New Revision: 406558

URL: http://svn.apache.org/viewcvs?rev=406558&view=rev
Log:
Extended the command set with the import command

Modified:
    directory/branches/elecharny/apacheds/server-tools/src/main/java/org/apache/directory/server/tools/BaseCommand.java

Modified: directory/branches/elecharny/apacheds/server-tools/src/main/java/org/apache/directory/server/tools/BaseCommand.java
URL: http://svn.apache.org/viewcvs/directory/branches/elecharny/apacheds/server-tools/src/main/java/org/apache/directory/server/tools/BaseCommand.java?rev=406558&r1=406557&r2=406558&view=diff
==============================================================================
--- directory/branches/elecharny/apacheds/server-tools/src/main/java/org/apache/directory/server/tools/BaseCommand.java
(original)
+++ directory/branches/elecharny/apacheds/server-tools/src/main/java/org/apache/directory/server/tools/BaseCommand.java
Sun May 14 23:49:04 2006
@@ -17,17 +17,23 @@
 package org.apache.directory.server.tools;
 
 
+import java.util.ArrayList;
 import java.util.HashMap;
 import java.util.Iterator;
+import java.util.List;
 import java.util.Map;
 
+import org.apache.commons.cli.AlreadySelectedException;
 import org.apache.commons.cli.CommandLine;
 import org.apache.commons.cli.CommandLineParser;
 import org.apache.commons.cli.HelpFormatter;
+import org.apache.commons.cli.MissingArgumentException;
+import org.apache.commons.cli.MissingOptionException;
 import org.apache.commons.cli.Option;
 import org.apache.commons.cli.Options;
 import org.apache.commons.cli.ParseException;
 import org.apache.commons.cli.PosixParser;
+import org.apache.commons.cli.UnrecognizedOptionException;
 
 
 /**
@@ -39,6 +45,7 @@
 public class BaseCommand
 {
     private Map commands = new HashMap();
+    private List commandsOrdered = new ArrayList();
     private Options global = new Options();
     private String productCommand;
     private String productVersion;
@@ -56,14 +63,26 @@
     protected void init()
     {
         ToolCommand command;
+        
+        command = new DiagnosticCommand();
+        commands.put( command.getName(), command );
+        commandsOrdered.add( command.getName() );
+        
         command = new DumpCommand();
-        getCommands().put( command.getName(), command );
+        commands.put( command.getName(), command );
+        commandsOrdered.add( command.getName() );
+        
         command = new GracefulShutdownCommand();
-        getCommands().put( command.getName(), command );
-        command = new DiagnosticCommand();
-        getCommands().put( command.getName(), command );
+        commands.put( command.getName(), command );
+        commandsOrdered.add( command.getName() );
+
+        command = new ImportCommand();
+        commands.put( command.getName(), command );
+        commandsOrdered.add( command.getName() );
+
         command = new DisconnectNotificationCommand();
-        getCommands().put( command.getName(), command );
+        commands.put( command.getName(), command );
+        commandsOrdered.add( command.getName() );
 
         Option op = new Option( "i", "install-path", true, "path to installation directory"
);
         getGlobal().addOption( op );
@@ -104,11 +123,32 @@
         {
             cmdline = parser.parse( all, args );
         }
-        catch ( ParseException e )
+        catch ( AlreadySelectedException ase )
         {
-            System.err.println( "Command line parsing failed for " + command + ".  Reason:
" + e.getMessage() );
+            System.err.println( "Command line parsing failed for " + command + ".  Reason:
already selected " + ase.getMessage() );
             System.exit( 1 );
         }
+        catch ( MissingArgumentException mae )
+        {
+            System.err.println( "Command line parsing failed for " + command + ".  Reason:
missing argument " + mae.getMessage() );
+            System.exit( 1 );
+        }
+        catch ( MissingOptionException moe )
+        {
+            System.err.println( "Command line parsing failed for " + command + ".  Reason:
missing option " + moe.getMessage() );
+            System.exit( 1 );
+        }
+        catch ( UnrecognizedOptionException uoe )
+        {
+            System.err.println( "Command line parsing failed for " + command + ".  Reason:
unrecognized option" + uoe.getMessage() );
+            System.exit( 1 );
+        }
+        catch ( ParseException pe )
+        {
+            System.err.println( "Command line parsing failed for " + command + ".  Reason:
" + pe.getClass() );
+            System.exit( 1 );
+        }
+
         return cmdline;
     }
 
@@ -122,6 +162,7 @@
 
         Options all = new Options();
         ToolCommand cmd = ( ToolCommand ) getCommands().get( command );
+        
         for ( Iterator ii = getGlobal().getOptions().iterator(); ii.hasNext(); )
         {
             all.addOption( ( Option ) ii.next() );
@@ -146,6 +187,7 @@
 
         StringBuffer buf = new StringBuffer();
         buf.append( msg ).append( "\n" );
+        
         for ( int ii = 0; ii < args.length; ii++ )
         {
             buf.append( "\targs[" + ii + "] = " ).append( args[ii] ).append( "\n" );
@@ -161,6 +203,7 @@
             printUsage();
             System.exit( 0 );
         }
+        
         if ( getCommands().containsKey( command ) )
         {
             ToolCommand cmd = ( ToolCommand ) getCommands().get( command );
@@ -180,9 +223,11 @@
         HelpFormatter formatter = new HelpFormatter();
         formatter.printHelp( getProductCommand() + " <command> [options]", "\nGlobal
options:", getGlobal(),
             "\nType \"" + getProductCommand() + " help <command>\" for help on a command."
);
-        System.out.println( "\nAvalable commands:" );
-        Iterator it = getCommands().values().iterator();
+        System.out.println( "\nAvailable commands:" );
+        
+        Iterator it = commandsOrdered.iterator();
         System.out.println( "\thelp" );
+        
         while ( it.hasNext() )
         {
             System.out.println( "\t" + it.next() );



Mime
View raw message