Spring Shell 2.0.0

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.
Features

Spring Shell’s features include

A simple, annotation driven, programming model to contribute custom commands

Use of Spring Boot auto-configuration functionality as the basis for a command plugin strategy

Tab completion, colorization, and script execution

Customization of command prompt, shell history file name, handling of results and errors

Dynamic enablement of commands based on domain specific criteria

Integration with the bean validation API

Already built-in commands, such as clear screen, gorgeous help, exit

ASCII art Tables, with formatting, alignment, fancy borders, etc.

Spring Boot Config

Start your Spring Shell application by adding the appropriate dependency:
Maven

org.springframework.shell spring-shell-starter 2.0.0.RELEASE

Gradle

dependencies {
compile ‘org.springframework.shell:spring-shell-starter:2.0.0.RELEASE’
}

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

}

Spring Initializr
Quickstart Your Project
Bootstrap your application with Spring Initializr.

发布了0 篇原创文章 · 获赞 125 · 访问量 4683
展开阅读全文

没有更多推荐了,返回首页

©️2019 CSDN 皮肤主题: 大白 设计师: CSDN官方博客

分享到微信朋友圈

×

扫一扫,手机浏览