springshell自定义clear命令

springshell如在修改clear分组时需要重写clear命令

重写clear命令,并实现Clear.Command

import org.jline.terminal.Terminal;
import org.jline.utils.InfoCmp;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Lazy;
import org.springframework.shell.standard.ShellCommandGroup;
import org.springframework.shell.standard.ShellComponent;
import org.springframework.shell.standard.ShellMethod;
import org.springframework.shell.standard.commands.Clear;

@ShellComponent
@ShellCommandGroup(value = "SpringShellDemo Commands")  // 自定义分组名
public class ClearCommand implements Clear.Command {

    @Autowired
    @Lazy
    private Terminal terminal;

    public ClearCommand() {
    }

    @ShellMethod("Clear the shell screen.")
    public void clear() {
        this.terminal.puts(InfoCmp.Capability.clear_screen, new Object[0]);
    }

    public interface Command {
    }
}

启动类中禁用springshell内置命令:

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.util.StringUtils;

@SpringBootApplication
public class SpringShellDemoApplication {

    public static void main(String[] args) {String[] disabledCommands = {"--spring.shell.command.clear.enabled=false"};
        String[] fullArgs = StringUtils.concatenateStringArrays(args, disabledCommands);
        SpringApplication.run(SpringShellDemoApplication.class, fullArgs);
    }

}

 

posted @ 2022-06-06 01:17  刀霸汉  阅读(55)  评论(0编辑  收藏  举报