List of usage examples for org.apache.commons.cli OptionBuilder create
public static Option create() throws IllegalArgumentException
From source file:com.vectorization.server.master.Application.java
private static Options createOptions() { Options options = new Options(); OptionBuilder.withLongOpt("help"); OptionBuilder.withDescription("Print this message"); Option help = OptionBuilder.create(); options.addOption(help);//w ww. j ava2 s . co m options.addOption("P", "port", true, "Port number to use for connection"); options.addOption("V", "version", false, "Output version information and exit."); return options; }
From source file:gr.evoltrio.conf.CliParametersParser.java
private void addOptions() { OptionBuilder.withLongOpt("begDur").withDescription("Sets the duration of the first note in a phrase") .hasArg().withArgName("[1,6]"); // music parameters options.addOption(OptionBuilder.create()); options.addOption(OptionBuilder.withLongOpt("phraseNotes") .withDescription("Sets the number of notes a phrase will contain").hasArg().withArgName("[4,32]") .create());//ww w . j a v a 2s. c o m options.addOption(OptionBuilder.withLongOpt("intJump") .withDescription("Sets the max interval jump between two adjacent notes").hasArg() .withArgName("[1,12]").create()); options.addOption(OptionBuilder.withLongOpt("durJump") .withDescription("Sets the max duration jump between two adjacent notes").hasArg() .withArgName("[1,6]").create()); options.addOption(OptionBuilder.withLongOpt("note").withDescription("The pitch of the key note").hasArg() .withArgName("[ C | C# | .. | B ]").create()); options.addOption(OptionBuilder.withLongOpt("octave").withDescription("The octave of the key note").hasArg() .withArgName("[2,7]").create()); options.addOption(OptionBuilder.withLongOpt("pattern").withDescription("The music pattern to use").hasArg() .withArgName("[ I-IV-V-I ]").create()); options.addOption(OptionBuilder.withLongOpt("drums").withDescription("The drum pattern to use").hasArg() .withArgName("[ default ]").create()); options.addOption(OptionBuilder.withLongOpt("bass").withDescription("The bass pattern to use").hasArg() .withArgName("[ default ]").create()); options.addOption(OptionBuilder.withLongOpt("tempo").withDescription("Defines the music tempo").hasArg() .withArgName("[ ADAGIO ]").create()); options.addOption(OptionBuilder.withLongOpt("organ") .withDescription("The midi instrument that the solist is going to use").hasArg() .withArgName("[0,127]").create()); // parameters for the evolution options.addOption(OptionBuilder.withLongOpt("random").withDescription("The random generator to use") .hasArg().withArgName("[ STOCK | CAUCHY | GAUSSIAN ]").create()); options.addOption(OptionBuilder.withLongOpt("natural").withDescription("The natural selector to use") .hasArg().withArgName("[ BEST | THRESHOLD | TOURNAMENT | WEIGHTED ]").create()); options.addOption("u", "execBefore", false, "Execute the natural selector before the genetic operators"); options.addOption(OptionBuilder.withLongOpt("minpop") .withDescription("Minimum percent size guaranteed for population").hasArg().withArgName("[0,100]") .create()); options.addOption(OptionBuilder.withLongOpt("previousGen") .withDescription( "Defines the percentage of the chromosomes that are going to enter the new population") .hasArg().withArgName("[0,1]").create()); options.addOption("f", "constant", false, "Keep constant the population size"); options.addOption(OptionBuilder.withLongOpt("crossover").withDescription("Defines the crossover rate") .hasArg().withArgName("[0,1]").create()); options.addOption(OptionBuilder.withLongOpt("mutation").withDescription("Defines the mutation rate") .hasArg().withArgName("[0,100]").create()); options.addOption(OptionBuilder.withLongOpt("pop").withDescription("Defines the population size").hasArg() .withArgName("[0,1000]").create()); options.addOption(OptionBuilder.withLongOpt("iterations") .withDescription("Sets the number of iterations that each phrase will evolve").hasArg() .withArgName("[1,10000]").create()); // fitness parameters options.addOption("1", "filtall", false, "Enables all the fitness filters. This option will override any other made that involves filters"); options.addOption("P", "pitch", false, "Enables simple pitch fitness filter"); options.addOption("D", "duration", false, "Enables simple duration fitness filter"); options.addOption("S", "scale", false, "Enables scale notes fitness filter. USE THIS!"); options.addOption("T", "time", false, "Enables time fitness filter"); options.addOption("B", "dull", false, "Enables dull (boring music) fitness filter"); options.addOption("H", "high", false, "Enables high diversity of notes fitness filter"); options.addOption("R", "repetition1", false, "Enables repetition of notes fitness filter"); options.addOption("E", "repetition2", false, "Enables a different repetition of notes fitness filter"); options.addOption("A", "ascending", false, "Enables adjacent ascending notes fitness filter"); options.addOption("Z", "descending", false, "Enables adjacent descending notes fitness filter"); // options.addOption(OptionBuilder.withLongOpt("file").isRequired() // .withDescription("The file to store the produced midi") // .hasArg().withArgName("FILE").create()); options.addOption("v", "version", false, "Show version"); options.addOption("h", "help", false, "Print this screen and quit"); }
From source file:com.conversantmedia.mapreduce.tool.AnnotatedToolContext.java
@SuppressWarnings("static-access") private org.apache.commons.cli.Option initOption(Options options, Option anno, String optName) { OptionBuilder.withLongOpt(optName).withArgName(getValue(anno.argName())) .withDescription(getValue(anno.description())).isRequired(anno.required()); if (anno.argCount() > 0) { OptionBuilder.hasArgs(anno.argCount()); }/* www. j a v a 2 s. c o m*/ return OptionBuilder.create(); }
From source file:edu.uchicago.lowasser.flaginjection.Flags.java
public static Injector bootstrapFlagInjector(final String[] args, String mainClassName, List<String> packages, Module... baseModules) {//from w w w . j a v a2s . c o m Logger logger = Logger.getLogger("org.learningu.scheduling.flags.Flags"); AbstractModule linkingModule = new AbstractModule() { @Override protected void configure() { } @Provides @RuntimeArguments String[] commandLineArguments() { return args; } @Provides @Singleton Options options(Map<Flag, Type> flagsMap) { Options options = new Options(); for (Flag flag : flagsMap.keySet()) { OptionBuilder.hasArgs(); OptionBuilder.withLongOpt(flag.name()); OptionBuilder.withDescription(flag.description()); OptionBuilder.withArgName(flagsMap.get(flag).toString()); options.addOption(OptionBuilder.create()); } return options; } @Provides @Singleton CommandLine commandLine(Options options, @RuntimeArguments String[] args) { try { return new PosixParser().parse(options, args); } catch (ParseException e) { throw Throwables.propagate(e); } } }; logger.fine("Built Options module"); Injector baseInjector = Guice.createInjector(new FlagErrorModule(mainClassName), Modules.combine(Iterables.concat(Arrays.asList(baseModules), ImmutableList.of(linkingModule)))); logger.fine("Bootstrapping flag injector with command line arguments"); Injector createdInjector = baseInjector .createChildInjector(baseInjector.getInstance(FlagBootstrapModule.class)); // Use reflection to instantiate the variables in FlagClass classes for (String packageName : packages) { Reflections reflections = new Reflections(packageName); Set<Class<? extends FlagsClass>> classes = reflections.getSubTypesOf(FlagsClass.class); for (Class<? extends FlagsClass> flagClass : classes) { createdInjector.getInstance(flagClass); } } return createdInjector; }
From source file:chibi.gemmaanalysis.GeneExpressionWriterCLI.java
@SuppressWarnings("static-access") @Override/* w ww . j a va 2 s. c om*/ protected void buildOptions() { super.buildOptions(); addForceOption(null); OptionBuilder.hasArg(); OptionBuilder.withDescription("Query file containing list of gene official symbols"); OptionBuilder.withArgName("File name"); OptionBuilder.withLongOpt("queryGeneFile"); Option queryGeneFileOption = OptionBuilder.create(); addOption(queryGeneFileOption); OptionBuilder.hasArgs(); OptionBuilder.withArgName("Gene symbol(s)"); OptionBuilder.withDescription("The query gene symbol(s), comma separated"); OptionBuilder.withValueSeparator(','); OptionBuilder.withLongOpt("queryGene"); Option queryGeneOption = OptionBuilder.create(); addOption(queryGeneOption); addOption(OptionBuilder.hasArg().withArgName("outfile").withDescription("Output filename prefix") .withLongOpt("outfile").isRequired().create('o')); }
From source file:com.symbian.utils.cmdline.CmdLine.java
/** * Adds a switch to a command./*from w ww. ja v a2 s.c o m*/ * * @param aSwitchName * name of the switch * @param aIsSingle * If the switch is single. * @param aDescription * description of the switch (for help command) * @param aIsMandatory * make switch mandatory * @param aDataCheck * facility to check the validity of the parameter. */ public synchronized void addSwitch(final String aSwitchName, final boolean aIsSingle, final String aDescription, final boolean aIsMandatory, final DataAcceptable aDataCheck) { Option lOption = null; OptionBuilder.withArgName(aSwitchName); OptionBuilder.withDescription(aDescription); OptionBuilder.isRequired(aIsMandatory); OptionBuilder.hasArg(aDataCheck != null); if (!aIsSingle) { OptionBuilder.withLongOpt(aSwitchName); lOption = OptionBuilder.create(); } else { lOption = OptionBuilder.create(aSwitchName); } if (aDataCheck != null) { iParametersToCheck.add(aSwitchName); iParametersChecks.add(aDataCheck); } iOptions.addOption(lOption); }
From source file:UartEchoServer.java
public static void main(String[] aArgs) { final Options options = new Options(); options.addOption(new Option(OPTION_HELP, "print this message")); OptionBuilder.withLongOpt(OPTION_PORT); OptionBuilder.withDescription("set port COMx"); OptionBuilder.withValueSeparator('='); OptionBuilder.hasArg();/*from www . j a v a 2 s .co m*/ options.addOption(OptionBuilder.create()); OptionBuilder.withLongOpt(OPTION_BAUD); OptionBuilder.withDescription("set the baud rate"); OptionBuilder.withValueSeparator('='); OptionBuilder.hasArg(); options.addOption(OptionBuilder.create()); OptionBuilder.withLongOpt(OPTION_DATA); OptionBuilder.withDescription("set the data bits [" + DATA_BITS_5 + "|" + DATA_BITS_6 + "|" + DATA_BITS_7 + "|" + DATA_BITS_8 + "]"); OptionBuilder.withValueSeparator('='); OptionBuilder.hasArg(); options.addOption(OptionBuilder.create()); OptionBuilder.withLongOpt(OPTION_STOP); OptionBuilder.withDescription( "set the stop bits [" + STOP_BITS_1 + "|" + STOP_BITS_1_5 + "|" + STOP_BITS_2 + "]"); OptionBuilder.withValueSeparator('='); OptionBuilder.hasArg(); options.addOption(OptionBuilder.create()); OptionBuilder.withLongOpt(OPTION_PARITY); OptionBuilder.withDescription("set the parity [" + PARITY_NONE + "|" + PARITY_EVEN + "|" + PARITY_ODD + "|" + PARITY_MARK + "|" + PARITY_SPACE + "]"); OptionBuilder.withValueSeparator('='); OptionBuilder.hasArg(); options.addOption(OptionBuilder.create()); OptionBuilder.withLongOpt(OPTION_FLOW); OptionBuilder.withDescription("set the flow control [" + FLOWCONTROL_NONE + "|" + FLOWCONTROL_RTSCTS + "|" + FLOWCONTROL_XONXOFF + "]"); OptionBuilder.withValueSeparator('='); OptionBuilder.hasArg(); options.addOption(OptionBuilder.create()); final CommandLineParser parser = new PosixParser(); try { // parse the command line arguments final CommandLine commandLine = parser.parse(options, aArgs); if (commandLine.hasOption(OPTION_HELP)) { final HelpFormatter formatter = new HelpFormatter(); formatter.printHelp("UartEchoServer", options); } else { final UartEchoServer echoServer = new UartEchoServer(); echoServer.Construct(commandLine); } } catch (Exception e) { e.printStackTrace(); } }
From source file:org.apache.hadoop.hive.llap.cli.LlapStatusOptionsProcessor.java
public LlapStatusOptionsProcessor() { for (OptionConstants optionConstant : OptionConstants.values()) { OptionBuilder optionBuilder = OptionBuilder.hasArgs(optionConstant.getNumArgs()) .withArgName(optionConstant.getArgName()).withLongOpt(optionConstant.getLongOpt()) .withDescription(optionConstant.getDescription()); if (optionConstant.getShortOpt() == null) { options.addOption(optionBuilder.create()); } else {/*from www. j a v a 2 s .c o m*/ options.addOption(optionBuilder.create(optionConstant.getShortOpt())); } } }
From source file:org.dcm4che2.tool.jpg2dcm.Jpg2Dcm.java
private static CommandLine parse(String[] args) { Options opts = new Options(); OptionBuilder.withArgName("code"); OptionBuilder.hasArg();//from ww w.j a v a2 s . co m OptionBuilder.withDescription(OPT_CHARSET_DESC); OptionBuilder.withLongOpt(LONG_OPT_CHARSET); opts.addOption(OptionBuilder.create()); OptionBuilder.withArgName("file"); OptionBuilder.hasArg(); OptionBuilder.withDescription(OPT_AUGMENT_CONFIG_DESC); opts.addOption(OptionBuilder.create("c")); OptionBuilder.withArgName("file"); OptionBuilder.hasArg(); OptionBuilder.withDescription(OPT_REPLACE_CONFIG_DESC); opts.addOption(OptionBuilder.create("C")); OptionBuilder.withArgName("prefix"); OptionBuilder.hasArg(); OptionBuilder.withDescription(OPT_UID_PREFIX_DESC); OptionBuilder.withLongOpt(LONG_OPT_UID_PREFIX); opts.addOption(OptionBuilder.create()); OptionBuilder.withArgName("uid"); OptionBuilder.hasArg(); OptionBuilder.withDescription(OPT_TRANSFER_SYNTAX_DESC); OptionBuilder.withLongOpt(LONG_OPT_TRANSFER_SYNTAX); opts.addOption(OptionBuilder.create()); opts.addOption(null, LONG_OPT_MPEG, false, OPT_MPEG_DESC); opts.addOption(null, LONG_OPT_NO_APPN, false, OPT_NO_APPN_DESC); opts.addOption("h", "help", false, OPT_HELP_DESC); opts.addOption("V", "version", false, OPT_VERSION_DESC); CommandLine cl = null; try { cl = new PosixParser().parse(opts, args); } catch (ParseException e) { exit("jpg2dcm: " + e.getMessage()); throw new RuntimeException("unreachable"); } if (cl.hasOption('V')) { Package p = Jpg2Dcm.class.getPackage(); System.out.println("jpg2dcm v" + p.getImplementationVersion()); System.exit(0); } if (cl.hasOption('h') || cl.getArgList().size() != 2) { HelpFormatter formatter = new HelpFormatter(); formatter.printHelp(USAGE, DESCRIPTION, opts, EXAMPLE); System.exit(0); } return cl; }
From source file:org.dcm4che3.tool.jpg2dcm.Jpg2Dcm.java
private static CommandLine parse(String[] args) { Options opts = new Options(); OptionBuilder.withArgName("code"); OptionBuilder.hasArg();// w w w.j a v a 2 s . co m OptionBuilder.withDescription(OPT_CHARSET_DESC); OptionBuilder.withLongOpt(LONG_OPT_CHARSET); opts.addOption(OptionBuilder.create()); OptionBuilder.withArgName("file"); OptionBuilder.hasArg(); OptionBuilder.withDescription(OPT_AUGMENT_CONFIG_DESC); opts.addOption(OptionBuilder.create("c")); OptionBuilder.withArgName("file"); OptionBuilder.hasArg(); OptionBuilder.withDescription(OPT_REPLACE_CONFIG_DESC); opts.addOption(OptionBuilder.create("C")); OptionBuilder.withArgName("prefix"); OptionBuilder.hasArg(); OptionBuilder.withDescription(OPT_UID_PREFIX_DESC); OptionBuilder.withLongOpt(LONG_OPT_UID_PREFIX); opts.addOption(OptionBuilder.create()); OptionBuilder.withArgName("uid"); OptionBuilder.hasArg(); OptionBuilder.withDescription(OPT_TRANSFER_SYNTAX_DESC); OptionBuilder.withLongOpt(LONG_OPT_TRANSFER_SYNTAX); opts.addOption(OptionBuilder.create()); opts.addOption(null, LONG_OPT_MPEG, false, OPT_MPEG_DESC); opts.addOption(null, LONG_OPT_NO_APPN, false, OPT_NO_APPN_DESC); opts.addOption("h", "help", false, OPT_HELP_DESC); opts.addOption("V", "version", false, OPT_VERSION_DESC); CommandLine cl = null; try { cl = new PosixParser().parse(opts, args); } catch (ParseException e) { exit("jpg2dcm: " + e.getMessage()); throw new RuntimeException("unreachable"); } if (cl.hasOption('V')) { Package p = Jpg2Dcm.class.getPackage(); LOG.info("jpg2dcm v" + p.getImplementationVersion()); System.exit(0); } if (cl.hasOption('h') || cl.getArgList().size() != 2) { HelpFormatter formatter = new HelpFormatter(); formatter.printHelp(USAGE, DESCRIPTION, opts, EXAMPLE); System.exit(0); } return cl; }