From f2cdb8c69fc00f7a24eedaf5edf4ad4111f24603 Mon Sep 17 00:00:00 2001 From: Dave Syer Date: Tue, 10 Dec 2013 13:38:52 +0000 Subject: [PATCH] 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. --- .../main/java/org/springframework/boot/cli/CommandFactory.java | 2 +- .../src/main/java/org/springframework/boot/cli/SpringCli.java | 2 +- .../boot/cli/command/DefaultCommandFactory.java | 3 ++- 3 files changed, 4 insertions(+), 3 deletions(-) diff --git a/spring-boot-cli/src/main/java/org/springframework/boot/cli/CommandFactory.java b/spring-boot-cli/src/main/java/org/springframework/boot/cli/CommandFactory.java index c5b3a29ffd..5126c830be 100644 --- a/spring-boot-cli/src/main/java/org/springframework/boot/cli/CommandFactory.java +++ b/spring-boot-cli/src/main/java/org/springframework/boot/cli/CommandFactory.java @@ -31,6 +31,6 @@ public interface CommandFactory { * Returns the CLI {@link Command}s. * @return The commands */ - Collection getCommands(); + Collection getCommands(SpringCli cli); } diff --git a/spring-boot-cli/src/main/java/org/springframework/boot/cli/SpringCli.java b/spring-boot-cli/src/main/java/org/springframework/boot/cli/SpringCli.java index 5a86d12549..3e3323e87f 100644 --- a/spring-boot-cli/src/main/java/org/springframework/boot/cli/SpringCli.java +++ b/spring-boot-cli/src/main/java/org/springframework/boot/cli/SpringCli.java @@ -60,7 +60,7 @@ public class SpringCli { private void setCommands(Iterable iterable) { this.commands = new ArrayList(); for (CommandFactory factory : iterable) { - for (Command command : factory.getCommands()) { + for (Command command : factory.getCommands(this)) { this.commands.add(command); } } diff --git a/spring-boot-cli/src/main/java/org/springframework/boot/cli/command/DefaultCommandFactory.java b/spring-boot-cli/src/main/java/org/springframework/boot/cli/command/DefaultCommandFactory.java index ca05222207..0b453ed43e 100644 --- a/spring-boot-cli/src/main/java/org/springframework/boot/cli/command/DefaultCommandFactory.java +++ b/spring-boot-cli/src/main/java/org/springframework/boot/cli/command/DefaultCommandFactory.java @@ -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 getCommands() { + public Collection getCommands(SpringCli cli) { return DEFAULT_COMMANDS; }