/** * Return the <code>Object</code> type of this <code>Option</code>. * * @param opt the name of the option * @return the type of this <code>Option</code> * @deprecated due to System.err message. Instead use getParsedOptionValue(String) */ @Deprecated public Object getOptionObject(String opt) { try { return getParsedOptionValue(opt); } catch (ParseException pe) { System.err.println("Exception found converting " + opt + " to desired type: " + pe.getMessage()); return null; } }
CommandLineParser cmdLineParser = new PosixParser(); Options options = new Options(); options.addOption(OptionBuilder.withLongOpt("integer-option") .withDescription("description") .withType(Number.class) .hasArg() .withArgName("argname") .create()); try { CommandLine cmdLine = cmdLineParser.parse(options, args); int value = 0; // initialize to some meaningful default value if (cmdLine.hasOption("integer-option")) { value = ((Number)cmdLine.getParsedOptionValue("integer-option")).intValue(); } System.out.println(value); } catch (ParseException e) { e.printStackTrace(); }
public static void main(String[] args) { try { CommandLine commandLine = parseArgs(args); String topic = commandLine.getOptionValue("topic"); int messages = ((Number) commandLine.getParsedOptionValue("messages")).intValue(); int producers = ((Number) commandLine.getParsedOptionValue("producers")).intValue(); String broker = commandLine.getOptionValue("broker"); String type = commandLine.getOptionValue("type"); Number timeshiftNumber = ((Number)commandLine.getParsedOptionValue("timeshift")); int timeshift = timeshiftNumber == null ? 0 : timeshiftNumber.intValue(); for (int i = 0; i < producers; ++i) { TestLogMessageProducer producer = new TestLogMessageProducer( topic, messages, type, broker, timeshift); producer.start(); } } catch (Throwable t) { LOG.error("Log message producer failed", t); System.exit(1); } } }
public static void main(String[] args) { try { CommandLine commandLine = parseArgs(args); SecorConfig config = SecorConfig.load(); FileUtil.configure(config); LogFileVerifier verifier = new LogFileVerifier(config, commandLine.getOptionValue("topic")); long startOffset = -2; long endOffset = Long.MAX_VALUE; if (commandLine.hasOption("start_offset")) { startOffset = Long.parseLong(commandLine.getOptionValue("start_offset")); if (commandLine.hasOption("end_offset")) { endOffset = Long.parseLong(commandLine.getOptionValue("end_offset")); } } int numMessages = -1; if (commandLine.hasOption("messages")) { numMessages = ((Number) commandLine.getParsedOptionValue("messages")).intValue(); } verifier.verifyCounts(startOffset, endOffset, numMessages); if (commandLine.hasOption("sequence_offsets")) { verifier.verifySequences(startOffset, endOffset); } System.out.println("verification succeeded"); } catch (Throwable t) { LOG.error("Log file verifier failed", t); System.exit(1); } } }
public static void main(String[] args) { try { CommandLine commandLine = parseArgs(args); String command = commandLine.getOptionValue("command"); if (!command.equals("delete_committed_offsets")) { throw new IllegalArgumentException( "command has to be one of \"delete_committed_offsets\""); } SecorConfig config = SecorConfig.load(); ZookeeperConnector zookeeperConnector = new ZookeeperConnector(config); String topic = commandLine.getOptionValue("topic"); if (commandLine.hasOption("partition")) { int partition = ((Number) commandLine.getParsedOptionValue("partition")).intValue(); TopicPartition topicPartition = new TopicPartition(topic, partition); zookeeperConnector.deleteCommittedOffsetPartitionCount(topicPartition); } else { zookeeperConnector.deleteCommittedOffsetTopicCount(topic); } } catch (Throwable t) { LOG.error("Zookeeper client failed", t); System.exit(1); } } }
@Test public void testGetParsedOptionValue() throws Exception { Options options = new Options(); options.addOption(OptionBuilder.hasArg().withType(Number.class).create("i")); options.addOption(OptionBuilder.hasArg().create("f")); CommandLineParser parser = new DefaultParser(); CommandLine cmd = parser.parse(options, new String[] { "-i", "123", "-f", "foo" }); assertEquals(123, ((Number) cmd.getParsedOptionValue("i")).intValue()); assertEquals("foo", cmd.getParsedOptionValue("f")); }
File outschema = (File)line.getParsedOptionValue("outschema"); job.set(AvroJob.OUTPUT_SCHEMA, Schema.parse(outschema).toString()); if (line.hasOption("outschemamap")) { job.set(AvroJob.MAP_OUTPUT_SCHEMA, Schema.parse((File)line.getParsedOptionValue("outschemamap")).toString()); job.setNumReduceTasks((Integer)line.getParsedOptionValue("reduces"));
if (cl.hasOption("t")) { try { numThreads = ((Number) cl.getParsedOptionValue("t")).intValue(); } catch (ParseException e) { throw new IOException("Failed to parse option -t into an integer", e);
/** * Retrieves a version of an option converted to a particular type. * * @param opt Name of the option. * @return The value of the argument if the option is set and has an argument, otherwise null. * @throws ParseException if the argument value cannot be converted to the specified type. */ public Object getParsedOptionValue(String opt) throws ParseException { return commandLine.getParsedOptionValue(opt); } }
private static int getColumnValue(CommandLine cmd, String opt, int defaultValue) throws ParseException { Object value = cmd.getParsedOptionValue(opt); return value == null ? defaultValue : ((Number)value).intValue() - 1; }
private static int getIntValue(CommandLine cmd, String opt, int defaultValue) throws ParseException { Object value = cmd.getParsedOptionValue(opt); return value == null ? defaultValue : ((Number)value).intValue(); }
private static double getDoubleValue(CommandLine cmd, String opt, double defaultValue) throws ParseException { Object value = cmd.getParsedOptionValue(opt); return value == null ? defaultValue : ((Number)value).doubleValue(); }
private int readThreadsCount(CommandLine cmd) throws ParseException { int threads = 0; if (cmd.hasOption("th")) { Object value = cmd.getParsedOptionValue("th"); if (value == null) { threads = Runtime.getRuntime().availableProcessors(); } else { threads = ((Number)value).intValue(); } } return threads; }
/** * Return the <code>Object</code> type of this <code>Option</code>. * * @param opt the name of the option * @return the type of this <code>Option</code> * @deprecated due to System.err message. Instead use getParsedOptionValue(String) */ public Object getOptionObject(String opt) { try { return getParsedOptionValue(opt); } catch(ParseException pe) { System.err.println("Exception found converting " + opt + " to desired type: " + pe.getMessage() ); return null; } }
/** * Process command line parameters. * * @param cmd Command line parameters. * @throws Exception Unexpected exception. */ private SchemaAssembler(CommandLine cmd) throws Exception { template = (File) cmd.getParsedOptionValue("template"); assertExists(template, "Template file"); config = (File) cmd.getParsedOptionValue("config"); assertExists(config, "Configuration file"); outdir = (File) cmd.getParsedOptionValue("outdir"); version = cmd.getOptionValue("version"); }
private String validateAndGetProtocolSuite() throws ParseException { Object suiteObj = this.cmd.getParsedOptionValue("s"); String suite = ((String) suiteObj).toLowerCase(); if (!CmdLineProtocolSuite.getSupportedProtocolSuites().contains(suite)) { throw new ParseException("Unknown protocol suite: " + suite); } return suite; }
protected void getOptionsValue(CommandLine line) throws ParseException { ip = line.getOptionValue(IP_KEY); if (line.hasOption(PORT_KEY)) { port = ((Number) line.getParsedOptionValue(PORT_KEY)).intValue(); } else { port = DEFAULT_PORT; } }
@Override protected void getOptionsValue(CommandLine line) throws ParseException { super.getOptionsValue(line); if (line.hasOption(SIZE_KEY)) { size = ((Number)line.getParsedOptionValue(SIZE_KEY)).intValue(); } else { size = SIZE_DEFAULT; } if (line.hasOption(LOOP_KEY)) { loop = ((Number)line.getParsedOptionValue(LOOP_KEY)).intValue(); } else { loop = LOOP_DEFAULT; } }
@Override protected void getOptionsValue(CommandLine line) throws ParseException { super.getOptionsValue(line); if (line.hasOption(QUEUEDEPTH_KEY)) { queueDepth = ((Number)line.getParsedOptionValue(QUEUEDEPTH_KEY)).intValue(); } else { queueDepth = QUEUEDEPTH_DEFAULT; } }
public void run(String[] args) throws Exception { CommandLine line = createCommandLineOptions(args); File modelFile = (File) line.getParsedOptionValue(MODEL_OPTION); File xjcDir = (File) line.getParsedOptionValue(XJC_OPTION); // Analyze the model files: Model model = new Model(); ModelAnalyzer modelAnalyzer = new ModelAnalyzer(); modelAnalyzer.setModel(model); modelAnalyzer.analyzeSource(modelFile); // Generate the enums: if (xjcDir != null) { FileUtils.forceMkdir(xjcDir); enumGenerator.setOutDir(xjcDir); enumGenerator.generate(model); } }