The Spring Shell project provides an interactive shell that allows you to plugin your own custom commands using a Spring based programming model.
Users of the Spring Shell project can easily build a full featured shell ( aka command line) application by depending on the Spring Shell jars and adding their own commands (which come as methods on spring beans). Creating a command line application can be useful e.g. to interact with your project's REST API, or to work with local file content.
Spring Shell's features include
Then to create a simple command that could be invoked as
shell:>translate "hello world!" --from en_US --to fr_FR
bonjour monde!
assuming you'd have access to some kind of translation service that worked with Locales:
package foo;
@ShellComponent
public class TranslationCommands {
private final TranslationService service;
@Autowired
public TranslationCommands(TranslationService service) {
this.service = service;
}
@ShellMethod"Translate text from one language to another.")
public String translate(
@ShellOption(mandatory = true) String text,
@ShellOption(mandatory = true, defaultValue = "en_US") Locale from,
@ShellOption(mandatory = true) Locate to
) {
// invoke service
return service.translate(text, from, to);
}
}