# HG changeset patch # User Omair Majid # Date 1373637366 14400 # Node ID ca38f9e22bd5219d135e235a932e00537f1869fa # Parent 1d6300d7232fc17874cfe0d80ea91466af158d57 PR1444: Help should say that connect/disconnect are to be used inside the shell only Reviewed-by: jerboaa Review-thread: http://icedtea.classpath.org/pipermail/thermostat/2013-May/006812.html diff -r 1d6300d7232f -r ca38f9e22bd5 integration-tests/src/test/java/com/redhat/thermostat/itest/CliTest.java --- a/integration-tests/src/test/java/com/redhat/thermostat/itest/CliTest.java Thu Jul 11 18:00:21 2013 -0600 +++ b/integration-tests/src/test/java/com/redhat/thermostat/itest/CliTest.java Fri Jul 12 09:56:06 2013 -0400 @@ -178,7 +178,7 @@ assertTrue(usage.matches("^usage: thermostat shell$")); String description = lines[1]; assertTrue(description.matches("^\\s+launches the Thermostat interactive shell$")); - assertTrue(lines[2].matches("thermostat shell")); + assertTrue(lines[3].matches("thermostat shell")); } @Test @@ -189,6 +189,7 @@ String expectedOut = "Could not parse options: Unrecognized option: --foo\n" + "usage: thermostat shell\n" + " launches the Thermostat interactive shell\n" + + "Note: this command is only supported outside the shell\n" + "thermostat shell\n\n"; assertEquals(expectedOut, stdOut); } diff -r 1d6300d7232f -r ca38f9e22bd5 launcher/src/main/java/com/redhat/thermostat/launcher/internal/HelpCommand.java --- a/launcher/src/main/java/com/redhat/thermostat/launcher/internal/HelpCommand.java Thu Jul 11 18:00:21 2013 -0600 +++ b/launcher/src/main/java/com/redhat/thermostat/launcher/internal/HelpCommand.java Fri Jul 12 09:56:06 2013 -0400 @@ -38,6 +38,7 @@ import java.io.PrintWriter; import java.util.ArrayList; +import java.util.Arrays; import java.util.Collection; import java.util.Collections; import java.util.Comparator; @@ -50,6 +51,7 @@ import com.redhat.thermostat.common.cli.CommandContext; import com.redhat.thermostat.common.cli.AbstractCommand; import com.redhat.thermostat.common.cli.TableRenderer; +import com.redhat.thermostat.launcher.internal.CommandInfo.Environment; import com.redhat.thermostat.shared.locale.Translate; public class HelpCommand extends AbstractCommand { @@ -118,12 +120,28 @@ PrintWriter pw = new PrintWriter(ctx.getConsole().getOutput()); Options options = info.getOptions(); - String name = APP_NAME + " " + info.getName(); String usage = APP_NAME + " " + info.getUsage() + "\n" + info.getDescription(); - helpFormatter.printHelp(pw, 80, usage, name, options, 2, 4, null); + String header = getAvailabilityNote(info) + "\n" + APP_NAME + " " + info.getName(); + helpFormatter.printHelp(pw, 80, usage, header, options, 2, 4, null); pw.flush(); } + private String getAvailabilityNote(CommandInfo info) { + String availabilityNote = ""; + + // Availability note is only needed if the command is not available everywhere + if (!info.getEnvironments().containsAll(Arrays.asList(Environment.values()))) { + if (info.getEnvironments().contains(Environment.SHELL)) { + availabilityNote = translator.localize(LocaleResources.COMMAND_AVAILABLE_INSIDE_SHELL).getContents(); + } else if (info.getEnvironments().contains(Environment.CLI)) { + availabilityNote = translator.localize(LocaleResources.COMMAND_AVAILABLE_OUTSIDE_SHELL).getContents(); + } else { + throw new AssertionError("Need to handle a third environment"); + } + } + return availabilityNote; + } + @Override public boolean isStorageRequired() { return false; diff -r 1d6300d7232f -r ca38f9e22bd5 launcher/src/main/java/com/redhat/thermostat/launcher/internal/LocaleResources.java --- a/launcher/src/main/java/com/redhat/thermostat/launcher/internal/LocaleResources.java Thu Jul 11 18:00:21 2013 -0600 +++ b/launcher/src/main/java/com/redhat/thermostat/launcher/internal/LocaleResources.java Fri Jul 12 09:56:06 2013 -0400 @@ -44,7 +44,9 @@ UNKNOWN_COMMAND, COMMAND_COULD_NOT_LOAD_BUNDLES, COMMAND_DESCRIBED_BUT_NOT_AVAILALBE, + COMMAND_AVAILABLE_INSIDE_SHELL, COMMAND_AVAILABLE_INSIDE_SHELL_ONLY, + COMMAND_AVAILABLE_OUTSIDE_SHELL, COMMAND_AVAILABLE_OUTSIDE_SHELL_ONLY, COMMAND_HELP_COMMAND_LIST_HEADER, diff -r 1d6300d7232f -r ca38f9e22bd5 launcher/src/main/resources/com/redhat/thermostat/launcher/internal/strings.properties --- a/launcher/src/main/resources/com/redhat/thermostat/launcher/internal/strings.properties Thu Jul 11 18:00:21 2013 -0600 +++ b/launcher/src/main/resources/com/redhat/thermostat/launcher/internal/strings.properties Fri Jul 12 09:56:06 2013 -0400 @@ -2,7 +2,13 @@ UNKNOWN_COMMAND = unknown command ''{0}''\n COMMAND_COULD_NOT_LOAD_BUNDLES = Could not load necessary bundles for {0} COMMAND_DESCRIBED_BUT_NOT_AVAILALBE = ERROR: Information about the command {0} is provided, but the command itself is not available. Was the Command object registered as an OSGi service? Was the bundle providing the command activated? +# Used in help to indicate where command is available +COMMAND_AVAILABLE_INSIDE_SHELL = Note: this command is only supported inside the shell +# Error Message COMMAND_AVAILABLE_INSIDE_SHELL_ONLY = The {0} command is not supported from outside the thermostat shell. +# Used in help to indicate where command is available +COMMAND_AVAILABLE_OUTSIDE_SHELL = Note: this command is only supported outside the shell +# Error Message COMMAND_AVAILABLE_OUTSIDE_SHELL_ONLY = The {0} command is not supported from within the thermostat shell. COMMAND_HELP_COMMAND_LIST_HEADER = list of commands:\n\n diff -r 1d6300d7232f -r ca38f9e22bd5 launcher/src/test/java/com/redhat/thermostat/launcher/internal/HelpCommandTest.java --- a/launcher/src/test/java/com/redhat/thermostat/launcher/internal/HelpCommandTest.java Thu Jul 11 18:00:21 2013 -0600 +++ b/launcher/src/test/java/com/redhat/thermostat/launcher/internal/HelpCommandTest.java Fri Jul 12 09:56:06 2013 -0400 @@ -44,6 +44,7 @@ import java.util.ArrayList; import java.util.Arrays; import java.util.Collection; +import java.util.EnumSet; import org.apache.commons.cli.Options; import org.junit.Before; @@ -51,6 +52,7 @@ import com.redhat.thermostat.common.cli.Arguments; import com.redhat.thermostat.common.cli.SimpleArguments; +import com.redhat.thermostat.launcher.internal.CommandInfo.Environment; import com.redhat.thermostat.test.TestCommandContextFactory; public class HelpCommandTest { @@ -129,6 +131,7 @@ when(testCommandInfo.getUsage()).thenReturn("usage of test command"); when(testCommandInfo.getDescription()).thenReturn("description of test command"); when(testCommandInfo.getOptions()).thenReturn(new Options()); + when(testCommandInfo.getEnvironments()).thenReturn(EnumSet.of(Environment.CLI)); when(infos.getCommandInfo("test1")).thenReturn(testCommandInfo); @@ -141,6 +144,7 @@ String actual = ctxFactory.getOutput(); assertEquals("usage: thermostat usage of test command\n" + " description of test command\n" + + "Note: this command is only supported outside the shell\n" + "thermostat test1\n\n", actual); } diff -r 1d6300d7232f -r ca38f9e22bd5 launcher/src/test/java/com/redhat/thermostat/launcher/internal/LauncherImplTest.java --- a/launcher/src/test/java/com/redhat/thermostat/launcher/internal/LauncherImplTest.java Thu Jul 11 18:00:21 2013 -0600 +++ b/launcher/src/test/java/com/redhat/thermostat/launcher/internal/LauncherImplTest.java Fri Jul 12 09:56:06 2013 -0400 @@ -369,6 +369,7 @@ String expected = "Could not parse options: Unrecognized option: --argNotAccepted\n" + "usage: thermostat test1 <--arg1 > [--arg2 ]\n" + " description 1\n" + + "\n" + "thermostat test1\n" + " --arg1 \n" + " --arg2 \n" @@ -381,6 +382,7 @@ String expected = "Missing required option: --arg1\n" + "usage: thermostat test1 <--arg1 > [--arg2 ]\n" + " description 1\n" + + "\n" + "thermostat test1\n" + " --arg1 \n" + " --arg2 \n" @@ -399,6 +401,7 @@ String expected = "Could not parse options: Missing argument for option: arg1\n" + "usage: thermostat test1 <--arg1 > [--arg2 ]\n" + " description 1\n" + + "\n" + "thermostat test1\n" + " --arg1 \n" + " --arg2 \n"