Skip to content

Commit

Permalink
Create Picoli example codestart for Quarkus JBang project type
Browse files Browse the repository at this point in the history
  • Loading branch information
nicobao committed Dec 11, 2020
1 parent 327b0f2 commit 62ca09c
Show file tree
Hide file tree
Showing 7 changed files with 113 additions and 4 deletions.
12 changes: 11 additions & 1 deletion devtools/cli/src/test/java/io/quarkus/cli/CliTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -303,7 +303,7 @@ public void testMavenBuild() throws Exception {
}

@Test
public void testCreateJBang() throws Exception {
public void testCreateJBangRestEasy() throws Exception {

execute("create-jbang", "--output-folder=my-jbang-project", "resteasy-jsonb");

Expand All @@ -312,6 +312,16 @@ public void testCreateJBang() throws Exception {
Assertions.assertEquals(CommandLine.ExitCode.OK, exitCode);
}

@Test
public void testCreateJBangPicocli() throws Exception {

execute("create-jbang", "--output-folder=my-jbang-project", "quarkus-picocli");

Path project = workspace.resolve("my-jbang-project");
System.setProperty("user.dir", project.toFile().getAbsolutePath());
Assertions.assertEquals(CommandLine.ExitCode.OK, exitCode);
}

private void deleteDir(Path path) throws Exception {
if (!path.toFile().exists())
return;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
## Greet the world!

```shell script
./jbang src/EntryCommand.java hello
```

## Say Goodbye!

```shell script
./jbang src/EntryCommand.java goodbye
```

## Show help

```shell script
./jbang src/EntryCommand.java -h
```

or

```shell script
./jbang src/EntryCommand.java --help
```

## Show version

```shell script
./jbang src/EntryCommand.java -V
```

or

```shell script
./jbang src/EntryCommand.java -h
```
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
name: jbang-picocli-code
ref: picocli
type: code
language:
base:
data:
resource:
class-name: EntryCommand
subcommands: "{HelloCommand.class, GoodByeCommand.class}"
hello:
name: "hello"
description: "Greet World!"
message: "Hello World!"
goodbye:
name: "goodbye"
description: "Say goodbye to World!"
message: "Goodbye World!"
dependencies:
- io.quarkus:quarkus-picocli
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
//usr/bin/env jbang "$0" "$@" ; exit $?
{#for dep in dependencies}
//DEPS {dep.formatted-ga}:{quarkus.version}
{/for}

//JAVAC_OPTIONS -parameters
//
import io.quarkus.picocli.runtime.annotations.TopCommand;
import picocli.CommandLine;

@TopCommand
@CommandLine.Command(mixinStandardHelpOptions = true, subcommands = {resource.subcommands})
public class {resource.class-name} {
}

@CommandLine.Command(name = "{resource.hello.name}", description = "{resource.hello.description}")
class HelloCommand implements Runnable {

@Override
public void run() {
System.out.println("{resource.hello.message}");
}
}

@CommandLine.Command(name = "{resource.goodbye.name}", description = "{resource.goodbye.description}")
class GoodByeCommand implements Runnable {

@Override
public void run() {
System.out.println("{resource.goodbye.message}");
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
```shell script
./jbang src/GreetingResource.java
```
Original file line number Diff line number Diff line change
@@ -1,5 +1,2 @@
# JBang Quarkus Project

```shell script
./jbang src/GreetingResource.java
```
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,19 @@ void generateDefaultProject() throws IOException {

}

@Test
void generatePicocliProject() throws IOException {
final QuarkusJBangCodestartProjectInput input = QuarkusJBangCodestartProjectInput.builder()
.addCodestart("jbang-picocli-code")
.putData("quarkus.version", "999-SNAPSHOT")
.build();
final Path projectDir = testDirPath.resolve("picocli");
getCatalog().createProject(input).generate(projectDir);

assertThat(projectDir.resolve("jbang")).exists();
assertThat(projectDir.resolve("src/EntryCommand.java")).exists();
}

private QuarkusJBangCodestartCatalog getCatalog() throws IOException {
return QuarkusJBangCodestartCatalog.fromQuarkusPlatformDescriptor(getPlatformDescriptor());
}
Expand Down

0 comments on commit 62ca09c

Please sign in to comment.