spring-shell icon indicating copy to clipboard operation
spring-shell copied to clipboard

Extend "script" command to accept classpath references

Open tkrah opened this issue 11 months ago • 2 comments

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.

tkrah avatar Mar 06 '24 20:03 tkrah

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 avatar Mar 10 '24 14:03 jvalkeal

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

jvalkeal avatar Mar 10 '24 14:03 jvalkeal