-
-
Save maxandersen/e5a83ec1f19c58f38be5c6d127515bff to your computer and use it in GitHub Desktop.
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
//usr/bin/env jbang "$0" "$@" ; exit $? | |
/** | |
* Minimal picocli with jbang and quarkus 1.8.0.CR1 | |
* The @QuarkusMain and extra run/main methods is only necessary now | |
* as the jbang integration in quarkus does not auto-generate a main. | |
* once that is fixed that all can go away. | |
*/ | |
//DEPS io.quarkus:quarkus-picocli:1.8.0.CR1 | |
//JAVA_OPTIONS -Djava.util.logging.manager=org.jboss.logmanager.LogManager | |
//Q:CONFIG quarkus.banner.enabled=false | |
//Q:CONFIG quarkus.log.level=WARN | |
package com.acme.picocli; | |
import picocli.CommandLine; | |
import javax.enterprise.context.Dependent; | |
import javax.inject.Inject; | |
import io.quarkus.runtime.annotations.QuarkusMain; | |
import io.quarkus.runtime.QuarkusApplication; | |
@QuarkusMain | |
@CommandLine.Command | |
public class quarkuscli implements Runnable, QuarkusApplication { | |
@CommandLine.Option(names = {"-n", "--name"}, description = "Who will we greet?", defaultValue = "World") | |
String name; | |
@Inject | |
CommandLine.IFactory factory; | |
private final GreetingService greetingService; | |
public quarkuscli(GreetingService greetingService) { | |
this.greetingService = greetingService; | |
} | |
@Override | |
public void run() { | |
greetingService.sayHello(name); | |
} | |
@Override | |
public int run(String... args) throws Exception { | |
return new CommandLine(this, factory).execute(args); | |
} | |
public static void main(String... args) { | |
io.quarkus.runtime.Quarkus.run(quarkuscli.class, args); | |
} | |
} | |
@Dependent | |
class GreetingService { | |
void sayHello(String name) { | |
System.out.println("Hello " + name + "!"); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment