系统相关
首页 > 系统相关> > springshell自定义clear命令

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);
    }

}

 

标签:shell,自定义,clear,springframework,org,springshell,import,public
来源: https://www.cnblogs.com/chencoolandclear/p/16345780.html