|
|
@ -63,6 +63,7 @@ public class SpringBootstrapCli {
|
|
|
|
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());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
@ -73,6 +74,7 @@ public class SpringBootstrapCli {
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
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());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
@ -94,7 +96,8 @@ public class SpringBootstrapCli {
|
|
|
|
Set<BootstrapCliException.Option> options = NO_EXCEPTION_OPTIONS;
|
|
|
|
Set<BootstrapCliException.Option> options = NO_EXCEPTION_OPTIONS;
|
|
|
|
if (ex instanceof BootstrapCliException) {
|
|
|
|
if (ex instanceof BootstrapCliException) {
|
|
|
|
options = ((BootstrapCliException) ex).getOptions();
|
|
|
|
options = ((BootstrapCliException) ex).getOptions();
|
|
|
|
} else {
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!(ex instanceof NoHelpCommandArgumentsException)) {
|
|
|
|
errorMessage(ex.getMessage());
|
|
|
|
errorMessage(ex.getMessage());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (options.contains(BootstrapCliException.Option.SHOW_USAGE)) {
|
|
|
|
if (options.contains(BootstrapCliException.Option.SHOW_USAGE)) {
|
|
|
@ -122,37 +125,23 @@ public class SpringBootstrapCli {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private Command find(String name) {
|
|
|
|
private Command find(String name) {
|
|
|
|
boolean isOption = name.startsWith("--");
|
|
|
|
|
|
|
|
if (isOption) {
|
|
|
|
|
|
|
|
name = name.substring(2);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
for (Command candidate : this.commands) {
|
|
|
|
for (Command candidate : this.commands) {
|
|
|
|
if ((isOption && candidate.isOptionCommand() || !isOption)
|
|
|
|
if (candidate.getName().equals(name)) {
|
|
|
|
&& candidate.getName().equals(name)) {
|
|
|
|
|
|
|
|
return candidate;
|
|
|
|
return candidate;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
throw (isOption ? new NoSuchOptionException(name) : new NoSuchCommandException(
|
|
|
|
throw new NoSuchCommandException(name);
|
|
|
|
name));
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
protected void showUsage() {
|
|
|
|
protected void showUsage() {
|
|
|
|
System.out.print("usage: " + CLI_APP + " ");
|
|
|
|
System.out.print("usage: " + CLI_APP + " ");
|
|
|
|
for (Command command : this.commands) {
|
|
|
|
|
|
|
|
if (command.isOptionCommand()) {
|
|
|
|
|
|
|
|
System.out.print("[--" + command.getName() + "] ");
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
System.out.println("");
|
|
|
|
System.out.println("");
|
|
|
|
System.out.println(" <command> [<args>]");
|
|
|
|
System.out.println(" <command> [<args>]");
|
|
|
|
System.out.println("");
|
|
|
|
System.out.println("");
|
|
|
|
System.out.println("Available commands are:");
|
|
|
|
System.out.println("Available commands are:");
|
|
|
|
for (Command command : this.commands) {
|
|
|
|
for (Command command : this.commands) {
|
|
|
|
if (!command.isOptionCommand()) {
|
|
|
|
|
|
|
|
System.out.println(String.format("\n %1$s %2$-15s\n %3$s",
|
|
|
|
System.out.println(String.format("\n %1$s %2$-15s\n %3$s",
|
|
|
|
command.getName(), command.getUsageHelp(),
|
|
|
|
command.getName(), command.getUsageHelp(), command.getDescription()));
|
|
|
|
command.getDescription()));
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
System.out.println("");
|
|
|
|
System.out.println("");
|
|
|
|
System.out.println("See '" + CLI_APP
|
|
|
|
System.out.println("See '" + CLI_APP
|
|
|
@ -179,6 +168,13 @@ public class SpringBootstrapCli {
|
|
|
|
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' and '--help' requests.
|
|
|
|
*/
|
|
|
|
*/
|
|
|
@ -191,7 +187,7 @@ public class SpringBootstrapCli {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
String commandName = args[0];
|
|
|
|
String commandName = args[0];
|
|
|
|
for (Command command : SpringBootstrapCli.this.commands) {
|
|
|
|
for (Command command : SpringBootstrapCli.this.commands) {
|
|
|
|
if (!command.isOptionCommand() && command.getName().equals(commandName)) {
|
|
|
|
if (command.getName().equals(commandName)) {
|
|
|
|
System.out.println(CLI_APP + " " + command.getName() + " - "
|
|
|
|
System.out.println(CLI_APP + " " + command.getName() + " - "
|
|
|
|
+ command.getDescription());
|
|
|
|
+ command.getDescription());
|
|
|
|
System.out.println();
|
|
|
|
System.out.println();
|
|
|
@ -212,11 +208,6 @@ public class SpringBootstrapCli {
|
|
|
|
return "help";
|
|
|
|
return "help";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
|
|
|
public boolean isOptionCommand() {
|
|
|
|
|
|
|
|
return false;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
@Override
|
|
|
|
public String getDescription() {
|
|
|
|
public String getDescription() {
|
|
|
|
return "Get help on commands";
|
|
|
|
return "Get help on commands";
|
|
|
|