Commit 98e4008b authored by Phillip Webb's avatar Phillip Webb

Don't display hint command in options help

Fixes gh-471
parent 2929d33e
...@@ -44,6 +44,7 @@ public class SpringCli { ...@@ -44,6 +44,7 @@ public class SpringCli {
runner.addCommand(new ShellCommand()); runner.addCommand(new ShellCommand());
runner.addCommand(new HintCommand(runner)); runner.addCommand(new HintCommand(runner));
runner.setOptionCommands(HelpCommand.class, VersionCommand.class); runner.setOptionCommands(HelpCommand.class, VersionCommand.class);
runner.setHiddenCommands(HintCommand.class);
int exitCode = runner.runAndHandleErrors(args); int exitCode = runner.runAndHandleErrors(args);
if (exitCode != 0) { if (exitCode != 0) {
......
...@@ -46,6 +46,8 @@ public class CommandRunner implements Iterable<Command> { ...@@ -46,6 +46,8 @@ public class CommandRunner implements Iterable<Command> {
private Class<?>[] optionCommandClasses = {}; private Class<?>[] optionCommandClasses = {};
private Class<?>[] hiddenCommandClasses = {};
/** /**
* Create a new {@link CommandRunner} instance. * Create a new {@link CommandRunner} instance.
* @param name the name of the runner or {@code null} * @param name the name of the runner or {@code null}
...@@ -94,6 +96,16 @@ public class CommandRunner implements Iterable<Command> { ...@@ -94,6 +96,16 @@ public class CommandRunner implements Iterable<Command> {
this.optionCommandClasses = commandClasses; this.optionCommandClasses = commandClasses;
} }
/**
* Set the command classes which should be hidden (i.e. executed but not displayed in
* the available commands list).
* @param commandClasses the classes of hidden commands
*/
public void setHiddenCommands(Class<?>... commandClasses) {
Assert.notNull(commandClasses, "CommandClasses must not be null");
this.hiddenCommandClasses = commandClasses;
}
/** /**
* Returns if the specified command is an option command. * Returns if the specified command is an option command.
* @param command the command to test * @param command the command to test
...@@ -101,8 +113,16 @@ public class CommandRunner implements Iterable<Command> { ...@@ -101,8 +113,16 @@ public class CommandRunner implements Iterable<Command> {
* @see #setOptionCommands(Class...) * @see #setOptionCommands(Class...)
*/ */
public boolean isOptionCommand(Command command) { public boolean isOptionCommand(Command command) {
for (Class<?> optionCommandClass : this.optionCommandClasses) { return isCommandInstanceOf(command, this.optionCommandClasses);
if (optionCommandClass.isInstance(command)) { }
private boolean isHiddenCommand(Command command) {
return isCommandInstanceOf(command, this.hiddenCommandClasses);
}
private boolean isCommandInstanceOf(Command command, Class<?>[] commandClasses) {
for (Class<?> commandClass : commandClasses) {
if (commandClass.isInstance(command)) {
return true; return true;
} }
} }
...@@ -249,7 +269,7 @@ public class CommandRunner implements Iterable<Command> { ...@@ -249,7 +269,7 @@ public class CommandRunner implements Iterable<Command> {
Log.info(""); Log.info("");
Log.info("Available commands are:"); Log.info("Available commands are:");
for (Command command : this.commands) { for (Command command : this.commands) {
if (!isOptionCommand(command)) { if (!isOptionCommand(command) && !isHiddenCommand(command)) {
String usageHelp = command.getUsageHelp(); String usageHelp = command.getUsageHelp();
String description = command.getDescription(); 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(),
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment