spring-projects / spring-shell

Spring based shell
http://projects.spring.io/spring-shell/
Apache License 2.0
723 stars 395 forks source link

PathInput treats existing directory as an ERROR #874

Open dkamenov opened 11 months ago

dkamenov commented 11 months ago

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()

Screenshot 2023-09-28 165413

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());
  }
jvalkeal commented 11 months ago

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.