Created
April 23, 2020 20:37
-
-
Save dmi3coder/a7c749de2c971cd893543e327ec547da to your computer and use it in GitHub Desktop.
Quarkus Greeting example with Command mode and main method
This file contains hidden or 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
package org.acme.getting.started; | |
import io.quarkus.runtime.Quarkus; | |
import io.quarkus.runtime.QuarkusApplication; | |
import io.quarkus.runtime.annotations.QuarkusMain; | |
import org.jboss.logging.Logger; | |
import javax.inject.Inject; | |
@QuarkusMain | |
public class GreetingApplication implements QuarkusApplication { | |
public static final Logger LOGGER = Logger.getLogger(GreetingApplication.class); | |
@Inject | |
GreetingService greetingService; | |
@Override | |
public int run(String... args) throws Exception { | |
if(args.length == 0) { | |
Quarkus.waitForExit(); | |
return 0; | |
} | |
if (args[0].equals("--help")) { | |
LOGGER.info( | |
"\nThis tool helps greet users by their name\n" + | |
"Available commands:\n" + | |
"\t--help\t\t\tShow helpful message\n" + | |
"\t--greet={name}\t\tGreet person by their name" | |
); | |
return 0; | |
} | |
if (args[0].startsWith("--greet")) { | |
String name = args[0].substring(8); | |
LOGGER.info(greetingService.greeting(name)); | |
} // ... more else if cases for diferent commands | |
return 0; | |
} | |
public static void main(String[] args) { | |
Quarkus.run(GreetingApplication.class); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment