Remove --help command

This commit is contained in:
Phillip Webb 2013-07-10 11:55:58 -07:00
parent 68f42a7c48
commit 7932456c5f
3 changed files with 8 additions and 23 deletions

View File

@ -26,7 +26,7 @@ class NoSuchCommandException extends SpringCliException {
private static final long serialVersionUID = 1L; private static final long serialVersionUID = 1L;
public NoSuchCommandException(String name) { public NoSuchCommandException(String name) {
super(String.format("%1$s: '%2$s' is not a valid command. See '%1$s --help'.", super(String.format("%1$s: '%2$s' is not a valid command. See '%1$s help'.",
SpringCli.CLI_APP, name)); SpringCli.CLI_APP, name));
} }

View File

@ -39,7 +39,7 @@ import java.util.Set;
*/ */
public class SpringCli { public class SpringCli {
public static final String CLI_APP = "spring"; public static final String CLI_APP = "spr";
private static final Set<SpringCliException.Option> NO_EXCEPTION_OPTIONS = EnumSet private static final Set<SpringCliException.Option> NO_EXCEPTION_OPTIONS = EnumSet
.noneOf(SpringCliException.Option.class); .noneOf(SpringCliException.Option.class);
@ -60,7 +60,6 @@ public class SpringCli {
this.commands.add(command); this.commands.add(command);
} }
} }
this.commands.add(0, new HelpOptionCommand());
this.commands.add(0, new HelpCommand()); this.commands.add(0, new HelpCommand());
} }
@ -71,7 +70,6 @@ public class SpringCli {
*/ */
public void setCommands(List<? extends Command> commands) { public void setCommands(List<? extends Command> commands) {
this.commands = new ArrayList<Command>(commands); this.commands = new ArrayList<Command>(commands);
this.commands.add(0, new HelpOptionCommand());
this.commands.add(0, new HelpCommand()); this.commands.add(0, new HelpCommand());
} }
@ -143,8 +141,11 @@ public class SpringCli {
Log.info(""); Log.info("");
Log.info("Available commands are:"); Log.info("Available commands are:");
for (Command command : this.commands) { for (Command command : this.commands) {
String usageHelp = command.getUsageHelp();
String description = command.getDescription();
Log.info(String.format("\n %1$s %2$-15s\n %3$s", command.getName(), Log.info(String.format("\n %1$s %2$-15s\n %3$s", command.getName(),
command.getUsageHelp(), command.getDescription())); (usageHelp == null ? "" : usageHelp), (description == null ? ""
: description)));
} }
Log.info(""); Log.info("");
Log.info("See '" + CLI_APP Log.info("See '" + CLI_APP
@ -171,15 +172,8 @@ public class SpringCli {
return rtn.toArray(new String[rtn.size()]); return rtn.toArray(new String[rtn.size()]);
} }
private class HelpOptionCommand extends HelpCommand {
@Override
public String getName() {
return "--help";
}
}
/** /**
* Internal {@link Command} used for 'help' and '--help' requests. * Internal {@link Command} used for 'help' requests.
*/ */
private class HelpCommand implements Command { private class HelpCommand implements Command {

View File

@ -10,9 +10,6 @@ import org.junit.Test;
import org.junit.rules.ExpectedException; import org.junit.rules.ExpectedException;
import org.mockito.Mock; import org.mockito.Mock;
import org.mockito.MockitoAnnotations; import org.mockito.MockitoAnnotations;
import org.springframework.cli.Command;
import org.springframework.cli.NoSuchCommandException;
import org.springframework.cli.SpringCli;
import org.springframework.cli.SpringCli.NoArgumentsException; import org.springframework.cli.SpringCli.NoArgumentsException;
import org.springframework.cli.SpringCli.NoHelpCommandArgumentsException; import org.springframework.cli.SpringCli.NoHelpCommandArgumentsException;
@ -136,7 +133,7 @@ public class SpringCliTests {
@Test @Test
public void exceptionMessages() throws Exception { public void exceptionMessages() throws Exception {
assertThat(new NoSuchCommandException("name").getMessage(), assertThat(new NoSuchCommandException("name").getMessage(),
equalTo("spring: 'name' is not a valid command. See 'spring --help'.")); equalTo("spr: 'name' is not a valid command. See 'spr help'."));
} }
@Test @Test
@ -151,12 +148,6 @@ public class SpringCliTests {
this.cli.run("help"); this.cli.run("help");
} }
@Test
public void helpLikeOption() throws Exception {
this.thrown.expect(NoHelpCommandArgumentsException.class);
this.cli.run("--help");
}
@Test @Test
public void helpUnknownCommand() throws Exception { public void helpUnknownCommand() throws Exception {
this.thrown.expect(NoSuchCommandException.class); this.thrown.expect(NoSuchCommandException.class);