Mercurial > hg > release > thermostat-0.15
changeset 1164:fd4db8e4dcba
Make command help message environment sensitive
Reviewed-by: jerboaa
Review-thread: http://icedtea.classpath.org/pipermail/thermostat/2013-July/007316.html
author | Omair Majid <omajid@redhat.com> |
---|---|
date | Fri, 12 Jul 2013 14:25:15 -0400 |
parents | f55fbcde5880 |
children | 9c787a04da94 |
files | integration-tests/src/test/java/com/redhat/thermostat/itest/CliTest.java launcher/src/main/java/com/redhat/thermostat/launcher/internal/HelpCommand.java |
diffstat | 2 files changed, 21 insertions(+), 11 deletions(-) [+] |
line wrap: on
line diff
--- a/integration-tests/src/test/java/com/redhat/thermostat/itest/CliTest.java Fri Jul 12 10:03:42 2013 -0400 +++ b/integration-tests/src/test/java/com/redhat/thermostat/itest/CliTest.java Fri Jul 12 14:25:15 2013 -0400 @@ -189,7 +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" + + "\n" + "thermostat shell\n\n"; assertEquals(expectedOut, stdOut); }
--- a/launcher/src/main/java/com/redhat/thermostat/launcher/internal/HelpCommand.java Fri Jul 12 10:03:42 2013 -0400 +++ b/launcher/src/main/java/com/redhat/thermostat/launcher/internal/HelpCommand.java Fri Jul 12 14:25:15 2013 -0400 @@ -132,24 +132,34 @@ PrintWriter pw = new PrintWriter(ctx.getConsole().getOutput()); Options options = info.getOptions(); String usage = APP_NAME + " " + info.getUsage() + "\n" + info.getDescription(); - String header = getAvailabilityNote(info) + "\n" + APP_NAME + " " + info.getName(); + String header = ""; + if (isAvailabilityNoteNeeded(info)) { + header = header + getAvailabilityNote(info); + } + header = header + "\n" + APP_NAME + " " + info.getName(); helpFormatter.printHelp(pw, 80, usage, header, options, 2, 4, null); pw.flush(); } + private boolean isAvailabilityNoteNeeded(CommandInfo info) { + return !info.getEnvironments().contains(currentEnvironment); + } + + /** Describe where command is available */ 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"); - } + // there are two mutually exclusive environments: if an availability + // note is needed, it will just be about one + 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; }