List of usage examples for org.apache.commons.cli Options addOptionGroup
public Options addOptionGroup(OptionGroup group)
From source file:pyromaniac.AcaciaMain.java
/** * The main method./*ww w. j a va 2 s . co m*/ * * @param args the arguments */ @SuppressWarnings("static-access") public static void main(String[] args) { AcaciaMain am = new AcaciaMain(); Options options = new Options(); OptionGroup runType = new OptionGroup(); Option genConfigFile = OptionBuilder.withArgName("file").hasArg() .withDescription("Write default config to this file").create("g"); Option runFromConfig = OptionBuilder.withArgName("file").hasArg() .withDescription("Run Acacia with this config").create("c"); Option runGUI = OptionBuilder.withDescription("Run Acacia GUI").create("u"); Option help = OptionBuilder.withDescription("Show this help message").create("h"); Option version = OptionBuilder.withDescription("Version").create("v"); Option property = OptionBuilder.withArgName("property=value").hasArgs(2).withValueSeparator() .withDescription("use value for given property [when running from command line]").create("D"); runType.addOption(genConfigFile); runType.addOption(runFromConfig); runType.addOption(runGUI); runType.addOption(help); runType.addOption(version); runType.addOption(property); //this indicates the user is running from the command line without a config. options.addOptionGroup(runType); try { CommandLineParser parser = new PosixParser(); CommandLine clObj = parser.parse(options, args); if (!(clObj.hasOption('g') ^ clObj.hasOption('c') ^ clObj.hasOption('u') ^ clObj.hasOption('D') ^ clObj.hasOption('v'))) { usage(options); } if (clObj.hasOption('g')) { String config = clObj.getOptionValue('g'); am.generateConfig(config); System.exit(0); } else if (clObj.hasOption('c')) { String config = clObj.getOptionValue('c'); HashMap<String, String> settings = am.loadConfigFromFile(config); am.runAcacia(settings); } else if (clObj.hasOption('u')) { am.runAcacia(null); } else if (clObj.hasOption('v')) { System.out.println("Acacia version: " + AcaciaEngine.getVersion()); System.exit(0); } else if (clObj.hasOption('D')) { //running from command line... HashMap<String, String> settings = am.populateSettingsFromCommandLine(clObj); am.runAcacia(settings); } else { usage(options); } } catch (ParseException pe) { System.out.println(pe.getMessage()); pe.printStackTrace(); usage(options); } catch (Exception e) { e.printStackTrace(); am.cleanExit(null, e); } }
From source file:scalabilityTests.scenarios.SchedulerJobSubmission.java
private static void addCommandLineOptions(Options options) { Option help = new Option("h", "help", false, "Display this help"); help.setRequired(false);//w ww . ja v a 2 s . c o m options.addOption(help); Option xmlDescriptor = new Option("ad", "gcmad", true, "path to the GCM Aplication Descriptor to be used"); xmlDescriptor.setArgName("GCMA_xml"); xmlDescriptor.setArgs(1); xmlDescriptor.setRequired(true); options.addOption(xmlDescriptor); Option vnode = new Option("vn", "virtualNode", true, "the name of the virtual node which identifies the nodes onto which the Active Object Actors will be deployed"); vnode.setArgName("AO_nodes"); vnode.setArgs(1); vnode.setRequired(true); options.addOption(vnode); Option schedulerUrl = new Option("u", "schedulerUrl", true, "the URL of the Scheduler"); schedulerUrl.setArgName("schedulerURL"); schedulerUrl.setArgs(1); schedulerUrl.setRequired(true); options.addOption(schedulerUrl); Option username = new Option("l", "login", true, "The username to join the Scheduler"); username.setArgName("login"); username.setArgs(1); username.setRequired(false); options.addOption(username); Option password = new Option("p", "password", true, "The password to join the Scheduler"); password.setArgName("pwd"); password.setArgs(1); password.setRequired(false); options.addOption(password); Option loginFile = new Option("lf", "loginFile", true, "The path to a file containing valid username:password combinations for the Scheduler"); loginFile.setArgName("login_cfg"); loginFile.setArgs(1); loginFile.setRequired(false); options.addOption(loginFile); Option jobDescriptor = new Option("j", "jobDesc", true, "The path to the XML job descriptor"); jobDescriptor.setArgName("XML_Job_Descriptor"); jobDescriptor.setArgs(1); jobDescriptor.setRequired(true); options.addOption(jobDescriptor); Option registerListeners = new Option("rl", "listener", false, "Register the specified Scheduler listener for each user. If no listener is specified, then a 'simple' scheduler listener will be registered"); registerListeners.setRequired(false); registerListeners.setOptionalArg(true); registerListeners.setArgs(1); registerListeners.setArgName("listenerClassName"); options.addOption(registerListeners); Option jobRepetition = new Option("rp", "repeats", true, "The number of times the job will be submitted(optional parameter; by default it will be set to 1)"); jobRepetition.setRequired(false); jobRepetition.setArgName("jobRepeats"); jobRepetition.setArgs(1); options.addOption(jobRepetition); Option jobResult = new Option("jr", "jobResult", false, "Fetch the result for the submitted jobs. Optional parameter, defaults to false"); jobResult.setRequired(false); options.addOption(jobResult); OptionGroup initialStateGroup = new OptionGroup(); initialStateGroup.setRequired(false); Option gui = new Option("gu", "gui", false, "Simulate an user which interacts with the Scheduler using a GUI(all scheduler state will be downloaded at login)"); gui.setRequired(false); initialStateGroup.addOption(gui); Option cli = new Option("cu", "cli", false, "Simulate an user which interacts with the Scheduler using a CLI(the scheduler state will NOT be downloaded at login)"); cli.setRequired(false); initialStateGroup.addOption(cli); options.addOptionGroup(initialStateGroup); Option myEventsOnly = new Option("me", "myEvsOnly", false, "While registering a listener, get only the events which concern me"); myEventsOnly.setRequired(false); options.addOption(myEventsOnly); }
From source file:scoutdoc.main.Main.java
/** * @param args/*from www .ja v a 2 s .c o m*/ */ public static void main(String[] args) { Option optHelp = new Option(HELP_ID, "help", false, "print this message"); Option optProp = new Option(PROP_ID, "config", true, "configuration file"); optProp.setArgName("file"); //source Option optTask = new Option(SOURCE_TASKS_ID, "task", true, "(source) one or many task files"); optTask.setArgName("files"); optTask.setArgs(Option.UNLIMITED_VALUES); Option optAllPages = new Option(SOURCE_ALL_PAGES_ID, "pages", false, "(source) use the pages contained in the source folder"); Option optListPages = new Option(SOURCE_LIST_ID, "list", true, "(source) list of pages contained in the file"); optListPages.setArgName("file"); Option optRecentChange = new Option(SOURCE_RECENT_CHANGES_ID, "recent-changes", false, "(source) use the pages from the wiki recent changes"); Option optRss = new Option(SOURCE_RSS_ID, "rss", false, "(source) use the pages from the rss feed of the wiki"); OptionGroup sourceGroup = new OptionGroup(); sourceGroup.setRequired(true); sourceGroup.addOption(optTask); sourceGroup.addOption(optAllPages); sourceGroup.addOption(optListPages); sourceGroup.addOption(optRecentChange); sourceGroup.addOption(optRss); Option optfilter = new Option(SOURCE_FILTER_ID, "filter", true, "Filter for list of pages used as source"); optfilter.setArgName("class"); List<String> values = Lists.newArrayList(); for (Operation o : Operation.values()) { values.add(o.name()); } Option optOperation = new Option(OPERATION_ID, "operation", true, "operation: " + Joiner.on(", ").join(values)); optOperation.setArgName("operations"); optOperation.setArgs(Option.UNLIMITED_VALUES); optOperation.setRequired(true); Option optOutputCheckstyle = new Option(OUTPUT_CHECKSTYLE_ID, "output-checkstyle", true, "(CHECK output) create a xml checkstyle file (<filename> is optional. Default: " + DEFAULT_CHECKSTYLE_NAME + ")"); optOutputCheckstyle.setArgName("filename"); optOutputCheckstyle.setOptionalArg(true); Option optOutputDashboard = new Option(OUTPUT_DASHBOARD_ID, "output-dashboard", true, "(CHECK output) create an html dashboard (<folder> is optional. Default: " + DEFAULT_DASHBOARD_NAME + ")"); optOutputDashboard.setArgName("folder"); optOutputDashboard.setOptionalArg(true); Options options = new Options(); options.addOption(optHelp); options.addOption(optProp); options.addOptionGroup(sourceGroup); options.addOption(optfilter); options.addOption(optOperation); options.addOption(optOutputCheckstyle); options.addOption(optOutputDashboard); try { CommandLineParser parser = new GnuParser(); CommandLine cmd = parser.parse(options, args); if (cmd.hasOption(HELP_ID)) { printHelpAndExit(options); } if (cmd.hasOption(PROP_ID)) { ProjectProperties.initProperties(cmd.getOptionValue(PROP_ID)); } Pages.initPageList(); List<Operation> operations = readOptionEnum(cmd, optOperation, Operation.class); List<Task> tasks = readTasks(cmd, optTask); Collection<Page> pageList; if (cmd.hasOption(SOURCE_ALL_PAGES_ID)) { pageList = PageUtility.loadPages(ProjectProperties.getFolderWikiSource()); } else if (cmd.hasOption(SOURCE_LIST_ID)) { String name = cmd.getOptionValue(SOURCE_LIST_ID); try { pageList = PageUtility.readList(name); } catch (IOException e) { throw new MissingArgumentException("IOException for file <" + name + "> for <" + optListPages.getLongOpt() + "> : " + e.getMessage()); } } else { pageList = Collections.emptyList(); } IPageFilter filter; if (cmd.hasOption(SOURCE_FILTER_ID)) { if (tasks.size() > 0) { throw new MissingArgumentException("Filter <" + optfilter.getLongOpt() + "> is not allowed for source <" + optTask.getLongOpt() + ">."); } filter = newInstance(cmd.getOptionValue(SOURCE_FILTER_ID), IPageFilter.class, new AcceptAllPageFilter()); } else { filter = new AcceptAllPageFilter(); } List<Page> pages = Lists.newArrayList(); for (Page page : pageList) { if (filter.keepPage(page)) { pages.add(page); } } if (operations.contains(Operation.FETCH)) { if (pages.size() > 0) { ScoutDocFetch sdf = new ScoutDocFetch(); RelatedPagesStrategy strategy; if (cmd.hasOption(SOURCE_ALL_PAGES_ID)) { strategy = RelatedPagesStrategy.NO_RELATED_PAGES; } else if (cmd.hasOption(SOURCE_LIST_ID)) { strategy = RelatedPagesStrategy.IMAGES_TEMPLATES_AND_LINKS; } else { throw new IllegalStateException("Page list comes from an unexpected option"); } sdf.execute(pages, strategy); } else if (cmd.hasOption(SOURCE_RECENT_CHANGES_ID)) { ScoutDocFetch sdf = new ScoutDocFetch(); sdf.executeRecentChanges(filter); } else if (cmd.hasOption(SOURCE_RSS_ID)) { ScoutDocFetch sdf = new ScoutDocFetch(); sdf.executeRss(filter); } else if (tasks.size() > 0) { for (Task task : tasks) { ScoutDocFetch sdf = new ScoutDocFetch(); sdf.execute(task); } } else { throw new MissingArgumentException("Missing a source"); } } if (operations.contains(Operation.CHECK)) { ScoutDocCheck sdc = new ScoutDocCheck(); List<Check> checks = Lists.newArrayList(); ensureNotSet(cmd, optRecentChange, Operation.CHECK); ensureNotSet(cmd, optRss, Operation.CHECK); if (pages.size() > 0) { checks = sdc.analysePages(pages); } else if (tasks.size() > 0) { for (Task task : tasks) { ScoutDocCheck sdcForTask = new ScoutDocCheck(); checks.addAll(sdcForTask.execute(task)); } } else { throw new MissingArgumentException("Missing a source"); } //output: if (cmd.hasOption(OUTPUT_CHECKSTYLE_ID)) { String fileName = cmd.getOptionValue(OUTPUT_CHECKSTYLE_ID, DEFAULT_CHECKSTYLE_NAME); sdc.writeCheckstyleFile(checks, fileName); } if (cmd.hasOption(OUTPUT_DASHBOARD_ID)) { String folderName = cmd.getOptionValue(OUTPUT_DASHBOARD_ID, DEFAULT_DASHBOARD_NAME); sdc.writeDashboardFiles(checks, folderName); } } if (operations.contains(Operation.CONVERT)) { ensureNotSet(cmd, optAllPages, Operation.CONVERT); ensureNotSet(cmd, optListPages, Operation.CONVERT); ensureNotSet(cmd, optRecentChange, Operation.CONVERT); ensureNotSet(cmd, optRss, Operation.CONVERT); if (tasks.size() > 0) { for (Task task : tasks) { ScoutDocConverter sdc = new ScoutDocConverter(); sdc.execute(task); } } else { throw new MissingArgumentException("Missing a source"); } } } catch (MissingOptionException e) { // Check if it is an error or if optHelp was selected. boolean help = false; try { Options helpOptions = new Options(); helpOptions.addOption(optHelp); CommandLineParser parser = new PosixParser(); CommandLine line = parser.parse(helpOptions, args); if (line.hasOption(HELP_ID)) { help = true; } } catch (Exception ex) { ex.printStackTrace(); } if (!help) { System.err.println(e.getMessage()); System.err.flush(); } printHelpAndExit(options); } catch (MissingArgumentException e) { System.err.println(e.getMessage()); printHelpAndExit(options); } catch (ParseException e) { System.err.println("Error while parsing the command line: " + e.getMessage()); System.exit(1); } catch (Exception e) { e.printStackTrace(); } }
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);//w ww. ja v a 2 s . com mode.addOption(search); 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 w w w .ja v a 2 s. c o 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
protected void printHelp() { HelpFormatter formatter = new HelpFormatter(); Options cmdOpts = new Options(); cmdOpts.addOptionGroup(getCommands()); formatter.setOptPrefix(""); formatter.printHelp("presage2-cli <command> [OPTIONS]", cmdOpts); }