List of usage examples for org.apache.commons.cli PosixParser parse
public CommandLine parse(Options options, String[] arguments) throws ParseException
arguments
based on the specifed Options . From source file:com.damon.rocketmq.example.operation.Producer.java
public static CommandLine buildCommandline(String[] args) { final Options options = new Options(); Option opt = new Option("h", "help", false, "Print help"); opt.setRequired(false);//from w ww .j a v a2 s. co m options.addOption(opt); opt = new Option("g", "producerGroup", true, "Producer Group Name"); opt.setRequired(true); options.addOption(opt); opt = new Option("t", "topic", true, "Topic Name"); opt.setRequired(true); options.addOption(opt); opt = new Option("a", "tags", true, "Tags Name"); opt.setRequired(true); options.addOption(opt); opt = new Option("k", "keys", true, "Keys Name"); opt.setRequired(true); options.addOption(opt); opt = new Option("c", "msgCount", true, "Message Count"); opt.setRequired(true); options.addOption(opt); PosixParser parser = new PosixParser(); HelpFormatter hf = new HelpFormatter(); hf.setWidth(110); CommandLine commandLine = null; try { commandLine = parser.parse(options, args); if (commandLine.hasOption('h')) { hf.printHelp("producer", options, true); return null; } } catch (ParseException e) { hf.printHelp("producer", options, true); return null; } return commandLine; }
From source file:com.damon.rocketmq.example.operation.Consumer.java
public static CommandLine buildCommandline(String[] args) { final Options options = new Options(); Option opt = new Option("h", "help", false, "Print help"); opt.setRequired(false);/*from w w w .j av a 2 s . co m*/ options.addOption(opt); opt = new Option("g", "consumerGroup", true, "Consumer Group Name"); opt.setRequired(true); options.addOption(opt); opt = new Option("t", "topic", true, "Topic Name"); opt.setRequired(true); options.addOption(opt); opt = new Option("s", "subscription", true, "subscription"); opt.setRequired(false); options.addOption(opt); opt = new Option("f", "returnFailedHalf", true, "return failed result, for half message"); opt.setRequired(true); options.addOption(opt); PosixParser parser = new PosixParser(); HelpFormatter hf = new HelpFormatter(); hf.setWidth(110); CommandLine commandLine = null; try { commandLine = parser.parse(options, args); if (commandLine.hasOption('h')) { hf.printHelp("producer", options, true); return null; } } catch (ParseException e) { hf.printHelp("producer", options, true); return null; } return commandLine; }
From source file:com.alibaba.rocketmq.example.operation.Consumer.java
public static CommandLine buildCommandline(String[] args) { final Options options = new Options(); // //////////////////////////////////////////////////// Option opt = new Option("h", "help", false, "Print help"); opt.setRequired(false);// w w w . j a va2 s. c o m options.addOption(opt); opt = new Option("g", "consumerGroup", true, "Consumer Group Name"); opt.setRequired(true); options.addOption(opt); opt = new Option("t", "topic", true, "Topic Name"); opt.setRequired(true); options.addOption(opt); opt = new Option("s", "subscription", true, "subscription"); opt.setRequired(false); options.addOption(opt); opt = new Option("f", "returnFailedHalf", true, "return failed result, for half message"); opt.setRequired(true); options.addOption(opt); // //////////////////////////////////////////////////// PosixParser parser = new PosixParser(); HelpFormatter hf = new HelpFormatter(); hf.setWidth(110); CommandLine commandLine = null; try { commandLine = parser.parse(options, args); if (commandLine.hasOption('h')) { hf.printHelp("producer", options, true); return null; } } catch (ParseException e) { hf.printHelp("producer", options, true); return null; } return commandLine; }
From source file:com.alibaba.rocketmq.example.operation.Producer.java
public static CommandLine buildCommandline(String[] args) { final Options options = new Options(); // //////////////////////////////////////////////////// Option opt = new Option("h", "help", false, "Print help"); opt.setRequired(false);//from w w w. j a v a2 s . c o m options.addOption(opt); opt = new Option("g", "producerGroup", true, "Producer Group Name"); opt.setRequired(true); options.addOption(opt); opt = new Option("t", "topic", true, "Topic Name"); opt.setRequired(true); options.addOption(opt); opt = new Option("a", "tags", true, "Tags Name"); opt.setRequired(true); options.addOption(opt); opt = new Option("k", "keys", true, "Keys Name"); opt.setRequired(true); options.addOption(opt); opt = new Option("c", "msgCount", true, "Message Count"); opt.setRequired(true); options.addOption(opt); // //////////////////////////////////////////////////// PosixParser parser = new PosixParser(); HelpFormatter hf = new HelpFormatter(); hf.setWidth(110); CommandLine commandLine = null; try { commandLine = parser.parse(options, args); if (commandLine.hasOption('h')) { hf.printHelp("producer", options, true); return null; } } catch (ParseException e) { hf.printHelp("producer", options, true); return null; } return commandLine; }
From source file:edu.umd.cs.guitar.replayer.sel.NewGReplayerConfiguration.java
public void parseArguments(String[] args) throws ParseException { PosixParser parser = new PosixParser(); cmd = parser.parse(opts, args); if (cmd.hasOption("help")) { // Print help and exit with non-zero status code HelpFormatter formatter = new HelpFormatter(); formatter.printHelp("ReplayerMain", opts); System.exit(1);//from ww w .j a v a 2 s. com } GUI_FILE = cmd.getOptionValue("gui-file", "GUITAR-Default.GUI"); EFG_FILE = cmd.getOptionValue("efg-file", "GUITAR-Default.EFG"); TESTCASE = cmd.getOptionValue("testcase"); GUI_STATE_FILE = cmd.getOptionValue("gui-state", "GUITAR-Default.STA"); LOG_FILE = cmd.getOptionValue("log-file", Util.getTimeStamp() + ".log"); CONFIG_FILE = cmd.getOptionValue("config-file", "configuration.xml"); DELAY = Integer.parseInt(cmd.getOptionValue("delay", "5000")); ARGUMENT_LIST = cmd.getOptionValue("args", ""); INITIAL_WAITING_TIME = Integer.parseInt(cmd.getOptionValue("initial-wait", "500")); }
From source file:edu.umd.cs.guitar.replayer.GReplayerConfiguration.java
public void parseArguments(String[] args) throws ParseException { PosixParser parser = new PosixParser(); cmd = parser.parse(opts, args); if (cmd.hasOption("help")) { // Print help and exit with non-zero status code HelpFormatter formatter = new HelpFormatter(); formatter.printHelp("ReplayerMain", opts); System.exit(1);//from w w w .j a v a2 s .c o m } GUI_FILE = cmd.getOptionValue("gui-file", "GUITAR-Default.GUI"); EFG_FILE = cmd.getOptionValue("efg-file", "GUITAR-Default.EFG"); TESTCASE = cmd.getOptionValue("testcase"); GUI_STATE_FILE = cmd.getOptionValue("gui-state", "GUITAR-Default.STA"); LOG_FILE = cmd.getOptionValue("log-file", Util.getTimeStamp() + ".log"); CONFIG_FILE = cmd.getOptionValue("config-file", "configuration.xml"); DELAY = Integer.parseInt(cmd.getOptionValue("delay", "500")); ARGUMENT_LIST = cmd.getOptionValue("args", ""); INITIAL_WAITING_TIME = Integer.parseInt(cmd.getOptionValue("initial-wait", "500")); //come on, why is this not pushing? REPLAYER_MODE = Integer.parseInt(cmd.getOptionValue("mode", "0")); }
From source file:com.aliyun.odps.udf.local.Main.java
public void run(String[] args) throws LocalRunException { try {//from w w w. ja va 2 s .com PosixParser parser = new PosixParser(); CommandLine cmdl = parser.parse(options, args); validArgments(cmdl); String defaultProject = cmdl.getOptionValue("project"); String endpoint = cmdl.getOptionValue("endpoint"); String accessId = cmdl.getOptionValue("access-id"); String accessKey = cmdl.getOptionValue("access-key"); Account account = new AliyunAccount(accessId, accessKey); Odps odps = new Odps(account); odps.setEndpoint(endpoint); odps.setDefaultProject(defaultProject); BaseRunner runner = RunnerFactory.getRunner(cmdl, odps); InputSource inputSource = getInputSource(cmdl); Object[] data; while ((data = inputSource.getNextRow()) != null) { runner.feed(data); } List<Object[]> result = runner.yield(); for (Object[] record : result) { System.out.println(StringUtils.join(record, ",")); } } catch (ParseException e) { throw new LocalRunException(e); } catch (LocalRunException e) { throw e; } catch (UDFException e) { throw new LocalRunException(e); } catch (IOException e) { throw new LocalRunException(e); } }
From source file:com.bc.fiduceo.post.PostProcessingTool_IOTest.java
@Test public void testInitialisation() throws Exception { final Options options = PostProcessingTool.getOptions(); final PosixParser parser = new PosixParser(); final CommandLine commandLine = parser.parse(options, new String[] { "-j", processingConfigName, "-i", "/mmd_files", "-start", "2011-123", "-end", "2011-124", "-c", configDir.getPath() }); final FileWriter fileWriter = new FileWriter(new File(configDir, "system-config.xml")); fileWriter.write("<system-config></system-config>"); fileWriter.close();/* w w w.j a v a 2 s .c om*/ final PostProcessingContext context = PostProcessingTool.initializeContext(commandLine); final String separator = FileSystems.getDefault().getSeparator(); assertEquals(separator + "mmd_files", context.getMmdInputDirectory().toString()); assertEquals("03-May-2011 00:00:00", ProductData.UTC.createDateFormat().format(context.getStartDate())); assertEquals("04-May-2011 23:59:59", ProductData.UTC.createDateFormat().format(context.getEndDate())); final SystemConfig sysConfig = context.getSystemConfig(); assertNotNull(sysConfig); assertNull(sysConfig.getArchiveConfig()); final PostProcessingConfig config = context.getProcessingConfig(); assertNotNull(config); final List<Element> postProcessingElements = config.getPostProcessingElements(); assertNotNull(postProcessingElements); assertEquals("java.util.Collections$UnmodifiableList", postProcessingElements.getClass().getTypeName()); assertEquals(1, postProcessingElements.size()); assertEquals(TAG_NAME_SPHERICAL_DISTANCE, postProcessingElements.get(0).getName()); }
From source file:com.sangachy.license.LicenseHelperCommand.java
public SingleTask parser(String[] args) { options.addOption("h", "help", false, "?"); options.addOption("u", "upload", false, "License"); options.addOption("a", "apply", false, "License"); options.addOption("tp", "temp-path", true, "License ?"); options.addOption("lp", "lic-path", true, "License ?"); options.addOption("e", "esn-key", true, "ESN ?"); options.addOption("ek", "env-key", true, ""); PosixParser basicParser = new PosixParser(); CommandLine commandLine;//from w ww . j a v a 2s . com try { commandLine = basicParser.parse(options, args); if (commandLine.getOptions().length <= 0) { System.out.println("??0?"); printHelp(); return null; } if (commandLine.getOptions().length > 0) { if (commandLine.hasOption("h")) { printHelp(); return null; } if (!commandLine.hasOption("a") && !commandLine.hasOption("u")) { System.out.println("????"); printHelp(); return null; } if (commandLine.hasOption("a")) { return getApplyLicenseTask(commandLine); } if (commandLine.hasOption("u")) { return getUploadTask(commandLine); } } return null; } catch (ParseException e) { System.out.println(e.getMessage()); printHelp(); return null; } }
From source file:main.CommandLineParser.java
private CommandLine parseOptions(String[] args) { PosixParser parser = new PosixParser(); // TODO use GNU parser? CommandLine cmd;/*from w w w.jav a2 s . c om*/ try { cmd = parser.parse(options.all, args); } catch (ParseException e) { printHelp(); return null; } if (hasOption(cmd, options.help)) { printHelp(); return null; } return cmd; }