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);
}
}
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());
}
}
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;
}
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);
}
}
}
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);
}
Aggregations