List of usage examples for org.apache.commons.cli OptionGroup addOption
public OptionGroup addOption(Option option)
Option
to this group. From source file:sse.Main.java
@SuppressWarnings("static-access") private static Options buildOptions() { Options options = new Options(); Option input = OptionBuilder.hasArg().withArgName("file").isRequired().withDescription( "The basename of the input files. Can be either a block for search mode or a text for create mode.") .create("i"); OptionGroup mode = new OptionGroup(); Option output = OptionBuilder.hasArg().withArgName("file") .withDescription("The basename of the output files.").create("o"); Option iv = OptionBuilder.hasArg().withArgName("file") .withDescription("The file wich contains the iv and salt.").create("iv"); Option help = new Option("help", "Prints the help message."); Option verbose = new Option("v", "Enables verbose mode."); Option backend = OptionBuilder.hasArg().withArgName("backend") .withDescription("Sets the backend which is to be used. Either amazon or file-system.") .create("backend"); Option create = new Option("create", "Encrypts the given text"); Option search = OptionBuilder.hasArg().withArgName("text").withDescription("Searches for the given text.") .create("search"); Option password = OptionBuilder.hasArg().withArgName("password") .withDescription("Sets the password used for encryption.").isRequired().create("password"); mode.addOption(create); mode.addOption(search);/*from ww w .ja va 2 s . c om*/ options.addOption(output); options.addOptionGroup(mode); options.addOption(input); options.addOption(iv); options.addOption(help); options.addOption(verbose); options.addOption(backend); options.addOption(password); return options; }
From source file:treecmp.commandline.CommandLineParser.java
public Command run(String args[]) { Command cmd = null;//from ww w . j a va 2s . co m DefinedMetricsSet DMSet = DefinedMetricsSet.getInstance(); Option oS = new Option("s", S_DESC); Option oW = new Option("w", W_DESC); oW.setArgName(W_ARG); oW.setArgs(1); Option oM = new Option("m", M_DESC); Option oR = new Option("r", R_DESC); oR.setArgName(R_ARG); oR.setArgs(1); OptionGroup cmdOpts = new OptionGroup(); cmdOpts.addOption(oS); cmdOpts.addOption(oW); cmdOpts.addOption(oM); cmdOpts.addOption(oR); cmdOpts.setRequired(true); //set metric option Option oD = new Option("d", D_DESC); oD.setArgName(D_ARG); oD.setValueSeparator(' '); oD.setArgs(DMSet.size()); oD.setRequired(true); Option oI = new Option("i", I_DESC); oI.setArgName(I_ARG); oI.setArgs(1); oI.setRequired(true); Option oO = new Option("o", O_DESC); oO.setArgs(1); oO.setArgName(O_ARG); oO.setRequired(true); Option oP = new Option("P", P_DESC); Option oSS = new Option("N", SS_DESC); Option oII = new Option("I", II_DESC); Option oOO = new Option("O", OO_DESC); Option oA = new Option("A", A_DESC); OptionGroup customMOpts = new OptionGroup(); customMOpts.addOption(oOO); customMOpts.addOption(oA); Options opts = new Options(); opts.addOptionGroup(cmdOpts); opts.addOption(oD); opts.addOption(oI); opts.addOption(oO); opts.addOption(oP); opts.addOption(oSS); opts.addOption(oII); opts.addOptionGroup(customMOpts); //getting version from manifest file String version = CommandLineParser.class.getPackage().getImplementationVersion(); if (version == null) { version = ""; } String FOOTER = ""; String HEADER = " "; String APP_NAME = "TreeCmp version " + version + "\n"; GnuParser parser = new GnuParser(); HelpFormatter formatter = new HelpFormatter(); formatter.setOptionComparator(new OptOrder()); System.out.println(APP_NAME); if (args.length == 0) { formatter.printHelp(CMD_LINE_SYNTAX, HEADER, opts, FOOTER, false); return null; } try { CommandLine commandLine = parser.parse(opts, args); if (commandLine != null) { // process these values //set IO settings String inputFileName = (String) commandLine.getOptionValue(oI.getOpt()); String outputFileName = (String) commandLine.getOptionValue(oO.getOpt()); if (inputFileName == null) { System.out.println("Error: input file not specified!"); formatter.printHelp(CMD_LINE_SYNTAX, HEADER, opts, FOOTER, false); return null; } if (outputFileName == null) { System.out.println("Error: output file not specified!"); formatter.printHelp(CMD_LINE_SYNTAX, HEADER, opts, FOOTER, false); return null; } //commandLine. IOSettings IOset = IOSettings.getIOSettings(); IOset.setInputFile(inputFileName); IOset.setOutputFile(outputFileName); //custom additinal options ArrayList<Option> custOpts = new ArrayList<Option>(); if (commandLine.hasOption(oP.getOpt())) { IOset.setPruneTrees(true); custOpts.add(oP); } if (commandLine.hasOption(oSS.getOpt())) { IOset.setRandomComparison(true); custOpts.add(oSS); } if (commandLine.hasOption(oA.getOpt())) { IOset.setGenAlignments(true); custOpts.add(oA); } if (commandLine.hasOption(oOO.getOpt())) { IOset.setOptMsMcByRf(true); custOpts.add(oOO); } if (commandLine.hasOption(oII.getOpt())) { IOset.setGenSummary(true); custOpts.add(oII); } Collections.sort(custOpts, new OptOrder()); //set active metrics ActiveMetricsSet AMSet = ActiveMetricsSet.getInstance(); final String[] metrics = commandLine.getOptionValues(oD.getOpt()); for (int i = 0; i < metrics.length; i++) { final DefinedMetric definedMetric = DMSet.getDefinedMetric(metrics[i]); if (definedMetric != null) { AMSet.addMetric(definedMetric); } else { System.out.print("Error: "); System.out.println("Metric: " + metrics[i] + " is unknown\n."); formatter.printHelp(CMD_LINE_SYNTAX, HEADER, opts, FOOTER, false); return null; } } //set active command String analysisType = ""; if (commandLine.hasOption(oW.getOpt())) { String sWindowSize = (String) commandLine.getOptionValue(oW.getOpt()); int iWindowSize = Integer.parseInt(sWindowSize); cmd = new RunWCommand(1, "-w", iWindowSize); analysisType = "window comparison mode (-w) with window size: " + iWindowSize; } else if (commandLine.hasOption(oM.getOpt())) { cmd = new RunMCommand(0, "-m"); analysisType = "matrix comparison mode (-m)"; } else if (commandLine.hasOption(oS.getOpt())) { cmd = new RunSCommand(0, "-s"); analysisType = "overlapping pair comparison mode (-s)"; } else if (commandLine.hasOption(oR.getOpt())) { String sRefTreeFile = (String) commandLine.getOptionValue(oR.getOpt()); cmd = new RunRCommand(0, "-r", sRefTreeFile); analysisType = " ref-to-all comparison mode (-r)"; } else { System.out.println("Error: type of the analysis not specified correctly!"); formatter.printHelp(CMD_LINE_SYNTAX, HEADER, opts, FOOTER, false); return null; } printOptionsInEffect(analysisType, AMSet, inputFileName, outputFileName, custOpts); return cmd; } else { //Error during parsing command line return null; } } catch (ParseException ex) { log.log(Level.WARNING, "Could not parse command line arguments.", ex); System.out.println(CMD_ERROR); formatter.printHelp(CMD_LINE_SYNTAX, HEADER, opts, FOOTER, false); } catch (NumberFormatException ex) { System.out.print("Error: "); System.out.println("window size should be an integer.\n"); formatter.printHelp(CMD_LINE_SYNTAX, HEADER, opts, FOOTER, false); } return cmd; }
From source file:uk.ac.imperial.presage2.core.cli.Presage2CLI.java
private OptionGroup getCommands() { OptionGroup cmdGroup = new OptionGroup(); for (String cmd : commands.keySet()) { cmdGroup.addOption(new Option(cmd, commands.get(cmd).getAnnotation(Command.class).description())); }//w w w . java 2s.co m return cmdGroup; }