Adam Erstelle
Adam Erstelle

Reputation: 2513

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?

Upvotes: 0

Views: 2198

Answers (2)

user3980519
user3980519

Reputation:

If you want to exclude some build-in commands. Pass the --disableInternalCommands parameter to the main function (see previous post) and add the org.springframework.shell.commands package to the spring component scan path and use the exculde filter to remove the build-in commands.

spring-shell-plugin.xml

<beans>
    <context:component-scan base-package="com.foo.bar.commands, org.springframework.shell.commands" >
        <context:exclude-filter type="regex" expression=".*(ScriptCommands|DateCommands|SystemPropertyCommands|VersionCommands)" />
    </context:component-scan>
</beans>

Upvotes: 0

Adam Erstelle
Adam Erstelle

Reputation: 2513

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.

Upvotes: 4

Related Questions