Add PathSearch component
- New PatchSearch component - Allow user to define base directory for search - Show (using single select list) search results - Allow user to define search string - Implement algorithms(start with exact-match and fuzzy-match) from fuzzy search tool (fzf) - Sample "component path search" and change "component path" to "component path input" - Fixes #556
This commit is contained in:
@@ -30,7 +30,10 @@ import org.springframework.shell.component.ConfirmationInput.ConfirmationInputCo
|
||||
import org.springframework.shell.component.MultiItemSelector;
|
||||
import org.springframework.shell.component.MultiItemSelector.MultiItemSelectorContext;
|
||||
import org.springframework.shell.component.PathInput;
|
||||
import org.springframework.shell.component.PathSearch;
|
||||
import org.springframework.shell.component.PathInput.PathInputContext;
|
||||
import org.springframework.shell.component.PathSearch.PathSearchConfig;
|
||||
import org.springframework.shell.component.PathSearch.PathSearchContext;
|
||||
import org.springframework.shell.component.SingleItemSelector;
|
||||
import org.springframework.shell.component.SingleItemSelector.SingleItemSelectorContext;
|
||||
import org.springframework.shell.component.StringInput;
|
||||
@@ -57,7 +60,7 @@ public class ComponentCommands extends AbstractShellComponent {
|
||||
return "Got value " + context.getResultValue();
|
||||
}
|
||||
|
||||
@ShellMethod(key = "component path", value = "Path input", group = "Components")
|
||||
@ShellMethod(key = "component path input", value = "Path input", group = "Components")
|
||||
public String pathInput() {
|
||||
PathInput component = new PathInput(getTerminal(), "Enter value");
|
||||
component.setResourceLoader(getResourceLoader());
|
||||
@@ -66,6 +69,31 @@ public class ComponentCommands extends AbstractShellComponent {
|
||||
return "Got value " + context.getResultValue();
|
||||
}
|
||||
|
||||
@ShellMethod(key = "component path search", value = "Path search", group = "Components")
|
||||
public String pathSearch(
|
||||
@ShellOption(defaultValue = ShellOption.NULL) Integer maxPathsShow,
|
||||
@ShellOption(defaultValue = ShellOption.NULL) Integer maxPathsSearch,
|
||||
@ShellOption(defaultValue = "true") boolean searchForward,
|
||||
@ShellOption(defaultValue = "false") boolean searchCaseSensitive,
|
||||
@ShellOption(defaultValue = "false") boolean searchNormalize
|
||||
) {
|
||||
PathSearchConfig config = new PathSearch.PathSearchConfig();
|
||||
if (maxPathsShow != null) {
|
||||
config.setMaxPathsShow(maxPathsShow);
|
||||
}
|
||||
if (maxPathsSearch != null) {
|
||||
config.setMaxPathsSearch(maxPathsSearch);
|
||||
}
|
||||
config.setSearchForward(searchForward);
|
||||
config.setSearchCaseSensitive(searchCaseSensitive);
|
||||
config.setSearchNormalize(searchNormalize);
|
||||
PathSearch component = new PathSearch(getTerminal(), "Enter value", config);
|
||||
component.setResourceLoader(getResourceLoader());
|
||||
component.setTemplateExecutor(getTemplateExecutor());
|
||||
PathSearchContext context = component.run(PathSearchContext.empty());
|
||||
return "Got value " + context.getResultValue();
|
||||
}
|
||||
|
||||
@ShellMethod(key = "component confirmation", value = "Confirmation input", group = "Components")
|
||||
public String confirmationInput(boolean no) {
|
||||
ConfirmationInput component = new ConfirmationInput(getTerminal(), "Enter value", !no);
|
||||
|
||||
Reference in New Issue
Block a user