zoukankan      html  css  js  c++  java
  • Ability to configure CLI as non-repl

    @SpringBootApplication
    public class NonInteractiveCliApp {
    
        /**
         * Configures non-interactive shell mode.
         */
        @Configuration
        public static class NonInteractiveConfig {
    
            @Autowired
            private ConfigurableEnvironment environment;
    
            @PostConstruct
            public void disableInteractiveShell() {
                InteractiveShellApplicationRunner.disable(environment);
            }
    
            @Bean
            @Lazy
            public NonInteractiveShellApplicationRunner nonInteractiveShellApplicationRunner(Parser parser, Shell shell) {
                return new NonInteractiveShellApplicationRunner(parser, shell);
            }
    
        }
    
        @Order(NonInteractiveShellApplicationRunner.PRECEDENCE)
        @RequiredArgsConstructor
        public static class NonInteractiveShellApplicationRunner implements ApplicationRunner {
    
            public static final int PRECEDENCE = InteractiveShellApplicationRunner.PRECEDENCE - 100;
    
            private final Parser parser;
            private final Shell shell;
    
            @Override
            public void run(ApplicationArguments args) throws Exception {
                String rawArgs = Arrays.stream(args.getSourceArgs()).collect(Collectors.joining(" "));
                Reader reader = new StringReader(rawArgs);
    
                // Use FileInputProvider to read the input arguments (it has little to do with files in fact).
                InputProvider inputProvider = new FileInputProvider(reader, parser);
                shell.run(inputProvider);
            }
        }
    
        public static void main(String[] args) {
            ConfigurableApplicationContext context = new SpringApplicationBuilder(NonInteractiveCliApp.class)
                    .web(WebApplicationType.NONE)
                    .run(args);
        }
    }

    原文链接: https://github.com/spring-projects/spring-shell/issues/241

  • 相关阅读:
    数値処理
    linux使用rsync+inotify-tools+ssh实现文件实时同步
    Linux内核分析第九次作业
    Linux内核原理第八次作业
    Linux内核分析第七次作业
    Linux内核分析第六次作业
    《Linux内核原理与设计》第五周作业
    《Linux内核原理与分析》第四次作业
    Linux内核分析第三次作业
    Linux内核分析第二次作业
  • 原文地址:https://www.cnblogs.com/sanshuiqing/p/14713140.html
Copyright © 2011-2022 走看看