0

I'm using spring shell and it's work fine. but i want to run some built in command for example exit command in a method.
How can i do that?

@Component  
 public class runCommand implements CommandMarker {

    @CliCommand(value = "exit", help = "")
    public void exit() {
      // run exit built in command to exit
    }
}
Sajad NasiriNezhad
  • 699
  • 1
  • 7
  • 27

2 Answers2

0

you can ref this, disabling_specific_commands

public static void main(String[] args) throws Exception {
        String[] disabledCommands = {"--spring.shell.command.exit.enabled=true"}; 
        String[] fullArgs = StringUtils.concatenateStringArrays(args, disabledCommands);
        SpringApplication.run(MyApp.class, fullArgs);
}
LiQIang.Feng
  • 148
  • 3
  • 11
0
  1. First you have to disable that command(In this case exit).
  2. Next create a Subclass by extending the command class.
  3. Next You can call command method from you subclass.

here is a example:

class CustomClear extends Clear {
    @ShellMethod(value="myClear")
    public void customCommand(){
        super.clear();
    }

}
Krishna
  • 353
  • 2
  • 15
  • Recommended way is to implement Clear.Command not directly extending the class, the second one didn't work for me. – RDK Mar 01 '22 at 03:56