spring-shell
spring-shell copied to clipboard
PathInput treats existing directory as an ERROR
I have a use case whereby the user should select an existing directory, however they see x Directory exists
which looks like an error message. It seems this behavior is hardcoded in PathInput.checkPath()
Observed on 2.1.12
code sample
protected Optional<Path> promptForPath(String prompt) {
PathInput component = new PathInput(getTerminal(), prompt);
component.setResourceLoader(getResourceLoader());
component.setTemplateExecutor(getTemplateExecutor());
return Optional.ofNullable(component.run(PathInputContext.empty()).getResultValue());
}
Right we need to add a way to customise how that check works.
Workaround would be to copy existing template https://github.com/spring-projects/spring-shell/blob/main/spring-shell-core/src/main/resources/org/springframework/shell/component/path-input-default.stg, modify and package it and set it in a same way as it's done in https://github.com/spring-projects/spring-shell/blob/6dd038830f8d3416bcb034a5717323bfd76ec838/spring-shell-core/src/main/java/org/springframework/shell/component/PathInput.java#L62.