use of picocli.CommandLine in project aion by aionnetwork.
the class CliTest method testParseDevFail.
/*
Ensure that the dev command only accepts one param within the mutually exclusive group of params
*/
@Parameters(method = "parametersForTestParseDevFail")
@Test(expected = RuntimeException.class)
public void testParseDevFail(String[] arr) {
CommandLine commandLine = new CommandLine(new Arguments()).addSubcommand(EditCli.class);
commandLine.parseArgs(arr);
}
use of picocli.CommandLine in project aion by aionnetwork.
the class CliTest method testEdit.
@Test
@Parameters(method = "parametersForTestEdit")
public void testEdit(String[] options) {
Arguments args = new Arguments();
EditCli editCli = new EditCli();
CommandLine parser = new CommandLine(args).addSubcommand(editCli);
final CommandLine.ParseResult parseResult = parser.parseArgs(options).subcommand();
editCli.checkOptions();
assertThat(parseResult).isNotNull();
assertThat(parseResult.commandSpec().userObject().getClass()).isEqualTo(EditCli.class);
assertThat(mockCli.callAndDoNotInitializeAvm(options, cfg)).isEqualTo(RUN);
}
use of picocli.CommandLine in project groovy by apache.
the class FileSystemCompiler method commandLineCompile.
/**
* Same as main(args) except that exceptions are thrown out instead of causing
* the VM to exit and the lookup for .groovy files can be controlled
*/
public static void commandLineCompile(String[] args, boolean lookupUnnamedFiles) throws Exception {
CompilationOptions options = new CompilationOptions();
CommandLine parser = configureParser(options);
ParseResult parseResult = parser.parseArgs(args);
if (CommandLine.printHelpIfRequested(parseResult)) {
return;
}
displayStackTraceOnError = options.printStack;
CompilerConfiguration configuration = options.toCompilerConfiguration();
// Load the file name list
String[] filenames = options.generateFileNames();
boolean fileNameErrors = filenames == null;
if (!fileNameErrors && (filenames.length == 0)) {
parser.usage(System.err);
return;
}
fileNameErrors = fileNameErrors && !validateFiles(filenames);
if (!fileNameErrors) {
doCompilation(configuration, null, filenames, lookupUnnamedFiles);
}
}
use of picocli.CommandLine in project jgnash by ccavanaugh.
the class jGnashFx method main.
public static void main(final String[] args) {
if (OS.getJavaVersion() < 11f) {
System.err.println(ResourceUtils.getString("Message.JVM11"));
System.err.println(ResourceUtils.getString("Message.Version") + " " + System.getProperty("java.version") + "\n");
// show a swing based dialog
JOptionPane.showMessageDialog(null, ResourceUtils.getString("Message.JVM11"), ResourceUtils.getString("Title.Error"), JOptionPane.ERROR_MESSAGE);
return;
}
// Register the default exception handler
Thread.setDefaultUncaughtExceptionHandler(new StaticUIMethods.ExceptionHandler());
final CommandLine commandLine = new CommandLine(new CommandLineOptions());
commandLine.setToggleBooleanFlags(false);
commandLine.setUsageHelpWidth(80);
try {
final ParseResult pr = commandLine.parseArgs(args);
final CommandLineOptions options = commandLine.getCommand();
if (CommandLine.printHelpIfRequested(pr)) {
System.exit(0);
}
// check for bad server file and hostName combination... can't do both
if (serverFile != null && options.hostName != null) {
commandLine.usage(System.err, Help.Ansi.AUTO);
System.exit(1);
}
configureLogging();
if (options.uninstall) {
PortablePreferences.deleteUserPreferences();
System.exit(0);
}
// System.getProperties().put(EncryptionManager.ENCRYPTION_FLAG, Boolean.toString(options.ssl));
// System.getProperties().put("ssl", Boolean.toString(options.ssl));
port = options.port;
hostName = options.hostName;
password = options.password;
if (options.shutdown) {
if (hostName == null) {
hostName = EngineFactory.LOCALHOST;
}
MessageBus.getInstance().shutDownRemoteServer(hostName, port + 1, password);
System.exit(0);
}
if (options.verbose) {
System.setProperty("javafx.verbose", "true");
}
if (options.portableFile != null) {
PortablePreferences.initPortablePreferences(options.portableFile.getAbsolutePath());
} else if (options.portable) {
PortablePreferences.initPortablePreferences(null);
}
if (options.zeroArgFile != null && options.zeroArgFile.exists()) {
jGnashFx.dataFile = options.zeroArgFile;
}
if (options.dataFile != null && options.dataFile.exists()) {
jGnashFx.dataFile = options.dataFile;
}
if (options.serverFile != null && options.serverFile.exists()) {
jGnashFx.serverFile = options.serverFile;
startServer();
} else {
setupNetworking();
launch(args);
}
} catch (final Exception e) {
logSevere(jGnashFx.class, e);
commandLine.usage(System.err, Help.Ansi.AUTO);
System.exit(1);
}
}
use of picocli.CommandLine in project checkstyle by checkstyle.
the class CliOptionsXdocsSyncTest method validateCliDocSections.
@Test
public void validateCliDocSections() throws Exception {
final Map<String, String> cmdDesc = new HashMap<>();
final NodeList sections = getSectionsFromXdoc("src/xdocs/cmdline.xml.vm");
final Set<String> cmdOptions = getListById(sections.item(2), "CLI_Options");
for (String option : cmdOptions) {
final String text = option.trim().replaceAll("\\s+", " ");
cmdDesc.put(text.substring(0, 2), text.substring(text.indexOf(" - ") + 3));
}
final Class<?> cliOptions = Class.forName("com.puppycrawl.tools.checkstyle" + ".Main$CliOptions");
final CommandLine commandLine = new CommandLine(cliOptions);
final List<OptionSpec> optionSpecList = commandLine.getCommandSpec().options();
for (OptionSpec opt : optionSpecList) {
final String option = opt.names()[0];
if ("-h".equals(option) || "-V".equals(option)) {
cmdDesc.remove(option);
continue;
}
final String descXdoc = cmdDesc.get(option);
final String descMain = opt.description()[0];
assertWithMessage("CLI Option: " + option + " present in " + "Main.java but not documented in cmdline.xml.vm").that(descXdoc).isNotNull();
assertWithMessage("CLI options descriptions in xdoc: " + " should match that of in Main.java").that(descMain).isEqualTo(descXdoc);
cmdDesc.remove(option);
}
assertWithMessage("CLI Options: %s present in cmdline.xml.vm, not documented in Main.java", cmdDesc).that(cmdDesc).isEmpty();
}
Aggregations