Spring Shell 基本设置

Spring Shell Spring Boot About 1,531 words

框架

Spring Boot为底座,加上spring-shell-starter为框架。

不显示 Banner

application.yaml中配置

spring:
  main:
    banner-mode: off

或者设置BannerModeBanner.Mode.OFF

@SpringBootApplication
public class LearnSpringShellApplication {

    public static void main(String[] args) {
        SpringApplication app = new SpringApplication(LearnSpringShellApplication.class);
        app.setBannerMode(Banner.Mode.OFF);
        app.run(args);
    }

}

设置应用类型

spring:
  main:
    web-application-type: none

关闭日志输出

一开始启动时会输出Spring Boot的日志,可以在配置文件中关闭。

logging:
  level:
    root: off

log-startup-info设置为false可以去掉一些日志,但WARN级别日志还是会输出。建议直接root: off

spring:
  main:
    log-startup-info: false

禁用内置命令

如:禁用stacktracescript,设置enabledfalse

spring:
  shell:
    command:
      stacktrace:
        enabled: false
      script:
        enabled: false

修改提示符

默认是白色字体,可以使用AttributedStyle设置粗体等,字体颜色使用foreground方法设置,背景颜色使用background方法设置。

import org.jline.utils.AttributedString;
import org.jline.utils.AttributedStyle;
import org.springframework.shell.jline.PromptProvider;
import org.springframework.stereotype.Service;

@Service
public class CustomPromptProvider implements PromptProvider {

    @Override
    public AttributedString getPrompt() {
        return new AttributedString("my-shell:>", AttributedStyle.BOLD.foreground(AttributedStyle.GREEN));
    }

}

快捷键

  • Tab:自动补全。(IDEA等开发工具直接启动的程序无法提示)
  • Ctrl+R:搜索输入过历史执行过的命令。减少重复的输入,提高操作效率。(与Linux中的搜索输入过的命令一样)
  • Ctrl+A:跳转到行头输入。
  • Ctrl+E:跳转到行尾输入。
  • 上下箭头:输入完命令名字之后,按上下箭头可以查阅之前输入过的参数命令。
  • \:命令换行,当命令太长时,可使用\进行换行,等同于Linux中的命令换行符。
Views: 1,115 · Posted: 2023-03-06

————        END        ————

Give me a Star, Thanks:)

https://github.com/fendoudebb/LiteNote

扫描下方二维码关注公众号和小程序↓↓↓

扫描下方二维码关注公众号和小程序↓↓↓


Today On History
Browsing Refresh