changeset 327:65ffb89c766b

Mention that a command is unknown in addition to printing out help Reviewed-by: vanaltj Review-thread: http://icedtea.classpath.org/pipermail/thermostat/2012-May/001434.html
author Omair Majid <omajid@redhat.com>
date Wed, 23 May 2012 12:03:47 -0400
parents cf01f141c88b
children 8dff701e098a
files common/src/main/java/com/redhat/thermostat/common/cli/Launcher.java common/src/main/java/com/redhat/thermostat/common/cli/LauncherImpl.java common/src/test/java/com/redhat/thermostat/common/cli/LauncherTest.java
diffstat 3 files changed, 21 insertions(+), 5 deletions(-) [+]
line wrap: on
line diff
--- a/common/src/main/java/com/redhat/thermostat/common/cli/Launcher.java	Tue May 22 21:56:27 2012 +0200
+++ b/common/src/main/java/com/redhat/thermostat/common/cli/Launcher.java	Wed May 23 12:03:47 2012 -0400
@@ -36,7 +36,14 @@
 
 package com.redhat.thermostat.common.cli;
 
+/**
+ * Launcher is the main entry point for the command line "thermostat" program.
+ */
 public interface Launcher {
 
+    /**
+     * Invoked when thermostat starts
+     * @param command line arguments to the program
+     */
     void run(String[] args);
 }
--- a/common/src/main/java/com/redhat/thermostat/common/cli/LauncherImpl.java	Tue May 22 21:56:27 2012 +0200
+++ b/common/src/main/java/com/redhat/thermostat/common/cli/LauncherImpl.java	Wed May 23 12:03:47 2012 -0400
@@ -49,6 +49,8 @@
 
 public class LauncherImpl implements Launcher {
 
+    private static final String UNKNOWN_COMMAND_MESSAGE = "unknown command '%s'\n";
+
     private ClientPreferences prefs = new ClientPreferences();
 
     private String[] args;
@@ -66,7 +68,10 @@
         try {
             initLogging();
             this.args = args;
-            if (hasNoArguments() || unknownCommand()) {
+            if (hasNoArguments()) {
+                runHelpCommand();
+            } else if (unknownCommand()) {
+                cmdCtxFactory.getConsole().getOutput().print(String.format(UNKNOWN_COMMAND_MESSAGE, args[0]));
                 runHelpCommand();
             } else {
                 runCommandFromArguments();
--- a/common/src/test/java/com/redhat/thermostat/common/cli/LauncherTest.java	Tue May 22 21:56:27 2012 +0200
+++ b/common/src/test/java/com/redhat/thermostat/common/cli/LauncherTest.java	Wed May 23 12:03:47 2012 -0400
@@ -158,7 +158,8 @@
 
     @Test
     public void testMainBadCommand1() {
-        String expected = "list of commands:\n\n"
+        String expected = "unknown command '--help'\n"
+            + "list of commands:\n\n"
             + " help          show help for a given command or help overview\n"
             + " test1         description 1\n"
             + " test2         description 2\n"
@@ -168,7 +169,8 @@
 
     @Test
     public void testMainBadCommand2() {
-        String expected = "list of commands:\n\n"
+        String expected = "unknown command '-help'\n"
+            + "list of commands:\n\n"
             + " help          show help for a given command or help overview\n"
             + " test1         description 1\n"
             + " test2         description 2\n"
@@ -178,7 +180,8 @@
 
     @Test
     public void testMainBadCommand3() {
-        String expected = "list of commands:\n\n"
+        String expected = "unknown command 'foobarbaz'\n"
+            + "list of commands:\n\n"
             + " help          show help for a given command or help overview\n"
             + " test1         description 1\n"
             + " test2         description 2\n"
@@ -188,7 +191,8 @@
 
     @Test
     public void testMainBadCommand4() {
-        String expected = "list of commands:\n\n"
+        String expected = "unknown command 'foo'\n"
+            + "list of commands:\n\n"
             + " help          show help for a given command or help overview\n"
             + " test1         description 1\n"
             + " test2         description 2\n"