ConfirmationInput should have resultValue
- Add flow hooks to ConfirmationInput so that user is able to pass a flag from an options so that component can bypass interactive mode. - Fixes #445
This commit is contained in:
@@ -15,6 +15,7 @@
|
||||
*/
|
||||
package org.springframework.shell.samples.standard;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
@@ -24,7 +25,9 @@ import java.util.stream.IntStream;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.shell.component.flow.ComponentFlow;
|
||||
import org.springframework.shell.component.flow.ResultMode;
|
||||
import org.springframework.shell.component.flow.SelectItem;
|
||||
import org.springframework.shell.component.flow.ComponentFlow.ComponentFlowResult;
|
||||
import org.springframework.shell.standard.AbstractShellComponent;
|
||||
import org.springframework.shell.standard.ShellComponent;
|
||||
import org.springframework.shell.standard.ShellMethod;
|
||||
@@ -36,8 +39,8 @@ public class ComponentFlowCommands extends AbstractShellComponent {
|
||||
@Autowired
|
||||
private ComponentFlow.Builder componentFlowBuilder;
|
||||
|
||||
@ShellMethod(key = "flow showcase", value = "Showcase", group = "Flow")
|
||||
public void showcase() {
|
||||
@ShellMethod(key = "flow showcase1", value = "Showcase", group = "Flow")
|
||||
public void showcase1() {
|
||||
Map<String, String> single1SelectItems = new HashMap<>();
|
||||
single1SelectItems.put("key1", "value1");
|
||||
single1SelectItems.put("key2", "value2");
|
||||
@@ -69,6 +72,67 @@ public class ComponentFlowCommands extends AbstractShellComponent {
|
||||
flow.run();
|
||||
}
|
||||
|
||||
@ShellMethod(key = "flow showcase2", value = "Showcase with options", group = "Flow")
|
||||
public String showcase2(
|
||||
@ShellOption(help = "Field1 value", defaultValue = ShellOption.NULL) String field1,
|
||||
@ShellOption(help = "Field2 value", defaultValue = ShellOption.NULL) String field2,
|
||||
@ShellOption(help = "Confirmation1 value", defaultValue = ShellOption.NULL) Boolean confirmation1,
|
||||
@ShellOption(help = "Path1 value", defaultValue = ShellOption.NULL) String path1,
|
||||
@ShellOption(help = "Single1 value", defaultValue = ShellOption.NULL) String single1,
|
||||
@ShellOption(help = "Multi1 value", defaultValue = ShellOption.NULL) List<String> multi1
|
||||
) {
|
||||
Map<String, String> single1SelectItems = new HashMap<>();
|
||||
single1SelectItems.put("key1", "value1");
|
||||
single1SelectItems.put("key2", "value2");
|
||||
List<SelectItem> multi1SelectItems = Arrays.asList(SelectItem.of("key1", "value1"),
|
||||
SelectItem.of("key2", "value2"), SelectItem.of("key3", "value3"));
|
||||
List<String> multi1ResultValues = multi1 != null ? multi1 : new ArrayList<>();
|
||||
ComponentFlow flow = componentFlowBuilder.clone().reset()
|
||||
.withStringInput("field1")
|
||||
.name("Field1")
|
||||
.defaultValue("defaultField1Value")
|
||||
.resultValue(field1)
|
||||
.resultMode(ResultMode.ACCEPT)
|
||||
.and()
|
||||
.withStringInput("field2")
|
||||
.name("Field2")
|
||||
.resultValue(field2)
|
||||
.resultMode(ResultMode.ACCEPT)
|
||||
.and()
|
||||
.withConfirmationInput("confirmation1")
|
||||
.name("Confirmation1")
|
||||
.resultValue(confirmation1)
|
||||
.resultMode(ResultMode.ACCEPT)
|
||||
.and()
|
||||
.withPathInput("path1")
|
||||
.name("Path1")
|
||||
.resultValue(path1)
|
||||
.resultMode(ResultMode.ACCEPT)
|
||||
.and()
|
||||
.withSingleItemSelector("single1")
|
||||
.name("Single1")
|
||||
.selectItems(single1SelectItems)
|
||||
.resultValue(single1)
|
||||
.resultMode(ResultMode.ACCEPT)
|
||||
.and()
|
||||
.withMultiItemSelector("multi1")
|
||||
.name("Multi1")
|
||||
.selectItems(multi1SelectItems)
|
||||
.resultValues(multi1ResultValues)
|
||||
.resultMode(ResultMode.ACCEPT)
|
||||
.and()
|
||||
.build();
|
||||
ComponentFlowResult result = flow.run();
|
||||
StringBuilder buf = new StringBuilder();
|
||||
result.getContext().stream().forEach(e -> {
|
||||
buf.append(e.getKey());
|
||||
buf.append(" = ");
|
||||
buf.append(e.getValue());
|
||||
buf.append("\n");
|
||||
});
|
||||
return buf.toString();
|
||||
}
|
||||
|
||||
@ShellMethod(key = "flow conditional", value = "Second component based on first", group = "Flow")
|
||||
public void conditional() {
|
||||
Map<String, String> single1SelectItems = new HashMap<>();
|
||||
|
||||
Reference in New Issue
Block a user