use of picocli.CommandLine.RunLast in project zdb by Zelldon.
the class ZeebeDebugger method main.
public static void main(String[] args) {
disableWarning();
cli = new CommandLine(new ZeebeDebugger()).setExecutionStrategy(new RunLast()).setCaseInsensitiveEnumValuesAllowed(true);
final int exitcode = cli.execute(args);
System.exit(exitcode);
}
use of picocli.CommandLine.RunLast in project copycat by vegardit.
the class CopyCatMain method main.
public static void main(final String[] args) throws Exception {
Thread.currentThread().setName("main");
// this is a small hack, but we need to evaluate the logging options before
// any other component starts throwing exceptions, see https://github.com/remkop/picocli/issues/1295
final var fileHandler = configureLogging(args);
// enable ANSI coloring
AnsiConsole.systemInstall();
final var handler = new CommandLine(new CopyCatMain());
handler.setCaseInsensitiveEnumValuesAllowed(true);
handler.setExecutionStrategy(new RunLast());
/*
* custom exception handlers that use a logger instead of directly writing to stdout/stderr
*/
handler.setParameterExceptionHandler((ex, args2) -> {
if (args2.length == 0) {
CommandLine.usage(handler, System.err);
System.err.println();
LOG.error(ex.getMessage());
} else {
LOG.error(ex.getMessage());
try (var sw = new StringPrintWriter()) {
UnmatchedArgumentException.printSuggestions(ex, sw);
final var suggestions = sw.toString();
if (Strings.isNotBlank(suggestions)) {
LOG.info(Strings.trim(suggestions));
}
}
LOG.info("Execute 'copycat --help' for usage help.");
}
return 1;
});
handler.setExecutionExceptionHandler((ex, commandLine, parseResult) -> {
if (LOG.isDebugEnabled()) {
// log with stacktrace
LOG.error(ex);
} else {
LOG.error(ex.getMessage());
}
return 1;
});
final var exitCode = handler.execute(args);
if (fileHandler != null) {
fileHandler.close();
}
System.exit(exitCode);
}
use of picocli.CommandLine.RunLast in project nabl by metaborg.
the class Statix method main.
public static void main(String... args) {
CommandLine cmd;
try {
cmd = new CommandLine(new Statix());
cmd.parseWithHandlers(new RunLast().andExit(0), CommandLine.defaultExceptionHandler().andExit(1), args);
} catch (MetaborgException e) {
logger.error("Cannot initialize Statix CLI", e);
System.exit(1);
}
}
use of picocli.CommandLine.RunLast in project besu by hyperledger.
the class Besu method main.
public static void main(final String... args) {
final Logger logger = setupLogging();
final BesuCommand besuCommand = new BesuCommand(logger, RlpBlockImporter::new, JsonBlockImporter::new, RlpBlockExporter::new, new RunnerBuilder(), new BesuController.Builder(), new BesuPluginContextImpl(), System.getenv());
besuCommand.parse(new RunLast().andExit(SUCCESS_EXIT_CODE), besuCommand.exceptionHandler().andExit(ERROR_EXIT_CODE), System.in, args);
}
use of picocli.CommandLine.RunLast in project besu by hyperledger.
the class CommandLineUtilsTest method optionsAreNotExpected.
@Test
public void optionsAreNotExpected() {
final AbstractTestCommand testCommand = new TestCommandWithDeps(mockLogger);
testCommand.commandLine.parseWithHandlers(new RunLast(), defaultExceptionHandler(), "--option-enabled", "false", "--option2", "20", "--option3", "30", "--option4", "40");
verifyOptionsConstraintLoggerCall(mockLogger, "--option2 and --option3", "--option-enabled");
assertThat(testCommand.optionEnabled).isFalse();
assertThat(testCommand.option2).isEqualTo(20);
assertThat(testCommand.option3).isEqualTo(30);
assertThat(testCommand.option4).isEqualTo(40);
}
Aggregations