Executing a single command and exiting from Spring Shell 2

Just to add, I found another way of doing this, doesn't give you the option to run in interactive mode but using your profiles above you can of course swap the configuration. Please note I'm using lombok and jool (just in case anyone copy pastes and gets funny issues!)

Entry

@SpringBootApplication
public class Righter {

    public static void main(String[] args) {
        SpringApplication.run(Righter.class, args);
    }

    @Bean
    public ApplicationRunner shellRunner(Shell shell) {
        return new NonInteractiveShellRunner(shell);
    }

Application runner:

@Order(0)
public class NonInteractiveShellRunner implements ApplicationRunner{

    private final Shell shell;

    public NonInteractiveShellRunner(Shell shell) {
        this.shell = shell;
    }

    @Override
    public void run(ApplicationArguments args) throws Exception {
        shell.run(new CommandInputProvider(args.getSourceArgs()));
    }

    public static class PredefinedInputProvider implements InputProvider{

        private final Input input;
        private boolean commandExecuted = false;

        public PredefinedInputProvider(String[] args) {
            this.input = new PredefinedInput(args);
        }

        @Override
        public Input readInput() {
            if (!commandExecuted){
                commandExecuted=true;
                return input;
            }
            return new PredefinedInput(new String[]{"exit"});
        }

        @AllArgsConstructor
        private static class PredefinedInput implements Input{

            private final String[] args;

            @Override
            public String rawText() {
                return Seq.of(args).toString(" ");
            }

            @Override
            public List<String> words(){
                return Arrays.asList(args);
            }
        }

    }

}