Change interface of CommandFactory slightly

It's super useful to get a reference to the current SpringCli
instance in the CommandFactory. Potentially implementations can
react to the properties of the Cli, or wrap it into something
more complex.

...supports the likely implementation of the REPL use
case that @jbrisbin has been working on.
This commit is contained in:
Dave Syer 2013-12-10 13:38:52 +00:00
parent e55e8f9863
commit f2cdb8c69f
3 changed files with 4 additions and 3 deletions

View File

@ -31,6 +31,6 @@ public interface CommandFactory {
* Returns the CLI {@link Command}s.
* @return The commands
*/
Collection<Command> getCommands();
Collection<Command> getCommands(SpringCli cli);
}

View File

@ -60,7 +60,7 @@ public class SpringCli {
private void setCommands(Iterable<CommandFactory> iterable) {
this.commands = new ArrayList<Command>();
for (CommandFactory factory : iterable) {
for (Command command : factory.getCommands()) {
for (Command command : factory.getCommands(this)) {
this.commands.add(command);
}
}

View File

@ -22,6 +22,7 @@ import java.util.List;
import org.springframework.boot.cli.Command;
import org.springframework.boot.cli.CommandFactory;
import org.springframework.boot.cli.SpringCli;
/**
* Default implementation of {@link CommandFactory}.
@ -35,7 +36,7 @@ public class DefaultCommandFactory implements CommandFactory {
new TestCommand(), new GrabCommand());
@Override
public Collection<Command> getCommands() {
public Collection<Command> getCommands(SpringCli cli) {
return DEFAULT_COMMANDS;
}