/*
 *  Copyright 2007-2008 University Of Southern California
 *
 *  Licensed under the Apache License, Version 2.0 (the "License");
 *  you may not use this file except in compliance with the License.
 *  You may obtain a copy of the License at
 *
 *  http://www.apache.org/licenses/LICENSE-2.0
 *
 *  Unless required by applicable law or agreed to in writing,
 *  software distributed under the License is distributed on an "AS IS" BASIS,
 *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 *  See the License for the specific language governing permissions and
 *  limitations under the License.
 */
package edu.usc.glidein.cli;

import java.util.LinkedList;
import java.util.List;

public class CommandLineClient 
{
	private static void fail()
	{
		System.out.println("Type '"+Command.COMMAND_NAME+" help' for usage");
		System.exit(1);
	}
	
	public static void main(String[] args)
	{
		if (args.length==0) {
			fail();
		} else {
			// Handle arguments
			List<String> arguments = new LinkedList<String>();
			for (String arg : args) arguments.add(arg);
			String name = arguments.remove(0);
			String[] ops = arguments.toArray(new String[0]); 
			
			// Invoke appropriate command
			Command command = Command.getCommand(name);
			if (command == null) {
				System.out.println("Unknown command: '"+name+"'");
				fail();
			} else {
				try {
					command.invoke(ops);
				} catch (CommandException e) {
					if (e.getMessage() != null) {
						System.out.println(e.getMessage());
					}
					if (command.isDebug() && e.getCause() != null) {
						e.getCause().printStackTrace();
					}
					System.exit(1);
				} catch (Exception e) {
					e.printStackTrace();
					System.exit(1);
				}
			}
		}
	}
}

@@ -1441,82 +1441,62 @@
 if (
-e.getMessage() != null) %7B%0A%09%09%09%09%09%09System.out.println(e.getMessag
+command.isDebug()) %7B%0A%09%09%09%09%09%09e.printStackTrac
 e()
-)
 ;%0A%09%09%09%09%09%7D
 %0A%09%09%09
@@ -1495,99 +1495,56 @@
 %09%09%09%7D
-%0A%09%09%09%09%09if (command.isDebug() && e.getCause() != null) %7B%0A%09%09%09%09%09%09e.getCause().printStackTrac
+ else %7B%0A%09%09%09%09%09%09System.out.println(e.getMessag
 e()
+)
 ;%0A%09%09

Fix error reporting