Search in sources :

Example 1 with RunLast

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);
}
Also used : CommandLine(picocli.CommandLine) RunLast(picocli.CommandLine.RunLast)

Example 2 with RunLast

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);
}
Also used : StringPrintWriter(net.sf.jstuff.core.io.StringPrintWriter) CommandLine(picocli.CommandLine) RunLast(picocli.CommandLine.RunLast)

Example 3 with RunLast

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);
    }
}
Also used : CommandLine(picocli.CommandLine) MetaborgException(org.metaborg.core.MetaborgException) RunLast(picocli.CommandLine.RunLast)

Example 4 with RunLast

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);
}
Also used : BesuPluginContextImpl(org.hyperledger.besu.services.BesuPluginContextImpl) BesuCommand(org.hyperledger.besu.cli.BesuCommand) BesuController(org.hyperledger.besu.controller.BesuController) JsonBlockImporter(org.hyperledger.besu.chainimport.JsonBlockImporter) RunLast(picocli.CommandLine.RunLast) RlpBlockImporter(org.hyperledger.besu.chainimport.RlpBlockImporter) RlpBlockExporter(org.hyperledger.besu.chainexport.RlpBlockExporter) Logger(org.slf4j.Logger)

Example 5 with RunLast

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);
}
Also used : RunLast(picocli.CommandLine.RunLast) Test(org.junit.Test)

Aggregations

RunLast (picocli.CommandLine.RunLast)13 CommandLine (picocli.CommandLine)6 Test (org.junit.Test)5 ParameterException (picocli.CommandLine.ParameterException)3 ParseResult (picocli.CommandLine.ParseResult)3 ArrayList (java.util.ArrayList)2 List (java.util.List)2 ExecutionException (picocli.CommandLine.ExecutionException)2 IExceptionHandler2 (picocli.CommandLine.IExceptionHandler2)2 ValidationException (com.milaboratory.cli.ValidationException)1 File (java.io.File)1 IOException (java.io.IOException)1 StringPrintWriter (net.sf.jstuff.core.io.StringPrintWriter)1 RlpBlockExporter (org.hyperledger.besu.chainexport.RlpBlockExporter)1 JsonBlockImporter (org.hyperledger.besu.chainimport.JsonBlockImporter)1 RlpBlockImporter (org.hyperledger.besu.chainimport.RlpBlockImporter)1 BesuCommand (org.hyperledger.besu.cli.BesuCommand)1 BesuController (org.hyperledger.besu.controller.BesuController)1 BesuPluginContextImpl (org.hyperledger.besu.services.BesuPluginContextImpl)1 MetaborgException (org.metaborg.core.MetaborgException)1