brooklyn-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From rich...@apache.org
Subject [01/14] git commit: Extract AbstractMain to remove duplication
Date Mon, 08 Sep 2014 12:39:01 GMT
Repository: incubator-brooklyn
Updated Branches:
  refs/heads/master dd7339ebf -> 0d4992b57


Extract AbstractMain to remove duplication

- CLI tools (Main and CloudExplorer) extend AbstractMain


Project: http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/commit/e67819cf
Tree: http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/tree/e67819cf
Diff: http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/diff/e67819cf

Branch: refs/heads/master
Commit: e67819cf583cda920430cfb3a6d2677eaeb8e0e8
Parents: e862b50
Author: Aled Sage <aled.sage@gmail.com>
Authored: Wed Aug 13 20:51:26 2014 +0100
Committer: Martin Harris <github@nakomis.com>
Committed: Mon Sep 8 11:20:32 2014 +0100

----------------------------------------------------------------------
 .../main/java/brooklyn/cli/AbstractMain.java    | 263 +++++++++++++++++++
 .../main/java/brooklyn/cli/CloudExplorer.java   |  58 +---
 usage/cli/src/main/java/brooklyn/cli/Main.java  | 165 +-----------
 .../cli/src/test/java/brooklyn/cli/CliTest.java |   4 +-
 .../brooklyn/cli/CloudExplorerLiveTest.java     |   2 +-
 5 files changed, 269 insertions(+), 223 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/e67819cf/usage/cli/src/main/java/brooklyn/cli/AbstractMain.java
----------------------------------------------------------------------
diff --git a/usage/cli/src/main/java/brooklyn/cli/AbstractMain.java b/usage/cli/src/main/java/brooklyn/cli/AbstractMain.java
new file mode 100644
index 0000000..d27dee7
--- /dev/null
+++ b/usage/cli/src/main/java/brooklyn/cli/AbstractMain.java
@@ -0,0 +1,263 @@
+/*
+ * 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 brooklyn.cli;
+
+import groovy.lang.GroovyClassLoader;
+import groovy.lang.GroovyShell;
+import io.airlift.command.Arguments;
+import io.airlift.command.Cli;
+import io.airlift.command.Cli.CliBuilder;
+import io.airlift.command.Command;
+import io.airlift.command.Help;
+import io.airlift.command.Option;
+import io.airlift.command.OptionType;
+import io.airlift.command.ParseException;
+
+import java.io.Console;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.PrintStream;
+import java.lang.reflect.Constructor;
+import java.lang.reflect.InvocationTargetException;
+import java.net.URI;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.Collection;
+import java.util.Collections;
+import java.util.List;
+import java.util.concurrent.Callable;
+
+import javax.inject.Inject;
+
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import brooklyn.BrooklynVersion;
+import brooklyn.catalog.BrooklynCatalog;
+import brooklyn.entity.Application;
+import brooklyn.entity.Entity;
+import brooklyn.entity.basic.AbstractApplication;
+import brooklyn.entity.basic.AbstractEntity;
+import brooklyn.entity.basic.ApplicationBuilder;
+import brooklyn.entity.basic.Entities;
+import brooklyn.entity.basic.StartableApplication;
+import brooklyn.entity.proxying.EntitySpec;
+import brooklyn.entity.rebind.persister.PersistMode;
+import brooklyn.entity.trait.Startable;
+import brooklyn.launcher.BrooklynLauncher;
+import brooklyn.launcher.BrooklynServerDetails;
+import brooklyn.launcher.config.StopWhichAppsOnShutdown;
+import brooklyn.management.ManagementContext;
+import brooklyn.management.ha.HighAvailabilityMode;
+import brooklyn.rest.security.PasswordHasher;
+import brooklyn.util.ResourceUtils;
+import brooklyn.util.exceptions.Exceptions;
+import brooklyn.util.exceptions.FatalConfigurationRuntimeException;
+import brooklyn.util.exceptions.FatalRuntimeException;
+import brooklyn.util.exceptions.UserFacingException;
+import brooklyn.util.guava.Maybe;
+import brooklyn.util.javalang.Enums;
+import brooklyn.util.net.Networking;
+import brooklyn.util.text.Identifiers;
+import brooklyn.util.text.StringEscapes.JavaStringEscapes;
+import brooklyn.util.text.Strings;
+
+import com.google.common.annotations.Beta;
+import com.google.common.annotations.VisibleForTesting;
+import com.google.common.base.Objects;
+import com.google.common.base.Objects.ToStringHelper;
+import com.google.common.collect.ImmutableList;
+
+/**
+ * This class is the primary CLI for brooklyn.
+ * Run with the `help` argument for help.
+ * <p>
+ * This class is designed for subclassing, with subclasses typically:
+ * <li> providing their own static {@link #main(String...)} (of course) which need
simply invoke 
+ *      {@link #execCli(String[])} with the arguments 
+ * <li> returning their CLI name (e.g. "start.sh") in an overridden {@link #cliScriptName()}
+ * <li> providing an overridden {@link LaunchCommand} via {@link #cliLaunchCommand()}
if desired
+ * <li> providing any other CLI customisations by overriding {@link #cliBuilder()}
+ *      (typically calling the parent and then customizing the builder)
+ * <li> populating a custom catalog using {@link LaunchCommand#populateCatalog(BrooklynCatalog)}
+ */
+public abstract class AbstractMain {
+
+    private static final Logger log = LoggerFactory.getLogger(AbstractMain.class);
+
+    // Launch banner
+    public static final String BANNER =
+        " _                     _    _             \n" +
+        "| |__  _ __ ___   ___ | | _| |_   _ _ __ (R)\n" +
+        "| '_ \\| '__/ _ \\ / _ \\| |/ / | | | | '_ \\ \n" +
+        "| |_) | | | (_) | (_) |   <| | |_| | | | |\n" +
+        "|_.__/|_|  \\___/ \\___/|_|\\_\\_|\\__, |_| |_|\n" +
+        "                              |___/             "+BrooklynVersion.get()+"\n";
+
+    // Error codes
+    public static final int SUCCESS = 0;
+    public static final int PARSE_ERROR = 1;
+    public static final int EXECUTION_ERROR = 2;
+    public static final int CONFIGURATION_ERROR = 3;
+
+    /** abstract superclass for commands defining global options, but not arguments,
+     * as that prevents Help from being injectable in the {@link HelpCommand} subclass */
+    public static abstract class BrooklynCommand implements Callable<Void> {
+
+        @Option(type = OptionType.GLOBAL, name = { "-v", "--verbose" }, description = "Verbose
mode")
+        public boolean verbose = false;
+
+        @Option(type = OptionType.GLOBAL, name = { "-q", "--quiet" }, description = "Quiet
mode")
+        public boolean quiet = false;
+
+        @VisibleForTesting
+        protected PrintStream stdout = System.out;
+        
+        @VisibleForTesting
+        protected PrintStream stderr = System.err;
+
+        @VisibleForTesting
+        protected InputStream stdin = System.in;
+
+        public ToStringHelper string() {
+            return Objects.toStringHelper(getClass())
+                    .add("verbose", verbose)
+                    .add("quiet", quiet);
+        }
+
+        @Override
+        public String toString() {
+            return string().toString();
+        }
+    }
+    
+    /** common superclass for commands, defining global options (in our super) and extracting
the arguments */
+    public static abstract class BrooklynCommandCollectingArgs extends BrooklynCommand {
+
+        /** extra arguments */
+        @Arguments
+        public List<String> arguments = new ArrayList<String>();
+        
+        /** @return true iff there are arguments; it also sys.errs a warning in that case
 */
+        protected boolean warnIfArguments() {
+            if (arguments.isEmpty()) return false;
+            stderr.println("Invalid subcommand arguments: "+Strings.join(arguments, " "));
+            return true;
+        }
+        
+        /** throw {@link ParseException} iff there are arguments */
+        protected void failIfArguments() {
+            if (arguments.isEmpty()) return ;
+            throw new ParseException("Invalid subcommand arguments '"+Strings.join(arguments,
" ")+"'");
+        }
+        
+        @Override
+        public ToStringHelper string() {
+            return super.string()
+                    .add("arguments", arguments);
+        }
+    }
+
+    @Command(name = "help", description = "Display help for available commands")
+    public static class HelpCommand extends BrooklynCommand {
+
+        @Inject
+        public Help help;
+
+        @Override
+        public Void call() throws Exception {
+            if (log.isDebugEnabled()) log.debug("Invoked help command: {}", this);
+            return help.call();
+        }
+    }
+
+    @Command(name = "info", description = "Display information about brooklyn")
+    public static class InfoCommand extends BrooklynCommandCollectingArgs {
+        
+        @Override
+        public Void call() throws Exception {
+            if (log.isDebugEnabled()) log.debug("Invoked info command: {}", this);
+            warnIfArguments();
+
+            System.out.println(BANNER);
+            System.out.println("Version:  " + BrooklynVersion.get());
+            System.out.println("Website:  http://brooklyn.incubator.apache.org");
+            System.out.println("Source:   https://github.com/apache/incubator-brooklyn");
+            System.out.println();
+            System.out.println("Copyright 2011-2014 The Apache Software Foundation.");
+            System.out.println("Licensed under the Apache 2.0 License");
+            System.out.println();
+
+            return null;
+        }
+    }
+
+
+    /** method intended for overriding when the script filename is different 
+     * @return the name of the script the user has invoked */
+    protected String cliScriptName() {
+        return "brooklyn";
+    }
+
+    /** 
+     * Build the commands.
+     */
+    protected abstract CliBuilder<BrooklynCommand> cliBuilder();
+    
+    protected void execCli(String ...args) {
+        execCli(cliBuilder().build(), args);
+    }
+    
+    protected void execCli(Cli<BrooklynCommand> parser, String ...args) {
+        try {
+            log.debug("Parsing command line arguments: {}", Arrays.asList(args));
+            BrooklynCommand command = parser.parse(args);
+            log.debug("Executing command: {}", command);
+            command.call();
+            System.exit(SUCCESS);
+        } catch (ParseException pe) { // looks like the user typed it wrong
+            System.err.println("Parse error: " + pe.getMessage()); // display
+                                                                   // error
+            System.err.println(getUsageInfo(parser)); // display cli help
+            System.exit(PARSE_ERROR);
+        } catch (FatalConfigurationRuntimeException e) {
+            log.error("Configuration error: "+e.getMessage(), e.getCause());
+            System.err.println("Configuration error: " + e.getMessage());
+            System.exit(CONFIGURATION_ERROR);
+        } catch (FatalRuntimeException e) { // anticipated non-configuration error
+            log.error("Startup error: "+e.getMessage(), e.getCause());
+            System.err.println("Startup error: "+e.getMessage());
+            System.exit(EXECUTION_ERROR);
+        } catch (Exception e) { // unexpected error during command execution
+            log.error("Execution error: " + e.getMessage(), e);
+            System.err.println("Execution error: " + e.getMessage());
+            if (!(e instanceof UserFacingException))
+                e.printStackTrace();
+            System.exit(EXECUTION_ERROR);
+        }
+    }
+
+    protected String getUsageInfo(Cli<BrooklynCommand> parser) {
+        StringBuilder help = new StringBuilder();
+        help.append("\n");
+        Help.help(parser.getMetadata(), Collections.<String>emptyList(), help);
+        return help.toString();
+    }
+
+}

http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/e67819cf/usage/cli/src/main/java/brooklyn/cli/CloudExplorer.java
----------------------------------------------------------------------
diff --git a/usage/cli/src/main/java/brooklyn/cli/CloudExplorer.java b/usage/cli/src/main/java/brooklyn/cli/CloudExplorer.java
index 379f362..d2936c8 100644
--- a/usage/cli/src/main/java/brooklyn/cli/CloudExplorer.java
+++ b/usage/cli/src/main/java/brooklyn/cli/CloudExplorer.java
@@ -22,12 +22,9 @@ import static com.google.common.base.Preconditions.checkNotNull;
 import io.airlift.command.Cli;
 import io.airlift.command.Cli.CliBuilder;
 import io.airlift.command.Command;
-import io.airlift.command.Help;
 import io.airlift.command.Option;
 import io.airlift.command.ParseException;
 
-import java.util.Arrays;
-import java.util.Collections;
 import java.util.List;
 import java.util.Map;
 import java.util.Set;
@@ -46,10 +43,6 @@ import org.jclouds.compute.options.TemplateOptions;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
-import brooklyn.cli.Main.BrooklynCommand;
-import brooklyn.cli.Main.BrooklynCommandCollectingArgs;
-import brooklyn.cli.Main.HelpCommand;
-import brooklyn.cli.Main.InfoCommand;
 import brooklyn.location.Location;
 import brooklyn.location.LocationDefinition;
 import brooklyn.location.basic.LocationConfigKeys;
@@ -58,8 +51,6 @@ import brooklyn.location.jclouds.JcloudsLocation;
 import brooklyn.location.jclouds.JcloudsUtil;
 import brooklyn.management.internal.LocalManagementContext;
 import brooklyn.util.exceptions.FatalConfigurationRuntimeException;
-import brooklyn.util.exceptions.FatalRuntimeException;
-import brooklyn.util.exceptions.UserFacingException;
 import brooklyn.util.stream.Streams;
 
 import com.google.common.base.Objects;
@@ -76,16 +67,10 @@ import com.google.common.collect.Lists;
  * so requires less additional credential configuration. It also gives brooklyn-specific
information,
  * such as which image will be used by default in a given cloud.
  */
-public class CloudExplorer {
+public class CloudExplorer extends AbstractMain {
 
     private static final Logger log = LoggerFactory.getLogger(Main.class);
 
-    // Error codes
-    public static final int SUCCESS = 0;
-    public static final int PARSE_ERROR = 1;
-    public static final int EXECUTION_ERROR = 2;
-    public static final int CONFIGURATION_ERROR = 3;
-
     public static void main(String... args) {
         new CloudExplorer().execCli(args);
     }
@@ -442,45 +427,4 @@ public class CloudExplorer {
 
         return builder;
     }
-    
-    protected void execCli(String ...args) {
-        execCli(cliBuilder().build(), args);
-    }
-    
-    protected void execCli(Cli<BrooklynCommand> parser, String ...args) {
-        try {
-            log.debug("Parsing command line arguments: {}", Arrays.asList(args));
-            BrooklynCommand command = parser.parse(args);
-            log.debug("Executing command: {}", command);
-            command.call();
-            System.exit(SUCCESS);
-        } catch (ParseException pe) { // looks like the user typed it wrong
-            System.err.println("Parse error: " + pe.getMessage()); // display
-                                                                   // error
-            System.err.println(getUsageInfo(parser)); // display cli help
-            System.exit(PARSE_ERROR);
-        } catch (FatalConfigurationRuntimeException e) {
-            log.error("Configuration error: "+e.getMessage(), e.getCause());
-            System.err.println("Configuration error: " + e.getMessage());
-            System.exit(CONFIGURATION_ERROR);
-        } catch (FatalRuntimeException e) { // anticipated non-configuration error
-            log.error("Startup error: "+e.getMessage(), e.getCause());
-            System.err.println("Startup error: "+e.getMessage());
-            System.exit(EXECUTION_ERROR);
-        } catch (Exception e) { // unexpected error during command execution
-            log.error("Execution error: " + e.getMessage(), e);
-            System.err.println("Execution error: " + e.getMessage());
-            if (!(e instanceof UserFacingException))
-                e.printStackTrace();
-            System.exit(EXECUTION_ERROR);
-        }
-    }
-
-    protected String getUsageInfo(Cli<BrooklynCommand> parser) {
-        StringBuilder help = new StringBuilder();
-        help.append("\n");
-        Help.help(parser.getMetadata(), Collections.<String>emptyList(), help);
-        return help.toString();
-    }
-
 }

http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/e67819cf/usage/cli/src/main/java/brooklyn/cli/Main.java
----------------------------------------------------------------------
diff --git a/usage/cli/src/main/java/brooklyn/cli/Main.java b/usage/cli/src/main/java/brooklyn/cli/Main.java
index 6bd6ca8..5a8c7d4 100644
--- a/usage/cli/src/main/java/brooklyn/cli/Main.java
+++ b/usage/cli/src/main/java/brooklyn/cli/Main.java
@@ -20,36 +20,23 @@ package brooklyn.cli;
 
 import groovy.lang.GroovyClassLoader;
 import groovy.lang.GroovyShell;
-import io.airlift.command.Arguments;
 import io.airlift.command.Cli;
 import io.airlift.command.Cli.CliBuilder;
 import io.airlift.command.Command;
-import io.airlift.command.Help;
 import io.airlift.command.Option;
-import io.airlift.command.OptionType;
-import io.airlift.command.ParseException;
 
 import java.io.Console;
 import java.io.File;
 import java.io.IOException;
 import java.io.InputStream;
-import java.io.PrintStream;
 import java.lang.reflect.Constructor;
 import java.lang.reflect.InvocationTargetException;
 import java.net.URI;
-import java.util.ArrayList;
-import java.util.Arrays;
 import java.util.Collection;
-import java.util.Collections;
-import java.util.List;
-import java.util.concurrent.Callable;
-
-import javax.inject.Inject;
 
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
-import brooklyn.BrooklynVersion;
 import brooklyn.catalog.BrooklynCatalog;
 import brooklyn.entity.Application;
 import brooklyn.entity.Entity;
@@ -83,7 +70,6 @@ import brooklyn.util.text.Strings;
 
 import com.google.common.annotations.Beta;
 import com.google.common.annotations.VisibleForTesting;
-import com.google.common.base.Objects;
 import com.google.common.base.Objects.ToStringHelper;
 import com.google.common.collect.ImmutableList;
 
@@ -100,22 +86,7 @@ import com.google.common.collect.ImmutableList;
  *      (typically calling the parent and then customizing the builder)
  * <li> populating a custom catalog using {@link LaunchCommand#populateCatalog(BrooklynCatalog)}
  */
-public class Main {
-
-    // Launch banner
-    public static final String BANNER =
-        " _                     _    _             \n" +
-        "| |__  _ __ ___   ___ | | _| |_   _ _ __ (R)\n" +
-        "| '_ \\| '__/ _ \\ / _ \\| |/ / | | | | '_ \\ \n" +
-        "| |_) | | | (_) | (_) |   <| | |_| | | | |\n" +
-        "|_.__/|_|  \\___/ \\___/|_|\\_\\_|\\__, |_| |_|\n" +
-        "                              |___/             "+BrooklynVersion.get()+"\n";
-
-    // Error codes
-    public static final int SUCCESS = 0;
-    public static final int PARSE_ERROR = 1;
-    public static final int EXECUTION_ERROR = 2;
-    public static final int CONFIGURATION_ERROR = 3;
+public class Main extends AbstractMain {
 
     /** @deprecated since 0.7.0 will become private static, subclasses should define their
own logger */
     @Deprecated
@@ -125,98 +96,6 @@ public class Main {
         new Main().execCli(args);
     }
 
-    /** abstract superclass for commands defining global options, but not arguments,
-     * as that prevents Help from being injectable in the {@link HelpCommand} subclass */
-    public static abstract class BrooklynCommand implements Callable<Void> {
-
-        @Option(type = OptionType.GLOBAL, name = { "-v", "--verbose" }, description = "Verbose
mode")
-        public boolean verbose = false;
-
-        @Option(type = OptionType.GLOBAL, name = { "-q", "--quiet" }, description = "Quiet
mode")
-        public boolean quiet = false;
-
-        @VisibleForTesting
-        protected PrintStream stdout = System.out;
-        
-        @VisibleForTesting
-        protected PrintStream stderr = System.err;
-
-        @VisibleForTesting
-        protected InputStream stdin = System.in;
-
-        public ToStringHelper string() {
-            return Objects.toStringHelper(getClass())
-                    .add("verbose", verbose)
-                    .add("quiet", quiet);
-        }
-
-        @Override
-        public String toString() {
-            return string().toString();
-        }
-    }
-    
-    /** common superclass for commands, defining global options (in our super) and extracting
the arguments */
-    public static abstract class BrooklynCommandCollectingArgs extends BrooklynCommand {
-
-        /** extra arguments */
-        @Arguments
-        public List<String> arguments = new ArrayList<String>();
-        
-        /** @return true iff there are arguments; it also sys.errs a warning in that case
 */
-        protected boolean warnIfArguments() {
-            if (arguments.isEmpty()) return false;
-            stderr.println("Invalid subcommand arguments: "+Strings.join(arguments, " "));
-            return true;
-        }
-        
-        /** throw {@link ParseException} iff there are arguments */
-        protected void failIfArguments() {
-            if (arguments.isEmpty()) return ;
-            throw new ParseException("Invalid subcommand arguments '"+Strings.join(arguments,
" ")+"'");
-        }
-        
-        @Override
-        public ToStringHelper string() {
-            return super.string()
-                    .add("arguments", arguments);
-        }
-    }
-
-    @Command(name = "help", description = "Display help for available commands")
-    public static class HelpCommand extends BrooklynCommand {
-
-        @Inject
-        public Help help;
-
-        @Override
-        public Void call() throws Exception {
-            if (log.isDebugEnabled()) log.debug("Invoked help command: {}", this);
-            return help.call();
-        }
-    }
-
-    @Command(name = "info", description = "Display information about brooklyn")
-    public static class InfoCommand extends BrooklynCommandCollectingArgs {
-        
-        @Override
-        public Void call() throws Exception {
-            if (log.isDebugEnabled()) log.debug("Invoked info command: {}", this);
-            warnIfArguments();
-
-            System.out.println(BANNER);
-            System.out.println("Version:  " + BrooklynVersion.get());
-            System.out.println("Website:  http://brooklyn.incubator.apache.org");
-            System.out.println("Source:   https://github.com/apache/incubator-brooklyn");
-            System.out.println();
-            System.out.println("Copyright 2011-2014 The Apache Software Foundation.");
-            System.out.println("Licensed under the Apache 2.0 License");
-            System.out.println();
-
-            return null;
-        }
-    }
-
     @Command(name = "generate-password", description = "Generates a hashed web-console password")
     public static class GeneratePasswordCommand extends BrooklynCommandCollectingArgs {
 
@@ -886,6 +765,7 @@ public class Main {
 
     /** method intended for overriding when a different {@link Cli} is desired,
      * or when the subclass wishes to change any of the arguments */
+    @Override
     protected CliBuilder<BrooklynCommand> cliBuilder() {
         @SuppressWarnings({ "unchecked" })
         CliBuilder<BrooklynCommand> builder = Cli.<BrooklynCommand>builder(cliScriptName())
@@ -905,45 +785,4 @@ public class Main {
     protected Class<? extends BrooklynCommand> cliLaunchCommand() {
         return LaunchCommand.class;
     }
-    
-    protected void execCli(String ...args) {
-        execCli(cliBuilder().build(), args);
-    }
-    
-    protected void execCli(Cli<BrooklynCommand> parser, String ...args) {
-        try {
-            log.debug("Parsing command line arguments: {}", Arrays.asList(args));
-            BrooklynCommand command = parser.parse(args);
-            log.debug("Executing command: {}", command);
-            command.call();
-            System.exit(SUCCESS);
-        } catch (ParseException pe) { // looks like the user typed it wrong
-            System.err.println("Parse error: " + pe.getMessage()); // display
-                                                                   // error
-            System.err.println(getUsageInfo(parser)); // display cli help
-            System.exit(PARSE_ERROR);
-        } catch (FatalConfigurationRuntimeException e) {
-            log.error("Configuration error: "+e.getMessage(), e.getCause());
-            System.err.println("Configuration error: " + e.getMessage());
-            System.exit(CONFIGURATION_ERROR);
-        } catch (FatalRuntimeException e) { // anticipated non-configuration error
-            log.error("Startup error: "+e.getMessage(), e.getCause());
-            System.err.println("Startup error: "+e.getMessage());
-            System.exit(EXECUTION_ERROR);
-        } catch (Exception e) { // unexpected error during command execution
-            log.error("Execution error: " + e.getMessage(), e);
-            System.err.println("Execution error: " + e.getMessage());
-            if (!(e instanceof UserFacingException))
-                e.printStackTrace();
-            System.exit(EXECUTION_ERROR);
-        }
-    }
-
-    protected String getUsageInfo(Cli<BrooklynCommand> parser) {
-        StringBuilder help = new StringBuilder();
-        help.append("\n");
-        Help.help(parser.getMetadata(), Collections.<String>emptyList(), help);
-        return help.toString();
-    }
-
 }

http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/e67819cf/usage/cli/src/test/java/brooklyn/cli/CliTest.java
----------------------------------------------------------------------
diff --git a/usage/cli/src/test/java/brooklyn/cli/CliTest.java b/usage/cli/src/test/java/brooklyn/cli/CliTest.java
index 7b934f9..058641a 100644
--- a/usage/cli/src/test/java/brooklyn/cli/CliTest.java
+++ b/usage/cli/src/test/java/brooklyn/cli/CliTest.java
@@ -47,9 +47,9 @@ import org.testng.annotations.AfterMethod;
 import org.testng.annotations.BeforeMethod;
 import org.testng.annotations.Test;
 
-import brooklyn.cli.Main.BrooklynCommand;
+import brooklyn.cli.AbstractMain.BrooklynCommand;
+import brooklyn.cli.AbstractMain.HelpCommand;
 import brooklyn.cli.Main.GeneratePasswordCommand;
-import brooklyn.cli.Main.HelpCommand;
 import brooklyn.cli.Main.LaunchCommand;
 import brooklyn.entity.Entity;
 import brooklyn.entity.basic.AbstractApplication;

http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/e67819cf/usage/cli/src/test/java/brooklyn/cli/CloudExplorerLiveTest.java
----------------------------------------------------------------------
diff --git a/usage/cli/src/test/java/brooklyn/cli/CloudExplorerLiveTest.java b/usage/cli/src/test/java/brooklyn/cli/CloudExplorerLiveTest.java
index 2a314bb..a79ad78 100644
--- a/usage/cli/src/test/java/brooklyn/cli/CloudExplorerLiveTest.java
+++ b/usage/cli/src/test/java/brooklyn/cli/CloudExplorerLiveTest.java
@@ -33,7 +33,7 @@ import java.util.List;
 import org.testng.annotations.AfterMethod;
 import org.testng.annotations.Test;
 
-import brooklyn.cli.Main.BrooklynCommand;
+import brooklyn.cli.AbstractMain.BrooklynCommand;
 
 import com.google.common.base.Splitter;
 import com.google.common.collect.ImmutableList;


Mime
View raw message