Skip to content

Commit 944f4e9

Browse files
committed
Implement v1.0.0
1 parent 5fb8a73 commit 944f4e9

8 files changed

Lines changed: 810 additions & 160 deletions

File tree

.gitignore

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
HELP.md
2+
/target/
3+
!.mvn/wrapper/maven-wrapper.jar
4+
5+
### STS ###
6+
.apt_generated
7+
.classpath
8+
.factorypath
9+
.project
10+
.settings
11+
.springBeans
12+
.sts4-cache
13+
14+
### IntelliJ IDEA ###
15+
.idea
16+
*.iws
17+
*.iml
18+
*.ipr
19+
20+
### NetBeans ###
21+
/nbproject/private/
22+
/nbbuild/
23+
/dist/
24+
/nbdist/
25+
/.nb-gradle/
26+
/build/
27+
28+
### VS Code ###
29+
.vscode/

LICENSE

Lines changed: 668 additions & 159 deletions
Large diffs are not rendered by default.

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
11
# shell-cli
2-
A combination of Sping Shell and CommandLineRunner
2+
A combo Spring Shell and Spring CommandLineRunner (ApplicationRunner)

pom.xml

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
3+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
4+
<modelVersion>4.0.0</modelVersion>
5+
<parent>
6+
<groupId>org.springframework.boot</groupId>
7+
<artifactId>spring-boot-starter-parent</artifactId>
8+
<version>2.0.2.RELEASE</version>
9+
<relativePath/>
10+
</parent>
11+
<groupId>com.batiwo.shell</groupId>
12+
<artifactId>shell-cli</artifactId>
13+
<version>1.0.0</version>
14+
<name>shell-cli</name>
15+
<description>Combine Spring Shell and CommandLineRunner application</description>
16+
17+
<properties>
18+
<java.version>1.8</java.version>
19+
</properties>
20+
21+
<dependencies>
22+
<dependency>
23+
<groupId>org.springframework.shell</groupId>
24+
<artifactId>spring-shell-starter</artifactId>
25+
<version>2.0.0.RELEASE</version>
26+
</dependency>
27+
</dependencies>
28+
29+
<build>
30+
<plugins>
31+
<plugin>
32+
<groupId>org.springframework.boot</groupId>
33+
<artifactId>spring-boot-maven-plugin</artifactId>
34+
<configuration>
35+
<executable>true</executable>
36+
</configuration>
37+
</plugin>
38+
</plugins>
39+
</build>
40+
</project>
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
package com.batiwo.shell;
2+
3+
import org.springframework.beans.factory.annotation.Autowired;
4+
import org.springframework.boot.ApplicationArguments;
5+
import org.springframework.boot.ApplicationRunner;
6+
import org.springframework.core.annotation.Order;
7+
import org.springframework.shell.Shell;
8+
import org.springframework.stereotype.Component;
9+
10+
@Order(0)
11+
@Component
12+
public class SampleApplicationRunner implements ApplicationRunner {
13+
14+
private final Shell shell;
15+
16+
@Autowired
17+
public SampleApplicationRunner(Shell shell) {
18+
this.shell = shell;
19+
}
20+
21+
@Override
22+
public void run(ApplicationArguments args) throws Exception {
23+
if (args.getSourceArgs().length > 0) {
24+
String commandLine = String.join(" ", args.getSourceArgs());
25+
Object result = shell.evaluate(() -> commandLine);
26+
if (result instanceof Throwable) {
27+
System.out.println(((Exception) result).getMessage());
28+
System.exit(result.hashCode());
29+
}
30+
31+
if (result != null) {
32+
System.out.println(result.toString());
33+
}
34+
System.exit(0);
35+
}
36+
}
37+
}
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
package com.batiwo.shell;
2+
3+
import org.springframework.shell.standard.ShellComponent;
4+
import org.springframework.shell.standard.ShellMethod;
5+
import org.springframework.shell.standard.ShellOption;
6+
7+
@ShellComponent
8+
public class SampleShellComponent {
9+
10+
@ShellMethod("Display the string")
11+
public void echo(String value, @ShellOption(value = {"-v", "--verbose"}, defaultValue = "false") boolean verbose) {
12+
if (verbose) {
13+
System.out.println(String.format("Received command echo with param %s", value));
14+
}
15+
System.out.println(value);
16+
}
17+
}
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
package com.batiwo.shell;
2+
3+
import org.springframework.boot.Banner;
4+
import org.springframework.boot.autoconfigure.SpringBootApplication;
5+
import org.springframework.boot.builder.SpringApplicationBuilder;
6+
7+
@SpringBootApplication
8+
public class ShellCliApplication {
9+
10+
public static void main(String[] args) {
11+
SpringApplicationBuilder builder = new SpringApplicationBuilder(ShellCliApplication.class);
12+
if (args.length > 0) {
13+
builder.bannerMode(Banner.Mode.OFF);
14+
}
15+
builder.run(args);
16+
}
17+
}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
logging.level.root=ERROR

0 commit comments

Comments
 (0)