List of usage examples for org.apache.commons.cli CommandLine getOptionProperties
public Properties getOptionProperties(String opt)
From source file:com.asakusafw.testdriver.tools.runner.BatchTestRunner.java
static BatchTestRunner parseArguments(String[] args) throws ParseException { assert args != null; CommandLineParser parser = new BasicParser(); CommandLine cmd = parser.parse(OPTIONS, args); String batchId = cmd.getOptionValue(OPT_BATCH_ID.getOpt()); LOG.debug("Batch ID: {}", batchId); //$NON-NLS-1$ Properties arguments = cmd.getOptionProperties(OPT_ARGUMENT.getOpt()); LOG.debug("Batch arguments: {}", arguments); //$NON-NLS-1$ Properties properties = cmd.getOptionProperties(OPT_PROPERTY.getOpt()); LOG.debug("Extra properties: {}", arguments); //$NON-NLS-1$ return new BatchTestRunner(batchId).withArguments(toMap(arguments)).withProperties(toMap(properties)); }
From source file:dk.alexandra.fresco.suite.tinytables.online.TinyTablesConfiguration.java
public static ProtocolSuiteConfiguration fromCmdLine(SCEConfiguration sceConf, CommandLine cmd) throws ParseException, IllegalArgumentException { Options options = new Options(); TinyTablesConfiguration configuration = new TinyTablesConfiguration(); String tinyTablesFileOption = "tinytables.file"; options.addOption(Option.builder("D").desc("The file where the generated TinyTables is leaded from.") .longOpt(tinyTablesFileOption).required(false).hasArgs().build()); Properties p = cmd.getOptionProperties("D"); String tinyTablesFilePath = p.getProperty(tinyTablesFileOption, "tinytables"); File tinyTablesFile = new File(tinyTablesFilePath); configuration.setTinyTablesFile(tinyTablesFile); System.out.println("FromCmdArgs: " + configuration.getTinyTablesFile()); return configuration; }
From source file:io.werval.cli.DamnSmallDevShell.java
private static void applySystemProperties(boolean debug, CommandLine cmd) { Properties systemProperties = cmd.getOptionProperties("D"); for (Iterator<Map.Entry<Object, Object>> it = systemProperties.entrySet().iterator(); it.hasNext();) { Map.Entry<?, ?> entry = it.next(); System.setProperty(entry.getKey().toString(), entry.getValue().toString()); }// ww w . ja v a 2 s .c om if (debug) { System.out.println("Applied System Properties are: " + systemProperties); } }
From source file:com.asakusafw.lang.compiler.cli.BatchCompilerCli.java
private static Map<String, String> parseProperties(CommandLine cmd, Option option) { Properties properties = cmd.getOptionProperties(option.getLongOpt()); Map<String, String> results = new TreeMap<>(); for (Map.Entry<Object, Object> entry : properties.entrySet()) { results.put((String) entry.getKey(), (String) entry.getValue()); }//from w w w . jav a 2 s. c om return results; }
From source file:com.asakusafw.testdriver.tools.runner.BatchTestPreparator.java
static Conf parseArguments(String[] args) throws ParseException { assert args != null; CommandLineParser parser = new BasicParser(); CommandLine cmd = parser.parse(OPTIONS, args); Conf conf = new Conf(); String importerClass = cmd.getOptionValue(OPT_IMPORTER.getLongOpt()); try {//from w w w .java 2 s .c o m conf.importer = Class.forName(importerClass).asSubclass(ImporterDescription.class).newInstance(); } catch (Exception e) { throw new IllegalArgumentException( MessageFormat.format(Messages.getString("BatchTestPreparator.errorInvalidImporterDescription"), //$NON-NLS-1$ importerClass), e); } conf.data = cmd.getOptionValue(OPT_DATA.getLongOpt()); conf.context = new TestDriverContext(conf.importer.getClass()); Properties arguments = cmd.getOptionProperties(OPT_ARGUMENT.getOpt()); conf.context.getBatchArgs().putAll(toMap(arguments)); Properties properties = cmd.getOptionProperties(OPT_PROPERTY.getOpt()); conf.context.getExtraConfigurations().putAll(toMap(properties)); return conf; }
From source file:com.asakusafw.testdriver.tools.runner.BatchTestCollector.java
static Conf parseArguments(String[] args) throws ParseException { assert args != null; CommandLineParser parser = new BasicParser(); CommandLine cmd = parser.parse(OPTIONS, args); Conf conf = new Conf(); String importerClass = cmd.getOptionValue(OPT_EXPORTER.getLongOpt()); try {//from w w w . j a v a 2s. c o m conf.exporter = Class.forName(importerClass).asSubclass(ExporterDescription.class).newInstance(); } catch (Exception e) { throw new IllegalArgumentException( MessageFormat.format(Messages.getString("BatchTestCollector.errorInvalidExporterDescription"), //$NON-NLS-1$ importerClass), e); } conf.output = cmd.getOptionValue(OPT_OUTPUT.getLongOpt()); conf.context = new TestDriverContext(conf.exporter.getClass()); Properties arguments = cmd.getOptionProperties(OPT_ARGUMENT.getOpt()); conf.context.getBatchArgs().putAll(toMap(arguments)); Properties properties = cmd.getOptionProperties(OPT_PROPERTY.getOpt()); conf.context.getExtraConfigurations().putAll(toMap(properties)); return conf; }
From source file:com.asakusafw.testdriver.tools.runner.BatchTestTruncator.java
static Conf parseArguments(String[] args) throws ParseException { assert args != null; CommandLineParser parser = new BasicParser(); CommandLine cmd = parser.parse(OPTIONS, args); Conf conf = new Conf(); String descriptionClass = cmd.getOptionValue(OPT_DESCRIPTION.getLongOpt()); Class<?> description;/* w w w . j av a 2 s . com*/ try { description = Class.forName(descriptionClass); } catch (Exception e) { throw new IllegalArgumentException( MessageFormat.format(Messages.getString("BatchTestTruncator.errorFailedToAnalyze"), //$NON-NLS-1$ descriptionClass), e); } conf.context = new TestDriverContext(description); resolveDescription(conf, description); Properties arguments = cmd.getOptionProperties(OPT_ARGUMENT.getOpt()); conf.context.getBatchArgs().putAll(toMap(arguments)); Properties properties = cmd.getOptionProperties(OPT_PROPERTY.getOpt()); conf.context.getExtraConfigurations().putAll(toMap(properties)); return conf; }
From source file:com.asakusafw.testdriver.tools.runner.BatchTestVerifier.java
static Conf parseArguments(String[] args) throws ParseException { assert args != null; CommandLineParser parser = new BasicParser(); CommandLine cmd = parser.parse(OPTIONS, args); Conf conf = new Conf(); String exporterClass = cmd.getOptionValue(OPT_EXPORTER.getLongOpt()); try {//w w w . j a v a 2s. co m conf.exporter = Class.forName(exporterClass).asSubclass(ExporterDescription.class).newInstance(); } catch (Exception e) { throw new IllegalArgumentException( MessageFormat.format(Messages.getString("BatchTestVerifier.errorInvalidExporterDescription"), //$NON-NLS-1$ exporterClass), e); } conf.data = cmd.getOptionValue(OPT_DATA.getLongOpt()); conf.rule = cmd.getOptionValue(OPT_RULE.getLongOpt()); conf.context = new TestDriverContext(conf.exporter.getClass()); Properties arguments = cmd.getOptionProperties(OPT_ARGUMENT.getOpt()); conf.context.getBatchArgs().putAll(toMap(arguments)); Properties properties = cmd.getOptionProperties(OPT_PROPERTY.getOpt()); conf.context.getExtraConfigurations().putAll(toMap(properties)); return conf; }
From source file:es.csic.iiia.planes.generator.Cli.java
/** * Parse the provided list of arguments according to the program's options. * * @param in_args list of input arguments. * @return a configuration object set according to the input options. *//*from w w w.j a va2 s. com*/ private static Configuration parseOptions(String[] in_args) { CommandLineParser parser = new PosixParser(); CommandLine line = null; Properties settings = loadDefaultSettings(); try { line = parser.parse(options, in_args); } catch (ParseException ex) { Logger.getLogger(Cli.class.getName()).log(Level.SEVERE, ex.getLocalizedMessage(), ex); showHelp(); } if (line.hasOption('h')) { showHelp(); } if (line.hasOption('d')) { dumpSettings(); } if (line.hasOption('s')) { String fname = line.getOptionValue('s'); try { settings.load(new FileReader(fname)); } catch (IOException ex) { throw new IllegalArgumentException("Unable to load the settings file \"" + fname + "\""); } } // Apply overrides settings.setProperty("quiet", String.valueOf(line.hasOption('q'))); Properties overrides = line.getOptionProperties("o"); settings.putAll(overrides); String[] args = line.getArgs(); if (args.length < 1) { showHelp(); } settings.setProperty("problem", args[0]); Configuration c = new Configuration(settings); if (line.hasOption('t')) { System.exit(0); } return c; }
From source file:exm.stc.ui.Main.java
private static Args processArgs(String[] args) { Options opts = initOptions();//www . ja va2s . co m CommandLine cmd = null; try { CommandLineParser parser = new GnuParser(); cmd = parser.parse(opts, args); } catch (ParseException ex) { // Use Apache CLI-provided messages System.err.println(ex.getMessage()); usage(opts); System.exit(1); return null; } boolean updateOutput = cmd.hasOption(UPDATE_FLAG); if (cmd.hasOption(INCLUDE_FLAG)) { for (String dir : cmd.getOptionValues(INCLUDE_FLAG)) { Settings.addModulePath(dir); } } Properties swiftProgramArgs = cmd.getOptionProperties(SWIFT_PROG_ARG_FLAG); String preprocMacros[]; if (cmd.hasOption(PREPROC_MACRO_FLAG)) { preprocMacros = cmd.getOptionValues(PREPROC_MACRO_FLAG); } else { preprocMacros = new String[0]; } String[] remainingArgs = cmd.getArgs(); if (remainingArgs.length < 1 || remainingArgs.length > 2) { System.out.println( "Expected input file and optional output file, but got " + remainingArgs.length + " arguments"); usage(opts); System.exit(ExitCode.ERROR_COMMAND.code()); } String input = remainingArgs[0]; String output = null; if (remainingArgs.length == 2) { output = remainingArgs[1]; } Args result = new Args(input, output, updateOutput, swiftProgramArgs, Arrays.asList(preprocMacros)); recordArgValues(result); return result; }