changeset 1811:e2b74104bfc7

Add links to the user guide in cli Reviewed-by: omajid, jerboaa Review-thread: http://icedtea.classpath.org/pipermail/thermostat/2015-September/016524.html Review-thread: http://icedtea.classpath.org/pipermail/thermostat/2015-June/014181.html PR2654
author Severin Gehwolf <sgehwolf@redhat.com>
date Mon, 28 Sep 2015 16:46:24 +0200
parents c99480ceed02
children 5db8eb6c7811
files launcher/src/main/java/com/redhat/thermostat/launcher/internal/LocaleResources.java launcher/src/main/java/com/redhat/thermostat/launcher/internal/ShellCommand.java launcher/src/main/resources/com/redhat/thermostat/launcher/internal/strings.properties launcher/src/test/java/com/redhat/thermostat/launcher/internal/ShellCommandTest.java
diffstat 4 files changed, 48 insertions(+), 31 deletions(-) [+]
line wrap: on
line diff
--- a/launcher/src/main/java/com/redhat/thermostat/launcher/internal/LocaleResources.java	Tue Sep 22 19:13:52 2015 +0200
+++ b/launcher/src/main/java/com/redhat/thermostat/launcher/internal/LocaleResources.java	Mon Sep 28 16:46:24 2015 +0200
@@ -53,6 +53,7 @@
 
     COMMAND_HELP_COMMAND_LIST_HEADER,
 
+    COMMAND_SHELL_USER_GUIDE,
     COMMAND_SHELL_IO_EXCEPTION,
 
     OPTION_DB_URL_DESC,
--- a/launcher/src/main/java/com/redhat/thermostat/launcher/internal/ShellCommand.java	Tue Sep 22 19:13:52 2015 +0200
+++ b/launcher/src/main/java/com/redhat/thermostat/launcher/internal/ShellCommand.java	Mon Sep 28 16:46:24 2015 +0200
@@ -55,6 +55,7 @@
 import org.osgi.framework.BundleContext;
 import org.osgi.framework.ServiceReference;
 
+import com.redhat.thermostat.common.ApplicationInfo;
 import com.redhat.thermostat.common.Version;
 import com.redhat.thermostat.common.cli.AbstractCommand;
 import com.redhat.thermostat.common.cli.CommandContext;
@@ -133,6 +134,9 @@
 
         try {
             ctx.getConsole().getOutput().println(version.getVersionInfo());
+            String userGuideUrl = new ApplicationInfo().getUserGuide();
+            String userGuideMessage = t.localize(LocaleResources.COMMAND_SHELL_USER_GUIDE, userGuideUrl).getContents();
+            ctx.getConsole().getOutput().println(userGuideMessage);
             shellMainLoop(ctx, history, term);
         } catch (IOException ex) {
             throw new CommandException(t.localize(LocaleResources.COMMAND_SHELL_IO_EXCEPTION), ex);
--- a/launcher/src/main/resources/com/redhat/thermostat/launcher/internal/strings.properties	Tue Sep 22 19:13:52 2015 +0200
+++ b/launcher/src/main/resources/com/redhat/thermostat/launcher/internal/strings.properties	Mon Sep 28 16:46:24 2015 +0200
@@ -15,6 +15,7 @@
 
 COMMAND_HELP_COMMAND_LIST_HEADER = list of commands:\n\n
 
+COMMAND_SHELL_USER_GUIDE = Please see the User Guide at {0}
 COMMAND_SHELL_IO_EXCEPTION = IOException caught during Thermostat shell session.
 
 OPTION_DB_URL_DESC = connect to the given URL
@@ -31,7 +32,7 @@
 LAUNCHER_MALFORMED_URL = Unsupported storage URL: {0}
 LAUNCHER_CONNECTION_ERROR = Could not connect to: {0}
 LAUNCHER_FIRST_LAUNCH_MSG = This appears to be the first time Thermostat has been launched.\n\
- Please run ''{0}''.
+ Please run ''{0}''. Please see the User Guide for more details: {1}.
 
 INVALID_DB_URL = Warning: Shell encountered a invalid database connection url: {0} Connection to storage may be corrupted.
 
--- a/launcher/src/test/java/com/redhat/thermostat/launcher/internal/ShellCommandTest.java	Tue Sep 22 19:13:52 2015 +0200
+++ b/launcher/src/test/java/com/redhat/thermostat/launcher/internal/ShellCommandTest.java	Mon Sep 28 16:46:24 2015 +0200
@@ -46,6 +46,7 @@
 import java.io.File;
 import java.io.IOException;
 import java.util.ArrayList;
+import java.util.Arrays;
 import java.util.Collection;
 import java.util.EnumSet;
 
@@ -54,6 +55,7 @@
 import jline.TerminalFactory.Type;
 import jline.UnixTerminal;
 import jline.console.history.PersistentHistory;
+
 import org.apache.commons.cli.Option;
 import org.apache.commons.cli.Options;
 import org.junit.After;
@@ -69,6 +71,7 @@
 import com.redhat.thermostat.common.cli.CommandException;
 import com.redhat.thermostat.common.cli.SimpleArguments;
 import com.redhat.thermostat.common.config.experimental.ConfigurationInfoSource;
+import com.redhat.thermostat.common.utils.StringUtils;
 import com.redhat.thermostat.launcher.Launcher;
 import com.redhat.thermostat.test.TestCommandContextFactory;
 
@@ -76,7 +79,8 @@
 
     static private final String VERSION = "Thermostat some version";
     static private final String VERSION_OUTPUT = VERSION + "\n";
-
+    static private final String USER_GUIDE_OUTPUT = "Please see the User Guide at http://icedtea.classpath.org/wiki/Thermostat/UserGuide\n";
+    static private final String INTRO = VERSION_OUTPUT + USER_GUIDE_OUTPUT;
     static private final String PROMPT = "Thermostat " + ShellPrompt.DEFAULT_DISCONNECTED_TOKEN + " > ";
 
     private ShellCommand cmd;
@@ -149,7 +153,7 @@
         Arguments args = new SimpleArguments();
         CommandContext ctx = ctxFactory.createContext(args);
         cmd.run(ctx);
-        assertEquals(VERSION_OUTPUT + PROMPT + "quit\n", ctxFactory.getOutput());
+        assertEquals(INTRO + PROMPT + "quit\n", ctxFactory.getOutput());
         assertEquals("", ctxFactory.getError());
     }
 
@@ -160,7 +164,7 @@
         Arguments args = new SimpleArguments();
         CommandContext ctx = ctxFactory.createContext(args);
         cmd.run(ctx);
-        assertEquals(VERSION_OUTPUT + PROMPT + "q\n", ctxFactory.getOutput());
+        assertEquals(INTRO + PROMPT + "q\n", ctxFactory.getOutput());
         assertEquals("", ctxFactory.getError());
     }
 
@@ -171,7 +175,7 @@
         Arguments args = new SimpleArguments();
         CommandContext ctx = ctxFactory.createContext(args);
         cmd.run(ctx);
-        assertEquals(VERSION_OUTPUT + PROMPT, ctxFactory.getOutput());
+        assertEquals(INTRO + PROMPT, ctxFactory.getOutput());
         assertEquals("", ctxFactory.getError());
     }
 
@@ -182,7 +186,7 @@
         Arguments args = new SimpleArguments();
         CommandContext ctx = ctxFactory.createContext(args);
         cmd.run(ctx);
-        assertEquals(VERSION_OUTPUT + PROMPT + "\n" + PROMPT + "exit\n", ctxFactory.getOutput());
+        assertEquals(INTRO + PROMPT + "\n" + PROMPT + "exit\n", ctxFactory.getOutput());
     }
 
     @Test
@@ -206,7 +210,7 @@
         CommandContext ctx = ctxFactory.createContext(args);
         cmd.run(ctx);
 
-        assertEquals(VERSION_OUTPUT + PROMPT + "old-history-value\n" + PROMPT + "exit\n", ctxFactory.getOutput());
+        assertEquals(INTRO + PROMPT + "old-history-value\n" + PROMPT + "exit\n", ctxFactory.getOutput());
         assertEquals("", ctxFactory.getError());
 
         verify(launcher).run(new String[] {"old-history-value"}, true);
@@ -232,7 +236,7 @@
         verify(mockHistory).add("add-to-history");
         verify(mockHistory).flush();
 
-        assertEquals(VERSION_OUTPUT + PROMPT + "add-to-history\n" + PROMPT + "exit\n", ctxFactory.getOutput());
+        assertEquals(INTRO + PROMPT + "add-to-history\n" + PROMPT + "exit\n", ctxFactory.getOutput());
         assertEquals("", ctxFactory.getError());
     }
 
@@ -274,16 +278,21 @@
         CommandContext ctx = ctxFactory.createContext(args);
         cmd.run(ctx);
 
-        String tabOutput = getTabOutput(ctxFactory);
+        String tabOutput = getTabOutput(getOutputWithoutIntro(ctxFactory));
 
         assertTrue(tabOutput.contains("test1"));
         assertTrue(tabOutput.contains("test2longname"));
         assertEquals("", ctxFactory.getError());
     }
 
-    private String getTabOutput(final TestCommandContextFactory ctxFactory) {
+    private String getOutputWithoutIntro(final TestCommandContextFactory ctxFactory) {
         String[] allOutput = ctxFactory.getOutput().split("\n");
+        String[] outputWithoutIntro = Arrays.copyOfRange(allOutput, 2, allOutput.length);
+        return StringUtils.join("\n", Arrays.asList(outputWithoutIntro));
+    }
 
+    private String getTabOutput(final String outputToProcess) {
+        String[] allOutput = outputToProcess.split("\n");
         String tabOutput = "";
         for (String output : allOutput) {
             if (!output.startsWith("Thermostat")) {
@@ -306,7 +315,7 @@
         CommandContext ctx = ctxFactory.createContext(args);
         cmd.run(ctx);
 
-        String tabOutput = getTabOutput(ctxFactory);
+        String tabOutput = getTabOutput(getOutputWithoutIntro(ctxFactory));
         assertTrue(tabOutput.contains("test1"));
         assertTrue(tabOutput.contains("test2longname"));
         assertEquals("", ctxFactory.getError());
@@ -325,9 +334,10 @@
         CommandContext ctx = ctxFactory.createContext(args);
         cmd.run(ctx);
 
-        String tabOutput = getTabOutput(ctxFactory);
+        String usefulOutput = getOutputWithoutIntro(ctxFactory);
+        String tabOutput = getTabOutput(usefulOutput);
         assertTrue(tabOutput.length() == 0);
-        assertEquals(PROMPT + "q", ctxFactory.getOutput().split("\n")[2]);
+        assertEquals(PROMPT + "q", usefulOutput.split("\n")[1]);
         assertEquals("", ctxFactory.getError());
     }
 
@@ -344,7 +354,7 @@
         CommandContext ctx = ctxFactory.createContext(args);
         cmd.run(ctx);
 
-        String tabOutput = getTabOutput(ctxFactory);
+        String tabOutput = getTabOutput(getOutputWithoutIntro(ctxFactory));
         assertTrue(tabOutput.contains("--Add"));
         assertTrue(tabOutput.contains("--remove"));
         assertTrue(tabOutput.contains("--test"));
@@ -368,11 +378,10 @@
         CommandContext ctx = ctxFactory.createContext(args);
         cmd.run(ctx);
 
-        String tabOutput = getTabOutput(ctxFactory);
+        String tabOutput = getTabOutput(getOutputWithoutIntro(ctxFactory));
         assertTrue(tabOutput.contains("--copy"));
         assertTrue(tabOutput.contains("--copy&paste"));
         assertEquals("", ctxFactory.getError());
-
     }
 
     @Test
@@ -388,9 +397,10 @@
         CommandContext ctx = ctxFactory.createContext(args);
         cmd.run(ctx);
 
-        String tabOutput = getTabOutput(ctxFactory);
+        String usefulOutput = getOutputWithoutIntro(ctxFactory);
+        String tabOutput = getTabOutput(usefulOutput);
         assertTrue(tabOutput.length() == 0);
-        assertEquals(PROMPT + "exit", ctxFactory.getOutput().split("\n")[2]);
+        assertEquals(PROMPT + "exit", usefulOutput.split("\n")[1]);
         assertEquals("", ctxFactory.getError());
 
     }
@@ -408,9 +418,10 @@
         CommandContext ctx = ctxFactory.createContext(args);
         cmd.run(ctx);
 
-        String tabOutput = getTabOutput(ctxFactory);
+        String usefulOutput = getOutputWithoutIntro(ctxFactory);
+        String tabOutput = getTabOutput(usefulOutput);
         assertTrue(tabOutput.length() == 0);
-        assertEquals(PROMPT + "exit", ctxFactory.getOutput().split("\n")[2]);
+        assertEquals(PROMPT + "exit", usefulOutput.split("\n")[1]);
         assertEquals("", ctxFactory.getError());
 
     }
@@ -428,7 +439,7 @@
         CommandContext ctx = ctxFactory.createContext(args);
         cmd.run(ctx);
 
-        String tabOutput = getTabOutput(ctxFactory);
+        String tabOutput = getTabOutput(getOutputWithoutIntro(ctxFactory));
         assertTrue(tabOutput.contains("--Paste"));
         assertTrue(tabOutput.contains("--copy"));
         assertTrue(tabOutput.contains("--copy&paste"));
@@ -454,7 +465,7 @@
         CommandContext ctx = ctxFactory.createContext(args);
         cmd.run(ctx);
 
-        String tabOutput = getTabOutput(ctxFactory);
+        String tabOutput = getTabOutput(getOutputWithoutIntro(ctxFactory));
         String inline = getTabbedInline(ctxFactory, input);
 
         assertEquals(0, tabOutput.length());
@@ -477,7 +488,7 @@
         CommandContext ctx = ctxFactory.createContext(args);
         cmd.run(ctx);
 
-        String tabOutput = getTabOutput(ctxFactory);
+        String tabOutput = getTabOutput(getOutputWithoutIntro(ctxFactory));
         String inline = getTabbedInline(ctxFactory, input);
 
         assertTrue(tabOutput.length() != 0);
@@ -500,7 +511,7 @@
         CommandContext ctx = ctxFactory.createContext(args);
         cmd.run(ctx);
 
-        String tabOutput = getTabOutput(ctxFactory);
+        String tabOutput = getTabOutput(getOutputWithoutIntro(ctxFactory));
         String inline = getTabbedInline(ctxFactory, input);
 
         assertEquals(0, tabOutput.length());
@@ -523,7 +534,7 @@
         CommandContext ctx = ctxFactory.createContext(args);
         cmd.run(ctx);
 
-        String tabOutput = getTabOutput(ctxFactory);
+        String tabOutput = getTabOutput(getOutputWithoutIntro(ctxFactory));
         String inline = getTabbedInline(ctxFactory, input);
 
         assertTrue(tabOutput.contains("--copy"));
@@ -549,7 +560,7 @@
         CommandContext ctx = ctxFactory.createContext(args);
         cmd.run(ctx);
 
-        String tabOutput = getTabOutput(ctxFactory);
+        String tabOutput = getTabOutput(getOutputWithoutIntro(ctxFactory));
         assertTrue(tabOutput.contains(filename));
         assertEquals("", ctxFactory.getError());
     }
@@ -571,7 +582,7 @@
         CommandContext ctx = ctxFactory.createContext(args);
         cmd.run(ctx);
 
-        String tabOutput = getTabOutput(ctxFactory);
+        String tabOutput = getTabOutput(getOutputWithoutIntro(ctxFactory));
         assertTrue(tabOutput.contains(filename));
         assertEquals("", ctxFactory.getError());
     }
@@ -593,7 +604,7 @@
         CommandContext ctx = ctxFactory.createContext(args);
         cmd.run(ctx);
 
-        String tabOutput = getTabOutput(ctxFactory);
+        String tabOutput = getTabOutput(getOutputWithoutIntro(ctxFactory));
         assertFalse(tabOutput.contains(filename));
         assertEquals("", tabOutput);
         assertEquals("", ctxFactory.getError());
@@ -619,7 +630,7 @@
         cmd.run(ctx);
 
         String inline = getTabbedInline(ctxFactory, input);
-        String tabOutput = getTabOutput(ctxFactory);
+        String tabOutput = getTabOutput(getOutputWithoutIntro(ctxFactory));
 
         setupCommandInfoSource();
         assertEquals(0, tabOutput.length());
@@ -651,7 +662,7 @@
         cmd.run(ctx);
 
         String inline = getTabbedInline(ctxFactory, input);
-        String tabOutput = getTabOutput(ctxFactory);
+        String tabOutput = getTabOutput(getOutputWithoutIntro(ctxFactory));
 
         assertTrue(tabOutput.contains(filename));
         assertFalse(inline.contains(filename));
@@ -684,7 +695,7 @@
         cmd.run(ctx);
 
         String inline = getTabbedInline(ctxFactory, input);
-        String tabOutput = getTabOutput(ctxFactory);
+        String tabOutput = getTabOutput(getOutputWithoutIntro(ctxFactory));
 
         assertTrue(tabOutput.contains(filename));
         assertFalse(inline.contains(filename));