Search in sources :

Example 1 with DefaultExceptionHandler

use of picocli.CommandLine.DefaultExceptionHandler in project hazelcast by hazelcast.

the class HazelcastCommandLine method runCommandLine.

static void runCommandLine(Function<ClientConfig, HazelcastInstance> hzClientFn, PrintStream out, PrintStream err, boolean shouldExit, String[] args) {
    CommandLine cmd = new CommandLine(new HazelcastCommandLine(hzClientFn, out, err));
    cmd.getSubcommands().get("submit").setStopAtPositional(true);
    String version = getBuildInfo().getVersion();
    cmd.getCommandSpec().usageMessage().header("Hazelcast " + version);
    if (args.length == 0) {
        cmd.usage(out);
    } else {
        DefaultExceptionHandler<List<Object>> excHandler = new ExceptionHandler<List<Object>>().useErr(err).useAnsi(Ansi.AUTO);
        if (shouldExit) {
            excHandler.andExit(1);
        }
        List<Object> parsed = cmd.parseWithHandlers(new RunAll().useOut(out).useAnsi(Ansi.AUTO), excHandler, args);
        // only top command was executed
        if (parsed != null && parsed.size() == 1) {
            cmd.usage(out);
        }
    }
}
Also used : DefaultExceptionHandler(picocli.CommandLine.DefaultExceptionHandler) CommandLine(picocli.CommandLine) RunAll(picocli.CommandLine.RunAll) Collections.emptyList(java.util.Collections.emptyList) List(java.util.List) Util.idToString(com.hazelcast.jet.Util.idToString)

Aggregations

Util.idToString (com.hazelcast.jet.Util.idToString)1 Collections.emptyList (java.util.Collections.emptyList)1 List (java.util.List)1 CommandLine (picocli.CommandLine)1 DefaultExceptionHandler (picocli.CommandLine.DefaultExceptionHandler)1 RunAll (picocli.CommandLine.RunAll)1