001    package com.saelist.command;
002    import org.apache.log4j.*;
003    
004    /** Passes arg[1..] to the Command indicated in arg[0]. "AbcCommand" is
005      * indicated by "abc". E.g. "ReplaceCommand" is indicated by "replace".
006      * Example:
007      * <pre>
008      *  java com.saelist.command.CommandLineInterface replace @replace-config.ls.txt
009      * </pre>
010      */
011    public class CommandLineInterface {
012    
013      public static void main(String[] args) throws CommandException {
014        try {
015          Logger.getRootLogger().setLevel(Level.ERROR);
016          Logger.getRootLogger().addAppender(new ConsoleAppender(new PatternLayout("%-6r [%15.15t] %-5p %30.30c %x - %m\n"), "System.err"));
017          Command command = null;
018    
019          // Create the command specified by the first argument.
020    
021          if(args[0].equals("replace"))
022            command = new ReplaceCommand();
023          else if(args[0].equals("smtp"))
024            command = new SmtpCommand();
025          else if(args[0].equals("transform"))
026            command = new TransformCommand();
027          else if(args[0].equals("findfiles"))
028            command = new FindFilesCommand();
029          else
030            throw new IllegalArgumentException();
031    
032          // Remove the command name from the argument list.
033    
034          String[] newargs = new String[args.length - 1];
035          for(int i = 1; i < args.length; i++)
036            newargs[i-1] = args[i];
037    
038          command.setArgs(newargs);
039          command.execute();
040        } catch(CommandException e) {
041          e.printStackTrace();
042        }
043    
044      }
045    
046    
047    }