update sample application
This commit is contained in:
@@ -17,22 +17,6 @@ dependencies {
|
||||
testCompile "junit:junit:$junitVersion"
|
||||
}
|
||||
|
||||
task copyDependency(type: Copy) {
|
||||
into "$buildDir/libs/dependency"
|
||||
from configurations.runtime
|
||||
}
|
||||
|
||||
project.ext.springShellJar = configurations.runtime.find { file -> file.name.contains("spring-shell")}
|
||||
//println("spring shell name is:" + project.ext.springShellJar.name)
|
||||
|
||||
project.ext.manifestClasspath = "dependency/" + springShellJar.name + " "
|
||||
project.ext.manifestClasspath = project.ext.manifestClasspath + configurations.runtime.collect{ File file -> "dependency/"+file.name}.join(' ')
|
||||
|
||||
jar {
|
||||
baseName "helloworld"
|
||||
manifest {
|
||||
attributes 'Main-Class' : 'org.springframework.shell.Bootstrap', "Class-Path" : project.ext.manifestClasspath
|
||||
}
|
||||
}
|
||||
mainClassName = "org.springframework.shell.Bootstrap"
|
||||
|
||||
defaultTasks 'clean', 'build', 'copyDependency'
|
||||
|
||||
@@ -1,6 +1,8 @@
|
||||
package org.springframework.shell.samples.helloworld.commands;
|
||||
|
||||
|
||||
import java.util.logging.Logger;
|
||||
|
||||
import org.springframework.shell.core.CommandMarker;
|
||||
import org.springframework.shell.core.annotation.CliAvailabilityIndicator;
|
||||
import org.springframework.shell.core.annotation.CliCommand;
|
||||
@@ -11,26 +13,27 @@ import org.springframework.stereotype.Component;
|
||||
public class HelloWorldCommands implements CommandMarker {
|
||||
|
||||
|
||||
protected final Logger LOG = Logger.getLogger(getClass().getName());
|
||||
|
||||
@CliAvailabilityIndicator({"hw echo"})
|
||||
public boolean isCommandAvailable() {
|
||||
return true;
|
||||
}
|
||||
|
||||
@CliCommand(value = "hw echo", help = "Print a hello world message")
|
||||
@CliCommand(value = "hw complex", help = "Print a complex hello world message")
|
||||
public void hello(
|
||||
@CliOption(key = { "message" }, mandatory = true, help = "The hello world message") final String message,
|
||||
@CliOption(key = { "name1"}, mandatory = true, help = "The hello world name1 ") final String name1,
|
||||
@CliOption(key = { "name2","name22" }, mandatory = true, help = "The hello world name2 ") final String name2,
|
||||
@CliOption(key = { "time" }, mandatory = false, specifiedDefaultValue="now", help = "The hello world time ") final String time,
|
||||
@CliOption(key = { "location" }, mandatory = false, help = "The hello world location ") final String location) {
|
||||
System.out.println("Hello world " + message + ", name1: " + name1 +
|
||||
", name2:" + name2 + ". time:" + time + ".location: " + location);
|
||||
@CliOption(key = { "name1"}, mandatory = true, help = "Say hello to the first name") final String name1,
|
||||
@CliOption(key = { "name2" }, mandatory = true, help = "Say hello to a second name") final String name2,
|
||||
@CliOption(key = { "time" }, mandatory = false, specifiedDefaultValue="now", help = "When you are saying hello") final String time,
|
||||
@CliOption(key = { "location" }, mandatory = false, help = "Where you are saying hello") final String location) {
|
||||
LOG.info("Hello " + name1 + " and " + name2 + ". Your special message is " + message + ". time=[" + time + "] location=[" + location + "]");
|
||||
}
|
||||
|
||||
@CliCommand(value = "hw auto", help = "Print a hello world message")
|
||||
public void autao(
|
||||
@CliCommand(value = "hw enum", help = "Print a simple hello world message from an enumerated value")
|
||||
public void eenum(
|
||||
@CliOption(key = { "message" }, mandatory = true, help = "The hello world message") final MessageType message){
|
||||
System.out.println("Hello world " + message);
|
||||
LOG.info("Hello. You special enumerated message is " + message);
|
||||
}
|
||||
|
||||
enum MessageType {
|
||||
|
||||
@@ -39,11 +39,9 @@ public class MyBannerProvider extends DefaultBannerProvider
|
||||
public String getBanner() {
|
||||
StringBuffer buf = new StringBuffer();
|
||||
buf.append("=======================================" + StringUtils.LINE_SEPARATOR);
|
||||
buf.append("* *"+ StringUtils.LINE_SEPARATOR);
|
||||
buf.append("* *"+ StringUtils.LINE_SEPARATOR);
|
||||
buf.append("* vHelper *" +StringUtils.LINE_SEPARATOR);
|
||||
buf.append("* *"+ StringUtils.LINE_SEPARATOR);
|
||||
buf.append("* *"+ StringUtils.LINE_SEPARATOR);
|
||||
buf.append("* *"+ StringUtils.LINE_SEPARATOR);
|
||||
buf.append("* HelloWorld *" +StringUtils.LINE_SEPARATOR);
|
||||
buf.append("* *"+ StringUtils.LINE_SEPARATOR);
|
||||
buf.append("=======================================" + StringUtils.LINE_SEPARATOR);
|
||||
buf.append("Verson:" + this.getVersion());
|
||||
return buf.toString();
|
||||
@@ -61,12 +59,12 @@ public class MyBannerProvider extends DefaultBannerProvider
|
||||
* @see org.springframework.shell.plugin.BannerProvider#getWelcomeMessage()
|
||||
*/
|
||||
public String getWelcomeMessage() {
|
||||
return "Welcome to vHelper CLI";
|
||||
return "Welcome to HelloWorld CLI";
|
||||
}
|
||||
|
||||
@Override
|
||||
public String name() {
|
||||
return "vHelper";
|
||||
return "helloworld";
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -28,12 +28,11 @@ import org.springframework.stereotype.Component;
|
||||
@Order(Ordered.HIGHEST_PRECEDENCE)
|
||||
public class MyPromptProvider extends DefaultPromptProvider {
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.springframework.shell.plugin.PromptProvider#getPromptText()
|
||||
*/
|
||||
public String getPromptText() {
|
||||
return "vHelper>";
|
||||
@Override
|
||||
public String getPrompt() {
|
||||
return "hw-shell>";
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public String name() {
|
||||
|
||||
Reference in New Issue
Block a user