spring-projects / spring-shell

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

Extend "script" command to accept classpath references #1014

Open tkrah opened 5 months ago

tkrah commented 5 months ago

The script command does accept files only at the moment.

If the command would use something like this:

public void script(String ref) throws Exception {
        Resource res = getApplicationContext().getResource(ref);
        Reader reader = new StringReader(new String(res.getInputStream().readAllBytes(), StandardCharsets.UTF_8));
        try (FileInputProvider inputProvider = new FileInputProvider(reader, parser)) {
            getShell().run(inputProvider);
        }
}

the script could be something like: "classpath:scripts/runthis" or "file:...." - all things possible which the app context can resolve. To be backwards compatible you could prefix "ref" always with "file:.." if nothing else is specified on the argument.

jvalkeal commented 5 months ago

Thanks for a proposal and I think it's definitely something what shell could support. We're probably not going to work in this feature but if you think it's important to you then we'd welcome a PR!

jvalkeal commented 5 months ago

Just a note for script runner behaviour in current main (aka 3.3.x) #1017 disabled this runner on default.