Search code examples
javaspringspring-shell

Remove commands from Spring-Shell


I'm looking to build a diagnostic utility using Spring-Shell for a tech support team. The idea is to drop the executable jar on a system, run the app and have it run through a bunch of diagnostics.

I want to disable/remove some of the commands that get auto-loaded from org.springframework.shell.commands package, and I can't quite figure out how to do that. Is it possible?

Failing that, I would like to just customize the help command so that I can output my own help. I can't even get that to work, though I was able to figure out how to remove them from the list of commands that display when the user hits TAB.

@CliAvailabilityIndicator({"!", "//", "script","system"})
public boolean isAvailable()
{
    return false;
}

Any ideas?


Solution

  • Turns out, according to http://docs.spring.io/spring-shell/docs/current/reference/htmlsingle/#d4e173, spring shell apps can be called with a command line argument to disable internal commands. so what I did is in my application's main method I add the argument myself.

    public static void main(String[] args) throws IOException
    {
        ArrayList<String> argsList = new ArrayList<String>(Arrays.asList(args));
        argsList.add("--disableInternalCommands");
        String[] argsArray = new String[argsList.size()];
        argsArray = argsList.toArray(argsArray);
        Bootstrap.main(argsArray);
    }
    

    There's probably a cleaner way to add the argument to the args parameter...but that's outside the scope of this question.