Search in sources :

Example 21 with CommandLine

use of picocli.CommandLine in project jgnash by ccavanaugh.

the class jGnash method main.

public static void main(final String[] args) {
    boolean bypassBootLoader = false;
    final CommandLine commandLine = new CommandLine(new jGnashFx.CommandLineOptions());
    commandLine.setToggleBooleanFlags(false);
    commandLine.setUsageHelpWidth(80);
    try {
        final CommandLine.ParseResult pr = commandLine.parseArgs(args);
        final jGnashFx.CommandLineOptions options = commandLine.getCommand();
        if (CommandLine.printHelpIfRequested(pr)) {
            System.exit(0);
        }
        bypassBootLoader = options.bypassBootloader;
    } catch (final CommandLine.UnmatchedArgumentException uae) {
        commandLine.usage(System.err, CommandLine.Help.Ansi.AUTO);
        System.exit(1);
    } catch (final Exception e) {
        logSevere(jGnash.class, e);
        System.exit(1);
    }
    if (BootLoader.getOS() != null) {
        if (bypassBootLoader || BootLoader.doFilesExist()) {
            launch(args);
        } else {
            EventQueue.invokeLater(() -> {
                final BootLoaderDialog d = new BootLoaderDialog();
                d.setVisible(true);
                final Thread thread = new Thread(() -> {
                    if (!BootLoader.downloadFiles(d.getActiveFileConsumer(), d.getPercentCompleteConsumer())) {
                        System.exit(-1);
                    }
                });
                thread.start();
            });
        }
    } else {
        JOptionPane.showMessageDialog(null, "Unsupported operating system", "Error", JOptionPane.ERROR_MESSAGE);
        System.exit(BootLoader.FAILED_EXIT);
    }
}
Also used : CommandLine(picocli.CommandLine) BootLoaderDialog(jgnash.bootloader.BootLoaderDialog)

Example 22 with CommandLine

use of picocli.CommandLine in project groovy by apache.

the class GroovyMain method processArgs.

// package-level visibility for testing purposes (just usage/errors at this stage)
static void processArgs(String[] args, final PrintStream out, final PrintStream err) {
    GroovyCommand groovyCommand = new GroovyCommand();
    CommandLine parser = new CommandLine(groovyCommand).setOut(new PrintWriter(out)).setErr(new PrintWriter(err)).setUnmatchedArgumentsAllowed(true).setStopAtUnmatched(true);
    try {
        ParseResult result = parser.parseArgs(args);
        if (CommandLine.printHelpIfRequested(result)) {
            return;
        }
        // TODO: pass printstream(s) down through process
        if (!groovyCommand.process(parser)) {
            // If we fail, then exit with an error so scripting frameworks can catch it.
            System.exit(1);
        }
    } catch (ParameterException ex) {
        // command line arguments could not be parsed
        err.println(ex.getMessage());
        ex.getCommandLine().usage(err);
    } catch (IOException ioe) {
        err.println("error: " + ioe.getMessage());
    }
}
Also used : CommandLine(picocli.CommandLine) ParseResult(picocli.CommandLine.ParseResult) ParameterException(picocli.CommandLine.ParameterException) IOException(java.io.IOException) PrintWriter(java.io.PrintWriter)

Example 23 with CommandLine

use of picocli.CommandLine in project groovy by apache.

the class FileSystemCompiler method configureParser.

public static CommandLine configureParser(CompilationOptions options) {
    CommandLine parser = new CommandLine(options);
    parser.getCommandSpec().parser().unmatchedArgumentsAllowed(true).unmatchedOptionsArePositionalParams(true).expandAtFiles(false).toggleBooleanFlags(false);
    return parser;
}
Also used : CommandLine(picocli.CommandLine)

Example 24 with CommandLine

use of picocli.CommandLine in project groovy by apache.

the class Groovyc method runCompiler.

private void runCompiler(String[] commandLine) {
    // hand crank it so we can add our own compiler configuration
    try {
        FileSystemCompiler.CompilationOptions options = new FileSystemCompiler.CompilationOptions();
        CommandLine parser = FileSystemCompiler.configureParser(options);
        parser.parseArgs(commandLine);
        configuration = options.toCompilerConfiguration();
        configuration.setScriptExtensions(getScriptExtensions());
        String tmpExtension = getScriptExtension();
        if (tmpExtension.startsWith("*."))
            tmpExtension = tmpExtension.substring(1);
        configuration.setDefaultScriptExtension(tmpExtension);
        if (targetBytecode != null) {
            configuration.setTargetBytecode(targetBytecode);
        }
        // Load the file name list
        String[] fileNames = options.generateFileNames();
        boolean fileNameErrors = (fileNames == null || !FileSystemCompiler.validateFiles(fileNames));
        if (!fileNameErrors) {
            try (GroovyClassLoader loader = buildClassLoaderFor()) {
                FileSystemCompiler.doCompilation(configuration, makeCompileUnit(loader), fileNames, forceLookupUnnamedFiles);
            }
        }
    } catch (Exception e) {
        Throwable t = e;
        if (e.getClass() == RuntimeException.class && e.getCause() != null) {
            // unwrap to the real exception
            t = e.getCause();
        }
        Writer writer = new StringBuilderWriter();
        new ErrorReporter(t, false).write(new PrintWriter(writer));
        String message = writer.toString();
        taskSuccess = false;
        if (errorProperty != null) {
            getProject().setNewProperty(errorProperty, "true");
        }
        if (failOnError) {
            log.error(message);
            throw new BuildException("Compilation Failed", t, getLocation());
        } else {
            log.error(message);
        }
    }
}
Also used : FileSystemCompiler(org.codehaus.groovy.tools.FileSystemCompiler) StringBuilderWriter(org.apache.groovy.io.StringBuilderWriter) URISyntaxException(java.net.URISyntaxException) BuildException(org.apache.tools.ant.BuildException) IOException(java.io.IOException) GroovyClassLoader(groovy.lang.GroovyClassLoader) CommandLine(picocli.CommandLine) ErrorReporter(org.codehaus.groovy.tools.ErrorReporter) BuildException(org.apache.tools.ant.BuildException) StringBuilderWriter(org.apache.groovy.io.StringBuilderWriter) PrintWriter(java.io.PrintWriter) FileWriter(java.io.FileWriter) Writer(java.io.Writer) PrintWriter(java.io.PrintWriter)

Example 25 with CommandLine

use of picocli.CommandLine in project checkstyle by checkstyle.

the class Main method main.

/**
 * Loops over the files specified checking them for errors. The exit code
 * is the number of errors found in all the files.
 *
 * @param args the command line arguments.
 * @throws IOException if there is a problem with files access
 * @noinspection UseOfSystemOutOrSystemErr, CallToPrintStackTrace, CallToSystemExit
 */
public static void main(String... args) throws IOException {
    final CliOptions cliOptions = new CliOptions();
    final CommandLine commandLine = new CommandLine(cliOptions);
    commandLine.setUsageHelpWidth(CliOptions.HELP_WIDTH);
    commandLine.setCaseInsensitiveEnumValuesAllowed(true);
    // provide proper exit code based on results.
    int exitStatus = 0;
    int errorCounter = 0;
    try {
        final ParseResult parseResult = commandLine.parseArgs(args);
        if (parseResult.isVersionHelpRequested()) {
            System.out.println(getVersionString());
        } else if (parseResult.isUsageHelpRequested()) {
            commandLine.usage(System.out);
        } else {
            exitStatus = execute(parseResult, cliOptions);
            errorCounter = exitStatus;
        }
    } catch (ParameterException ex) {
        exitStatus = EXIT_WITH_INVALID_USER_INPUT_CODE;
        System.err.println(ex.getMessage());
        System.err.println("Usage: checkstyle [OPTIONS]... FILES...");
        System.err.println("Try 'checkstyle --help' for more information.");
    } catch (CheckstyleException ex) {
        exitStatus = EXIT_WITH_CHECKSTYLE_EXCEPTION_CODE;
        errorCounter = 1;
        ex.printStackTrace();
    } finally {
        // return exit code base on validation of Checker
        if (errorCounter > 0) {
            final Violation errorCounterViolation = new Violation(1, Definitions.CHECKSTYLE_BUNDLE, ERROR_COUNTER, new String[] { String.valueOf(errorCounter) }, null, Main.class, null);
            // print error count statistic to error output stream,
            // output stream might be used by validation report content
            System.err.println(errorCounterViolation.getViolation());
        }
    }
    Runtime.getRuntime().exit(exitStatus);
}
Also used : Violation(com.puppycrawl.tools.checkstyle.api.Violation) CommandLine(picocli.CommandLine) ParseResult(picocli.CommandLine.ParseResult) ParameterException(picocli.CommandLine.ParameterException) CheckstyleException(com.puppycrawl.tools.checkstyle.api.CheckstyleException)

Aggregations

CommandLine (picocli.CommandLine)45 Test (org.junit.jupiter.api.Test)22 ArgumentMatchers.anyString (org.mockito.ArgumentMatchers.anyString)19 Copier (org.neo4j.pushtocloud.PushToCloudCommand.Copier)17 Path (java.nio.file.Path)9 DumpCreator (org.neo4j.pushtocloud.PushToCloudCommand.DumpCreator)5 ParseResult (picocli.CommandLine.ParseResult)5 IOException (java.io.IOException)4 PrintWriter (java.io.PrintWriter)3 HashMap (java.util.HashMap)3 List (java.util.List)3 Set (java.util.Set)3 ParameterException (picocli.CommandLine.ParameterException)3 PrintStream (java.io.PrintStream)2 Files (java.nio.file.Files)2 Map (java.util.Map)2 ServiceProvider (com.b2international.snowowl.core.ServiceProvider)1 AuthorizedEventBus (com.b2international.snowowl.core.authorization.AuthorizedEventBus)1 JWTGenerator (com.b2international.snowowl.core.identity.JWTGenerator)1 Environment (com.b2international.snowowl.core.setup.Environment)1