spring-projects / spring-shell

Spring based shell

Home Page:http://projects.spring.io/spring-shell/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Extend "script" command to accept classpath references

tkrah opened this issue · 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.

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!

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