/**
 * Copyright 2015 Benjamin Navetta
 *
 * 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 com.bennavetta.aeneas.cli;

import java.util.logging.LogManager;

import org.slf4j.bridge.SLF4JBridgeHandler;

import io.airlift.airline.Cli;
import io.airlift.airline.Cli.CliBuilder;
import io.airlift.airline.help.Help;

import com.bennavetta.aeneas.cli.zookeeper.CreateNodes;
import com.bennavetta.aeneas.cli.zookeeper.ListNodes;
import com.bennavetta.aeneas.cli.zookeeper.RemoveNodes;
import com.bennavetta.aeneas.cli.zookeeper.StartNodes;
import com.bennavetta.aeneas.cli.zookeeper.StopNodes;
import com.bennavetta.aeneas.cli.zookeeper.ZooKeeperManager;

/**
 * Entry point for Aeneas' command line utility.
 */
public class Main
{
	@SuppressWarnings("unchecked")
	public static void main(String[] args)
	{
		System.setProperty("org.slf4j.simpleLogger.log.mousio.etcd4j.transport.EtcdNettyClient", "error");
		System.setProperty("org.slf4j.simpleLogger.log.org.glassfish.jersey.filter.LoggingFilter", "error");
		System.setProperty("org.slf4j.simpleLogger.log.com.github.dockerjava.jaxrs.DockerCmdExecFactoryImpl", "error");
		
		LogManager.getLogManager().reset();
		SLF4JBridgeHandler.install();
		
		CliBuilder<Runnable> builder = Cli.<Runnable>builder("aeneas")
				.withDescription("A dynamic, distributed cloud orchestration system")
				.withDefaultCommand(Help.class)
				.withCommands(Help.class);
		
		builder.withGroup("zookeeper")
			.withDefaultCommand(ListNodes.class)
			.withCommands(ZooKeeperManager.class, ListNodes.class,
					CreateNodes.class, StartNodes.class,
					StopNodes.class, RemoveNodes.class);

		Cli<Runnable> parser = builder.build();
		parser.parse(args).run();
	}
}

@@ -638,84 +638,74 @@
 ort 
-java.util.logging.LogManager;%0A%0Aimport org.slf4j.bridge.SLF4JBridgeHandl
+io.airlift.airline.Cli;%0Aimport io.airlift.airline.Cli.CliBuild
 er;%0A
-%0A
 impo
@@ -718,35 +718,46 @@
 airlift.airline.
-Cli
+ParseException
 ;%0Aimport io.airl
@@ -772,61 +772,247 @@
 ine.
-Cli.CliBuild
+help.Help;%0A%0Aimport java.io.IOException;%0Aimport java.util.logging.LogManag
 er;%0A
+%0A
 import 
-io.airlift.airline.help.Help;%0A
+jersey.repackaged.com.google.common.collect.Lists;%0A%0Aimport org.slf4j.bridge.SLF4JBridgeHandler;%0A%0Aimport com.bennavetta.aeneas.cli.mesos.CreateMesosMaster;
 %0Aimp
@@ -2133,16 +2133,65 @@
 eeper%22)%0A
+%09%09%09.withDescription(%22Manage ZooKeeper clusters%22)%0A
 %09%09%09.with
@@ -2363,16 +2363,136 @@
 .class);
+%0A%09%09%0A%09%09builder.withGroup(%22mesos%22)%0A%09%09%09.withDescription(%22Manage Mesos clusters%22)%0A%09%09%09.withCommands(CreateMesosMaster.class);
 %0A%0A%09%09Cli%3C
@@ -2527,16 +2527,27 @@
 uild();%0A
+%09%09try%0A%09%09%7B%0A%09
 %09%09parser
@@ -2566,13 +2566,305 @@
 .run();%0A
+%09%09%7D%0A%09%09catch(ParseException e)%0A%09%09%7B%0A%09%09%09System.err.println(e.getMessage());%0A%09%09%09try%0A%09%09%09%7B%0A%09%09%09%09Help.help(parser.getMetadata(), Lists.newArrayList());%0A%09%09%09%7D%0A%09%09%09catch (IOException e1)%0A%09%09%09%7B%0A%09%09%09%09System.err.println(%22Error generating usage documentation: %22 + e1.getMessage());%0A%09%09%09%7D%0A%09%09%09System.exit(1);%0A%09%09%7D%0A
 %09%7D%0A%7D%0A

print usage on parse exception