List of usage examples for org.apache.commons.cli Option setArgs
public void setArgs(int num)
From source file:fr.ujm.tse.lt2c.satin.main.Main.java
/** * @param args//from w ww . j av a 2s . c o m * @return a ReasoningArguements object containing all the parsed arguments */ private static ReasoningArguments getArguments(final String[] args) { /* Reasoner fields */ int threadsNB = DEFAULT_THREADS_NB; int bufferSize = DEFAULT_BUFFER_SIZE; long timeout = DEFAULT_TIMEOUT; int iteration = 1; ReasonerProfile profile = DEFAULT_PROFILE; /* Extra fields */ boolean verboseMode = DEFAULT_VERBOSE_MODE; boolean warmupMode = DEFAULT_WARMUP_MODE; boolean dumpMode = DEFAULT_DUMP_MODE; boolean batchMode = DEFAULT_BATCH_MODE; /* * Options */ final Options options = new Options(); final Option bufferSizeO = new Option("b", "buffer-size", true, "set the buffer size"); bufferSizeO.setArgName("size"); bufferSizeO.setArgs(1); bufferSizeO.setType(Number.class); options.addOption(bufferSizeO); final Option timeoutO = new Option("t", "timeout", true, "set the buffer timeout in ms (0 means timeout will be disabled)"); bufferSizeO.setArgName("time"); bufferSizeO.setArgs(1); bufferSizeO.setType(Number.class); options.addOption(timeoutO); final Option iterationO = new Option("i", "iteration", true, "how many times each file "); iterationO.setArgName("number"); iterationO.setArgs(1); iterationO.setType(Number.class); options.addOption(iterationO); final Option directoryO = new Option("d", "directory", true, "infers on all ontologies in the directory"); directoryO.setArgName("directory"); directoryO.setArgs(1); directoryO.setType(File.class); options.addOption(directoryO); options.addOption("o", "output", false, "save output into file"); options.addOption("h", "help", false, "print this message"); options.addOption("v", "verbose", false, "enable verbose mode"); options.addOption("r", "batch-reasoning", false, "enable batch reasoning"); options.addOption("w", "warm-up", false, "insert a warm-up lap before the inference"); final Option profileO = new Option("p", "profile", true, "set the fragment " + java.util.Arrays.asList(ReasonerProfile.values())); profileO.setArgName("profile"); profileO.setArgs(1); options.addOption(profileO); final Option threadsO = new Option("n", "threads", true, "set the number of threads by available core (0 means the jvm manage)"); threadsO.setArgName("number"); threadsO.setArgs(1); threadsO.setType(Number.class); options.addOption(threadsO); /* * Arguments parsing */ final CommandLineParser parser = new GnuParser(); final CommandLine cmd; try { cmd = parser.parse(options, args); } catch (final ParseException e) { LOGGER.error("", e); return null; } /* help */ if (cmd.hasOption("help")) { final HelpFormatter formatter = new HelpFormatter(); formatter.printHelp("main", options); return null; } /* buffer */ if (cmd.hasOption("buffer-size")) { final String arg = cmd.getOptionValue("buffer-size"); try { bufferSize = Integer.parseInt(arg); } catch (final NumberFormatException e) { LOGGER.error("Buffer size must be a number. Default value used", e); } } /* timeout */ if (cmd.hasOption("timeout")) { final String arg = cmd.getOptionValue("timeout"); try { timeout = Integer.parseInt(arg); } catch (final NumberFormatException e) { LOGGER.error("Timeout must be a number. Default value used", e); } } /* verbose */ if (cmd.hasOption("verbose")) { verboseMode = true; if (LOGGER.isInfoEnabled()) { LOGGER.info("Verbose mode enabled"); } } /* warm-up */ if (cmd.hasOption("warm-up")) { warmupMode = true; if (LOGGER.isInfoEnabled()) { LOGGER.info("Warm-up mode enabled"); } } /* dump */ if (cmd.hasOption("output")) { dumpMode = true; if (LOGGER.isInfoEnabled()) { LOGGER.info("Dump mode enabled"); } } /* dump */ if (cmd.hasOption("batch-reasoning")) { batchMode = true; if (LOGGER.isInfoEnabled()) { LOGGER.info("Batch mode enabled"); } } /* directory */ String dir = null; if (cmd.hasOption("directory")) { for (final Object o : cmd.getOptionValues("directory")) { String arg = o.toString(); if (arg.startsWith("~" + File.separator)) { arg = System.getProperty("user.home") + arg.substring(1); } final File directory = new File(arg); if (!directory.exists()) { LOGGER.warn("**Cant not find " + directory); } else if (!directory.isDirectory()) { LOGGER.warn("**" + directory + " is not a directory"); } else { dir = directory.getAbsolutePath(); } } } /* profile */ if (cmd.hasOption("profile")) { final String string = cmd.getOptionValue("profile"); switch (string) { case "RhoDF": profile = ReasonerProfile.RHODF; break; case "BRhoDF": profile = ReasonerProfile.BRHODF; break; case "RDFS": profile = ReasonerProfile.RDFS; break; case "BRDFS": profile = ReasonerProfile.BRDFS; break; default: LOGGER.warn("Profile unknown, default profile used: " + DEFAULT_PROFILE); profile = DEFAULT_PROFILE; break; } } /* threads */ if (cmd.hasOption("threads")) { final String arg = cmd.getOptionValue("threads"); try { threadsNB = Integer.parseInt(arg); } catch (final NumberFormatException e) { LOGGER.error("Threads number must be a number. Default value used", e); } } /* iteration */ if (cmd.hasOption("iteration")) { final String arg = cmd.getOptionValue("iteration"); try { iteration = Integer.parseInt(arg); } catch (final NumberFormatException e) { LOGGER.error("Iteration must be a number. Default value used", e); } } final List<File> files = new ArrayList<>(); if (dir != null) { final File directory = new File(dir); final File[] listOfFiles = directory.listFiles(); for (final File file : listOfFiles) { // Maybe other extensions ? if (file.isFile() && file.getName().endsWith(".nt")) { files.add(file); } } } for (final Object o : cmd.getArgList()) { String arg = o.toString(); if (arg.startsWith("~" + File.separator)) { arg = System.getProperty("user.home") + arg.substring(1); } final File file = new File(arg); if (!file.exists()) { LOGGER.warn("**Cant not find " + file); } else if (file.isDirectory()) { LOGGER.warn("**" + file + " is a directory"); } else { files.add(file); } } Collections.sort(files, new Comparator<File>() { @Override public int compare(final File f1, final File f2) { if (f1.length() > f2.length()) { return 1; } if (f2.length() > f1.length()) { return -1; } return 0; } }); if (LOGGER.isInfoEnabled()) { LOGGER.info("********* OPTIONS *********"); LOGGER.info("Buffer size: " + bufferSize); LOGGER.info("Profile: " + profile); if (threadsNB > 0) { LOGGER.info("Threads: " + threadsNB); } else { LOGGER.info("Threads: Automatic"); } LOGGER.info("Iterations: " + iteration); LOGGER.info("Timeout: " + timeout); LOGGER.info("***************************"); } return new ReasoningArguments(threadsNB, bufferSize, timeout, iteration, profile, verboseMode, warmupMode, dumpMode, batchMode, files); }
From source file:de.zib.scalaris.InterOpTest.java
/** * Creates the options the command line should understand. * * @return the options the program understands *//*from w w w. j a v a2 s . c o m*/ private static Options getOptions() { final Options options = new Options(); final OptionGroup group = new OptionGroup(); /* Note: arguments are set to be optional since we implement argument * checks on our own (commons.cli is not flexible enough and only * checks for the existence of a first argument) */ options.addOption(new Option("h", "help", false, "print this message")); options.addOption(new Option("v", "verbose", false, "print verbose information, e.g. the properties read")); final Option read = new Option("r", "read", true, "read an item"); read.setArgName("basekey> <language"); read.setArgs(2); read.setOptionalArg(true); group.addOption(read); final Option write = new Option("w", "write", true, "write an item"); write.setArgName("basekey"); write.setArgs(1); write.setOptionalArg(true); group.addOption(write); options.addOptionGroup(group); options.addOption(new Option("lh", "localhost", false, "gets the local host's name as known to Java (for debugging purposes)")); return options; }
From source file:dk.statsbiblioteket.netark.dvenabler.Command.java
private static Options getOptions() { Options options = new Options(); options.addOption("h", HELP, false, "Print help message and exit"); options.addOption("v", VERBOSE, false, "Enable verbose output"); options.addOption("l", LIST, false, "Lists fields in index"); options.addOption("c", CONVERT, false, "Convert index with the given field adjustments"); {//from ww w.j ava 2 s . c o m Option iOption = new Option("f", FIELDS, true, "The fields to adjust.\n" + "entry: fieldname(docvaluetype)\n" + "docvaluetype: " + "NONE" + " | " + FieldInfo.DocValuesType.NUMERIC + "(numerictype) | " + FieldInfo.DocValuesType.BINARY + " | " + FieldInfo.DocValuesType.SORTED + " | " + FieldInfo.DocValuesType.SORTED_SET + "\n" + "numerictype: " + FieldType.NumericType.INT + " | " + FieldType.NumericType.LONG + " | " + FieldType.NumericType.FLOAT + " | " + FieldType.NumericType.DOUBLE + "\n" + "Sample: title(SORTED) year(NUMERIC(INT)) author(SORTED_SET) deprecated(NONE)"); iOption.setArgs(Option.UNLIMITED_VALUES); options.addOption(iOption); } { Option iOption = new Option("i", INPUT, true, "Input folder with Lucene index"); iOption.setArgs(1); options.addOption(iOption); } { Option iOption = new Option("o", OUTPUT, true, "Destination folder for adjusted Lucene index"); iOption.setArgs(1); options.addOption(iOption); } return options; }
From source file:com.geeksaga.light.tools.Main.java
private Options getOptions() { Option attachOption = new Option("a", "attach", true, "attach java process"); attachOption.setArgs(Option.UNLIMITED_VALUES); attachOption.setArgName("process ID"); Options options = new Options(); options.addOption(attachOption);/* w ww . j a va2 s . co m*/ options.addOption(new Option("p", "process", false, "find java process")); options.addOption(new Option("s", "self", false, "self attach java process")); return options; }
From source file:de.softwareforge.pgpsigner.commands.SignEventCommand.java
@Override public Option getCommandLineOption() { Option option = super.getCommandLineOption(); option.setArgs(1); option.setArgName("eventname"); return option; }
From source file:de.softwareforge.pgpsigner.commands.KeyServerCommand.java
@Override public Option getCommandLineOption() { Option option = super.getCommandLineOption(); option.setArgs(1); option.setArgName("hostname"); return option; }
From source file:de.softwareforge.pgpsigner.commands.PartyRingCommand.java
@Override public Option getCommandLineOption() { Option option = super.getCommandLineOption(); option.setArgs(1); option.setArgName("file"); return option; }
From source file:de.softwareforge.pgpsigner.commands.PublicRingCommand.java
public Option getCommandLineOption() { Option option = super.getCommandLineOption(); option.setArgs(1); option.setArgName("file"); return option; }
From source file:de.softwareforge.pgpsigner.commands.SignKeyCommand.java
@Override public Option getCommandLineOption() { Option option = super.getCommandLineOption(); option.setArgs(1); option.setArgName("key"); return option; }
From source file:com.geeksaga.light.console.Main.java
private Options getOptions() { Option bootStrapOption = new Option("b", "bootstrap", true, "library append to class loader of bootstrap"); bootStrapOption.setArgs(Option.UNLIMITED_VALUES); bootStrapOption.setArgName("library path"); Option attachOption = new Option("a", "attach", true, "attach java process"); attachOption.setArgs(Option.UNLIMITED_VALUES); attachOption.setArgName("process ID"); Option processOption = new Option("p", "process", false, "find java process"); Options options = new Options(); options.addOption(bootStrapOption);/*from ww w . j ava 2 s. c om*/ options.addOption(attachOption); options.addOption(processOption); return options; }