This repository has been archived by the owner on Jul 17, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 42
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #59 from remkop/#474-create-cli-app
#474 add create-cli-app command that creates CLI app with the correct main class
- Loading branch information
Showing
15 changed files
with
254 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
description: Creates a picocli-based command line application using Groovy | ||
dependentFeatures: | ||
- groovy | ||
- picocli | ||
dependencies: | ||
- scope: compile | ||
coords: io.micronaut:runtime |
28 changes: 28 additions & 0 deletions
28
...i-groovy/skeleton/src/main/groovy/@defaultPackage.path@/@project.className@Command.groovy
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
package @defaultPackage@ | ||
|
||
import io.micronaut.configuration.picocli.PicocliRunner | ||
import io.micronaut.context.ApplicationContext | ||
|
||
import picocli.CommandLine | ||
import picocli.CommandLine.Command | ||
import picocli.CommandLine.Option | ||
import picocli.CommandLine.Parameters | ||
|
||
@Command(name = '@project.name@', description = '...', | ||
mixinStandardHelpOptions = true) | ||
class @project.className@Command implements Runnable { | ||
|
||
@Option(names = ['-v', '--verbose'], description = '...') | ||
boolean verbose | ||
|
||
static void main(String[] args) throws Exception { | ||
PicocliRunner.run(@project.className@Command.class, args) | ||
} | ||
|
||
void run() { | ||
// business logic here | ||
if (verbose) { | ||
println "Hi!" | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
description: Creates a picocli-based command line application using Java | ||
dependentFeatures: | ||
- java | ||
- picocli | ||
dependencies: | ||
- scope: compile | ||
coords: io.micronaut:runtime | ||
- scope: testCompile | ||
coords: io.micronaut:inject-java |
28 changes: 28 additions & 0 deletions
28
...picocli-java/skeleton/src/main/java/@defaultPackage.path@/@project.className@Command.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
package @defaultPackage@; | ||
|
||
import io.micronaut.configuration.picocli.PicocliRunner; | ||
import io.micronaut.context.ApplicationContext; | ||
|
||
import picocli.CommandLine; | ||
import picocli.CommandLine.Command; | ||
import picocli.CommandLine.Option; | ||
import picocli.CommandLine.Parameters; | ||
|
||
@Command(name = "@project.name@", description = "...", | ||
mixinStandardHelpOptions = true) | ||
public class @project.className@Command implements Runnable { | ||
|
||
@Option(names = {"-v", "--verbose"}, description = "...") | ||
boolean verbose; | ||
|
||
public static void main(String[] args) throws Exception { | ||
PicocliRunner.run(@project.className@Command.class, args); | ||
} | ||
|
||
public void run() { | ||
// business logic here | ||
if (verbose) { | ||
System.out.println("Hi!"); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
description: Creates a picocli-based command line application using Kotlin | ||
dependentFeatures: | ||
- kotlin | ||
- picocli | ||
dependencies: | ||
- scope: compile | ||
coords: io.micronaut:runtime | ||
- scope: testCompile | ||
coords: io.micronaut:inject-java |
30 changes: 30 additions & 0 deletions
30
...cocli-kotlin/skeleton/src/main/kotlin/@defaultPackage.path@/@project.className@Command.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
package @defaultPackage@ | ||
|
||
import io.micronaut.configuration.picocli.PicocliRunner | ||
import io.micronaut.context.ApplicationContext | ||
|
||
import picocli.CommandLine | ||
import picocli.CommandLine.Command | ||
import picocli.CommandLine.Option | ||
import picocli.CommandLine.Parameters | ||
|
||
@Command(name = "@project.name@", description = ["..."], | ||
mixinStandardHelpOptions = true) | ||
class @project.className@Command : Runnable { | ||
|
||
@Option(names = ["-v", "--verbose"], description = ["..."]) | ||
private var verbose : Boolean = false | ||
|
||
override fun run() { | ||
// business logic here | ||
if (verbose) { | ||
println("Hi!") | ||
} | ||
} | ||
|
||
companion object { | ||
@JvmStatic fun main(args: Array<String>) { | ||
PicocliRunner.run(@project.className@Command::class.java, *args) | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
description: Creates JUnit test for a picocli-based command line application | ||
dependentFeatures: | ||
- junit | ||
- picocli | ||
#dependencies: | ||
# - scope: testCompile | ||
# coords: io.micronaut:function-client | ||
# - scope: testRuntime | ||
# coords: io.micronaut:http-server-netty | ||
# - scope: testRuntime | ||
# coords: io.micronaut:function-web |
28 changes: 28 additions & 0 deletions
28
...li-junit/skeleton/src/test/java/@defaultPackage.path@/@project.className@CommandTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
package @defaultPackage@; | ||
|
||
import io.micronaut.configuration.picocli.PicocliRunner; | ||
import io.micronaut.context.ApplicationContext; | ||
import io.micronaut.context.env.Environment; | ||
|
||
import java.io.ByteArrayOutputStream; | ||
import java.io.PrintStream; | ||
import org.junit.Test; | ||
|
||
import static org.junit.Assert.*; | ||
|
||
public class @project.className@CommandTest { | ||
|
||
@Test | ||
public void testWithCommandLineOption() throws Exception { | ||
ByteArrayOutputStream baos = new ByteArrayOutputStream(); | ||
System.setOut(new PrintStream(baos)); | ||
|
||
try (ApplicationContext ctx = ApplicationContext.run(Environment.CLI, Environment.TEST)) { | ||
String[] args = new String[] { "-v" }; | ||
PicocliRunner.run(@project.className@Command.class, ctx, args); | ||
|
||
// @project.name@ | ||
assertTrue(baos.toString(), baos.toString().contains("Hi!")); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
description: Creates Spek test for a picocli-based command line application | ||
dependentFeatures: | ||
- spek | ||
- picocli | ||
#dependencies: | ||
# - scope: testCompile | ||
# coords: io.micronaut:function-client | ||
# - scope: testCompile | ||
# coords: io.micronaut:http-client | ||
# - scope: testRuntime | ||
# coords: io.micronaut:http-server-netty | ||
# - scope: testRuntime | ||
# coords: io.micronaut:function-web |
37 changes: 37 additions & 0 deletions
37
...cli-spek/skeleton/src/test/kotlin/@defaultPackage.path@/@project.className@CommandTest.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
package @defaultPackage@ | ||
|
||
import io.micronaut.configuration.picocli.PicocliRunner | ||
import io.micronaut.context.ApplicationContext | ||
import io.micronaut.context.env.Environment | ||
|
||
import org.jetbrains.spek.api.Spek | ||
import org.jetbrains.spek.api.dsl.describe | ||
import org.jetbrains.spek.api.dsl.it | ||
import org.jetbrains.spek.api.dsl.on | ||
import org.junit.jupiter.api.Assertions.* | ||
|
||
import java.io.ByteArrayOutputStream | ||
import java.io.PrintStream | ||
|
||
object @project.className@CommandTest : Spek({ | ||
|
||
describe("@project.name@") { | ||
val ctx = ApplicationContext.run(Environment.CLI, Environment.TEST) | ||
|
||
on("invocation with -v") { | ||
val baos = ByteArrayOutputStream() | ||
System.setOut(PrintStream(baos)) | ||
|
||
val args = arrayOf("-v") | ||
PicocliRunner.run(@project.className@Command::class.java, ctx, *args) | ||
|
||
it("should display greeting") { | ||
assertTrue(baos.toString().contains("Hi!")) | ||
} | ||
} | ||
|
||
on("other") { | ||
// add more tests... | ||
} | ||
} | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
description: Creates Spock test for a picocli-based command line application | ||
dependentFeatures: | ||
- spock | ||
- picocli | ||
#dependencies: | ||
# - scope: testCompile | ||
# coords: io.micronaut:function-client | ||
# - scope: testRuntime | ||
# coords: io.micronaut:http-server-netty | ||
# - scope: testRuntime | ||
# coords: io.micronaut:function-web |
29 changes: 29 additions & 0 deletions
29
...pock/skeleton/src/test/groovy/@defaultPackage.path@/@project.className@CommandSpec.groovy
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
package @defaultPackage@ | ||
|
||
import io.micronaut.configuration.picocli.PicocliRunner | ||
import io.micronaut.context.ApplicationContext | ||
import io.micronaut.context.env.Environment | ||
|
||
import spock.lang.AutoCleanup | ||
import spock.lang.Shared | ||
import spock.lang.Specification | ||
|
||
import java.io.ByteArrayOutputStream | ||
import java.io.PrintStream | ||
|
||
class @project.className@CommandSpec extends Specification { | ||
|
||
@Shared @AutoCleanup ApplicationContext ctx = ApplicationContext.run(Environment.CLI, Environment.TEST) | ||
|
||
void "test @project.name@ with command line option"() { | ||
given: | ||
ByteArrayOutputStream baos = new ByteArrayOutputStream() | ||
System.setOut(new PrintStream(baos)) | ||
|
||
String[] args = ['-v'] as String[] | ||
PicocliRunner.run(@project.className@Command, ctx, args) | ||
|
||
expect: | ||
baos.toString().contains('Hi!') | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,8 @@ | ||
mainClassName = "@defaultPackage@.@project.className@Command" | ||
applicationDefaultJvmArgs = [""] | ||
|
||
mainClassName = "@defaultPackage@.Application" | ||
jar { | ||
manifest { | ||
attributes 'Main-Class': mainClassName | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | ||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> | ||
<properties> | ||
<exec.mainClass>@defaultPackage@.Application</exec.mainClass> | ||
<exec.mainClass>@defaultPackage@.@project.className@Command</exec.mainClass> | ||
</properties> | ||
</project> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters