// Path: cli/src/main/java/org/apache/whirr/cli/command/DestroyClusterCommand.java
// public class DestroyClusterCommand extends ClusterSpecCommand {
// 
//   public DestroyClusterCommand() throws IOException {
//     this(new ServiceFactory());
//   }
// 
//   public DestroyClusterCommand(ServiceFactory factory) {
//     super("destroy-cluster", "Terminate and cleanup resources for a running cluster.", factory);
//   }
//   
//   @Override
//   public int run(InputStream in, PrintStream out, PrintStream err,
//       List<String> args) throws Exception {
//     
//     OptionSet optionSet = parser.parse(args.toArray(new String[0]));
// 
//     if (!optionSet.nonOptionArguments().isEmpty()) {
//       printUsage(parser, err);
//       return -1;
//     }
//     try {
//       ClusterSpec clusterSpec = getClusterSpec(optionSet);
// 
//       Service service = factory.create(clusterSpec.getServiceName());
//       service.destroyCluster(clusterSpec);
//       return 0;
//     } catch (IllegalArgumentException e) {
//       err.println(e.getMessage());
//       printUsage(parser, err);
//       return -1;
//     }
//   }
// 
//   private void printUsage(OptionParser parser, PrintStream stream) throws IOException {
//     stream.println("Usage: whirr destroy-cluster [OPTIONS]");
//     stream.println();
//     parser.printHelpOn(stream);
//   }
// }
// 
// Path: cli/src/main/java/org/apache/whirr/cli/command/LaunchClusterCommand.java
// public class LaunchClusterCommand extends ClusterSpecCommand {
// 
//   public LaunchClusterCommand() throws IOException {
//     this(new ServiceFactory());
//   }
// 
//   public LaunchClusterCommand(ServiceFactory factory) {
//     super("launch-cluster", "Launch a new cluster running a service.", factory);
//   }
// 
//   @Override
//   public int run(InputStream in, PrintStream out, PrintStream err,
//       List<String> args) throws Exception {
//     
//     OptionSet optionSet = parser.parse(args.toArray(new String[0]));
// 
//     if (!optionSet.nonOptionArguments().isEmpty()) {
//       printUsage(parser, err);
//       return -1;
//     }
//     
//     try {
//       ClusterSpec clusterSpec = getClusterSpec(optionSet);
//       Service service = factory.create(clusterSpec.getServiceName());
//       Cluster cluster = service.launchCluster(clusterSpec);
//       out.printf("Started cluster of %s instances\n",
//           cluster.getInstances().size());
//       out.println(cluster);
//       return 0;
//     } catch (IllegalArgumentException e) {
//       err.println(e.getMessage());
//       printUsage(parser, err);
//       return -1;
//     }
//   }
// 
//   private void printUsage(OptionParser parser, PrintStream stream) throws IOException {
//     stream.println("Usage: whirr launch-cluster [OPTIONS]");
//     stream.println();
//     parser.printHelpOn(stream);
//   }
// }


import com.google.common.collect.Maps;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintStream;
import java.util.Arrays;
import java.util.List;
import java.util.Map;
import org.apache.whirr.cli.command.DestroyClusterCommand;
import org.apache.whirr.cli.command.LaunchClusterCommand;
/**
 * Licensed to the Apache Software Foundation (ASF) under one
 * or more contributor license agreements.  See the NOTICE file
 * distributed with this work for additional information
 * regarding copyright ownership.  The ASF licenses this file
 * to you 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 org.apache.whirr.cli;




/**
 * The entry point for the Whirr CLI.
 */
public class Main {
  
  private Map<String, Command> commandMap = Maps.newLinkedHashMap();
  private int maxLen = 0;
  
  Main(Command... commands) throws IOException {
    for (Command command : commands) {
      commandMap.put(command.getName(), command);
      maxLen = Math.max(maxLen, command.getName().length());
    }
  }
  
  int run(InputStream in, PrintStream out, PrintStream err,
      List<String> list) throws Exception {
    if (list.isEmpty()) {
      out.println("Usage: whirr COMMAND [ARGS]");
// Path: cli/src/main/java/org/apache/whirr/cli/command/DestroyClusterCommand.java
// public class DestroyClusterCommand extends ClusterSpecCommand {
// 
//   public DestroyClusterCommand() throws IOException {
//     this(new ServiceFactory());
//   }
// 
//   public DestroyClusterCommand(ServiceFactory factory) {
//     super("destroy-cluster", "Terminate and cleanup resources for a running cluster.", factory);
//   }
//   
//   @Override
//   public int run(InputStream in, PrintStream out, PrintStream err,
//       List<String> args) throws Exception {
//     
//     OptionSet optionSet = parser.parse(args.toArray(new String[0]));
// 
//     if (!optionSet.nonOptionArguments().isEmpty()) {
//       printUsage(parser, err);
//       return -1;
//     }
//     try {
//       ClusterSpec clusterSpec = getClusterSpec(optionSet);
// 
//       Service service = factory.create(clusterSpec.getServiceName());
//       service.destroyCluster(clusterSpec);
//       return 0;
//     } catch (IllegalArgumentException e) {
//       err.println(e.getMessage());
//       printUsage(parser, err);
//       return -1;
//     }
//   }
// 
//   private void printUsage(OptionParser parser, PrintStream stream) throws IOException {
//     stream.println("Usage: whirr destroy-cluster [OPTIONS]");
//     stream.println();
//     parser.printHelpOn(stream);
//   }
// }
// 
// Path: cli/src/main/java/org/apache/whirr/cli/command/LaunchClusterCommand.java
// public class LaunchClusterCommand extends ClusterSpecCommand {
// 
//   public LaunchClusterCommand() throws IOException {
//     this(new ServiceFactory());
//   }
// 
//   public LaunchClusterCommand(ServiceFactory factory) {
//     super("launch-cluster", "Launch a new cluster running a service.", factory);
//   }
// 
//   @Override
//   public int run(InputStream in, PrintStream out, PrintStream err,
//       List<String> args) throws Exception {
//     
//     OptionSet optionSet = parser.parse(args.toArray(new String[0]));
// 
//     if (!optionSet.nonOptionArguments().isEmpty()) {
//       printUsage(parser, err);
//       return -1;
//     }
//     
//     try {
//       ClusterSpec clusterSpec = getClusterSpec(optionSet);
//       Service service = factory.create(clusterSpec.getServiceName());
//       Cluster cluster = service.launchCluster(clusterSpec);
//       out.printf("Started cluster of %s instances\n",
//           cluster.getInstances().size());
//       out.println(cluster);
//       return 0;
//     } catch (IllegalArgumentException e) {
//       err.println(e.getMessage());
//       printUsage(parser, err);
//       return -1;
//     }
//   }
// 
//   private void printUsage(OptionParser parser, PrintStream stream) throws IOException {
//     stream.println("Usage: whirr launch-cluster [OPTIONS]");
//     stream.println();
//     parser.printHelpOn(stream);
//   }
// }


// Path: cli/src/main/java/org/apache/whirr/cli/Main.java
import com.google.common.collect.Maps;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintStream;
import java.util.Arrays;
import java.util.List;
import java.util.Map;
import org.apache.whirr.cli.command.DestroyClusterCommand;
import org.apache.whirr.cli.command.LaunchClusterCommand;

/**
 * Licensed to the Apache Software Foundation (ASF) under one
 * or more contributor license agreements.  See the NOTICE file
 * distributed with this work for additional information
 * regarding copyright ownership.  The ASF licenses this file
 * to you 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 org.apache.whirr.cli;




/**
 * The entry point for the Whirr CLI.
 */
public class Main {
  
  private Map<String, Command> commandMap = Maps.newLinkedHashMap();
  private int maxLen = 0;
  
  Main(Command... commands) throws IOException {
    for (Command command : commands) {
      commandMap.put(command.getName(), command);
      maxLen = Math.max(maxLen, command.getName().length());
    }
  }
  
  int run(InputStream in, PrintStream out, PrintStream err,
      List<String> list) throws Exception {
    if (list.isEmpty()) {
      out.println("Usage: whirr COMMAND [ARGS]");
      out.println("where COMMAND may be one of:");