org.apache.commons.cli.BasicParser Java Examples
The following examples show how to use
org.apache.commons.cli.BasicParser.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: UpgradeCounterValues.java From datawave with Apache License 2.0 | 6 votes |
private void parseConfig(String[] args) throws ParseException { CommandLine cl = new BasicParser().parse(options, args); instanceName = cl.getOptionValue(instanceNameOpt.getOpt()); zookeepers = cl.getOptionValue(zookeeperOpt.getOpt()); username = cl.getOptionValue(usernameOpt.getOpt()); password = cl.getOptionValue(passwordOpt.getOpt()); tableName = cl.getOptionValue(tableNameOpt.getOpt()); ranges = new ArrayList<>(); if (!cl.hasOption(rangesOpt.getOpt())) { System.out.println("NOTE: no ranges specified on the command line. Scanning the entire table."); ranges.add(new Range()); } else { for (String rangeStr : cl.getOptionValues(rangesOpt.getOpt())) { String[] startEnd = rangeStr.split("\\s*,\\s*"); ranges.add(new Range(startEnd[0], false, startEnd[1], false)); } System.out.println("Using ranges: " + ranges); } if (cl.hasOption(bsThreadsOpt.getOpt())) bsThreads = Integer.parseInt(cl.getOptionValue(bsThreadsOpt.getOpt())); if (cl.hasOption(bwThreadsOpt.getOpt())) bwThreads = Integer.parseInt(cl.getOptionValue(bwThreadsOpt.getOpt())); if (cl.hasOption(bwMemoryOpt.getOpt())) bwMemory = Long.parseLong(cl.getOptionValue(bwMemoryOpt.getOpt())); }
Example #2
Source File: PostmanCollectionRunner.java From postman-runner with Apache License 2.0 | 6 votes |
public static void main(String[] args) throws Exception { Options options = new Options(); options.addOption(ARG_COLLECTION, true, "File name of the POSTMAN collection."); options.addOption(ARG_ENVIRONMENT, true, "File name of the POSTMAN environment variables."); options.addOption(ARG_FOLDER, true, "(Optional) POSTMAN collection folder (group) to execute i.e. \"My Use Cases\""); options.addOption(ARG_HALTONERROR, false, "(Optional) Stop on first error in POSTMAN folder."); CommandLineParser parser = new BasicParser(); CommandLine cmd = parser.parse(options, args); String colFilename = cmd.getOptionValue(ARG_COLLECTION); String envFilename = cmd.getOptionValue(ARG_ENVIRONMENT); String folderName = cmd.getOptionValue(ARG_FOLDER); boolean haltOnError = cmd.hasOption(ARG_HALTONERROR); if (colFilename == null || colFilename.isEmpty() || envFilename == null || envFilename.isEmpty()) { // automatically generate the help statement HelpFormatter formatter = new HelpFormatter(); formatter.printHelp("postman-runner", options); return; } PostmanCollectionRunner pcr = new PostmanCollectionRunner(); pcr.runCollection(colFilename, envFilename, folderName, haltOnError, false, null); }
Example #3
Source File: DistributedLogServerApp.java From distributedlog with Apache License 2.0 | 6 votes |
private void run() { try { logger.info("Running distributedlog server : args = {}", Arrays.toString(args)); BasicParser parser = new BasicParser(); CommandLine cmdline = parser.parse(options, args); runCmd(cmdline); } catch (ParseException pe) { logger.error("Argument error : {}", pe.getMessage()); printUsage(); Runtime.getRuntime().exit(-1); } catch (IllegalArgumentException iae) { logger.error("Argument error : {}", iae.getMessage()); printUsage(); Runtime.getRuntime().exit(-1); } catch (ConfigurationException ce) { logger.error("Configuration error : {}", ce.getMessage()); printUsage(); Runtime.getRuntime().exit(-1); } catch (IOException ie) { logger.error("Failed to start distributedlog server : ", ie); Runtime.getRuntime().exit(-1); } catch (ClassNotFoundException cnf) { logger.error("Failed to start distributedlog server : ", cnf); Runtime.getRuntime().exit(-1); } }
Example #4
Source File: AdeAnalysisOutputCompare.java From ade with GNU General Public License v3.0 | 6 votes |
/** * Parses the arguments passed into the program. * * @param args * an array of String that contains all values passed into the * program * @throws ParseException * if there is an error parsing arguments */ private void parseArgs(String[] args) throws ParseException { final Options options = getCmdLineOptions(); final CommandLineParser parser = new BasicParser(); CommandLine cmd = null; /* * Parse the args according to the options definition. Will throw * MissingOptionException when a required option is not specified or the * more generic ParseException if there is any other error parsing the * arguments. */ cmd = parser.parse(options, args); if (cmd.hasOption("b")) { setBaselinePath(cmd.getOptionValue("b")); } }
Example #5
Source File: NeedingHelpGoPackageFinder.java From spark-on-k8s-gcp-examples with Apache License 2.0 | 6 votes |
public static void main(String[] args) throws Exception { Options opts = new Options(); opts.addOption("usesample", false, "Use the sample tables if present."); CommandLineParser parser = new BasicParser(); CommandLine cmd = parser.parse(opts, args); args = cmd.getArgs(); if (args.length != 3) { System.err.println("Usage: NeedingHelpGoPackageFinder " + "<GCP project ID for billing> " + "<BigQuery dataset for output tables> " + "<GCS bucket used by BigQuery for temporary data>"); System.exit(1); } String projectId = args[0]; String bigQueryDataset = args[1]; String gcsBucket = args[2]; NeedingHelpGoPackageFinder finder = new NeedingHelpGoPackageFinder(projectId, bigQueryDataset, gcsBucket, cmd.hasOption("usesample")); finder.run(); }
Example #6
Source File: CommandUtils.java From super-cloudops with Apache License 2.0 | 6 votes |
/** * Build parsing required options. * * @param args * @return * @throws ParseException */ public CommandLine build(String args[]) throws ParseException { CommandLine line = null; try { line = new BasicParser().parse(options, args); if (log.isInfoEnabled()) { // Print input argument list. List<String> printArgs = asList(line.getOptions()).stream() .map(o -> o.getOpt() + "|" + o.getLongOpt() + "=" + o.getValue()).collect(toList()); log.info("Parsed commond line args: {}", printArgs); } } catch (Exception e) { new HelpFormatter().printHelp(120, "\n", "", options, ""); throw new ParseException(e.getMessage()); } return line; }
Example #7
Source File: EmbeddedZookeeper.java From brooklin with BSD 2-Clause "Simplified" License | 6 votes |
private static CommandLine parseArgs(String[] args) { Options options = new Options(); options.addOption("p", "port", true, "Zookeeper port number to use"); options.addOption("l", "logDir", true, "Zookeeper logDir"); options.addOption("s", "snapshotDir", true, "Zookeeper snapshotDir"); // Parse the command line options CommandLineParser parser = new BasicParser(); CommandLine commandLine; try { commandLine = parser.parse(options, args); } catch (Exception e) { commandLine = null; LOG.error(e.getMessage()); } return commandLine; }
Example #8
Source File: CmdLineOpts.java From yb-sample-apps with Apache License 2.0 | 6 votes |
private static void parseHelpDetailed(String[] args, Options options) throws Exception { Options helpOptions = new Options(); helpOptions.addOption("help", true, "Print help."); CommandLineParser helpParser = new BasicParser(); CommandLine helpCommandLine = null; try { helpCommandLine = helpParser.parse(helpOptions, args); } catch (org.apache.commons.cli.MissingArgumentException e1) { // This is ok since there was no help argument passed. return; } catch (ParseException e) { return; } if (helpCommandLine.hasOption("help")) { printUsageDetails(options, "Usage:", helpCommandLine.getOptionValue("help")); System.exit(0); } }
Example #9
Source File: DistributedLogServerApp.java From distributedlog with Apache License 2.0 | 6 votes |
private void run() { try { logger.info("Running distributedlog server : args = {}", Arrays.toString(args)); BasicParser parser = new BasicParser(); CommandLine cmdline = parser.parse(options, args); runCmd(cmdline); } catch (ParseException pe) { logger.error("Argument error : {}", pe.getMessage()); printUsage(); Runtime.getRuntime().exit(-1); } catch (IllegalArgumentException iae) { logger.error("Argument error : {}", iae.getMessage()); printUsage(); Runtime.getRuntime().exit(-1); } catch (ConfigurationException ce) { logger.error("Configuration error : {}", ce.getMessage()); printUsage(); Runtime.getRuntime().exit(-1); } catch (IOException ie) { logger.error("Failed to start distributedlog server : ", ie); Runtime.getRuntime().exit(-1); } }
Example #10
Source File: EventHubConsoleConsumer.java From samza with Apache License 2.0 | 5 votes |
public static void main(String[] args) throws EventHubException, IOException, ExecutionException, InterruptedException { Options options = new Options(); options.addOption( CommandLineHelper.createOption(OPT_SHORT_EVENTHUB_NAME, OPT_LONG_EVENTHUB_NAME, OPT_ARG_EVENTHUB_NAME, true, OPT_DESC_EVENTHUB_NAME)); options.addOption(CommandLineHelper.createOption(OPT_SHORT_NAMESPACE, OPT_LONG_NAMESPACE, OPT_ARG_NAMESPACE, true, OPT_DESC_NAMESPACE)); options.addOption(CommandLineHelper.createOption(OPT_SHORT_KEY_NAME, OPT_LONG_KEY_NAME, OPT_ARG_KEY_NAME, true, OPT_DESC_KEY_NAME)); options.addOption( CommandLineHelper.createOption(OPT_SHORT_TOKEN, OPT_LONG_TOKEN, OPT_ARG_TOKEN, true, OPT_DESC_TOKEN)); CommandLineParser parser = new BasicParser(); CommandLine cmd; try { cmd = parser.parse(options, args); } catch (Exception e) { HelpFormatter formatter = new HelpFormatter(); formatter.printHelp(String.format("Error: %s%neh-console-consumer.sh", e.getMessage()), options); return; } String ehName = cmd.getOptionValue(OPT_SHORT_EVENTHUB_NAME); String namespace = cmd.getOptionValue(OPT_SHORT_NAMESPACE); String keyName = cmd.getOptionValue(OPT_SHORT_KEY_NAME); String token = cmd.getOptionValue(OPT_SHORT_TOKEN); consumeEvents(ehName, namespace, keyName, token); }
Example #11
Source File: AbstractCommandLineTool.java From kieker with Apache License 2.0 | 5 votes |
private CommandLine parseCommandLineArguments(final Options options, final String[] arguments) { final BasicParser parser = new BasicParser(); try { return parser.parse(options, arguments); } catch (final ParseException ex) { // Note that we append ex.getMessage() to the log message on purpose to improve the // logging output on the console. LOGGER.error("An error occurred while parsing the command line arguments: {}", ex.getMessage(), ex); LOGGER.info("Use the option `--{}` for usage information", CMD_OPT_NAME_HELP_LONG); return null; } }
Example #12
Source File: AbstractSamzaBench.java From samza with Apache License 2.0 | 5 votes |
public AbstractSamzaBench(String scriptName, String[] args) throws ParseException { options = new Options(); options.addOption( CommandLineHelper.createOption(OPT_SHORT_PROPERTIES_FILE, OPT_LONG_PROPERTIES_FILE, OPT_ARG_PROPERTIES_FILE, true, OPT_DESC_PROPERTIES_FILE)); options.addOption( CommandLineHelper.createOption(OPT_SHORT_NUM_EVENTS, OPT_LONG_NUM_EVENTS, OPT_ARG_NUM_EVENTS, true, OPT_DESC_NUM_EVENTS)); options.addOption( CommandLineHelper.createOption(OPT_SHORT_START_PARTITION, OPT_LONG_START_PARTITION, OPT_ARG_START_PARTITION, true, OPT_DESC_START_PARTITION)); options.addOption( CommandLineHelper.createOption(OPT_SHORT_END_PARTITION, OPT_LONG_END_PARTITION, OPT_ARG_END_PARTITION, true, OPT_DESC_END_PARTITION)); options.addOption( CommandLineHelper.createOption(OPT_SHORT_STREAM, OPT_LONG_STREAM, OPT_ARG_STREAM, true, OPT_DESC_STREAM)); addOptions(options); CommandLineParser parser = new BasicParser(); try { cmd = parser.parse(options, args); } catch (Exception e) { HelpFormatter formatter = new HelpFormatter(); formatter.printHelp(String.format("Error: %s.sh", scriptName), options); throw e; } }
Example #13
Source File: HiveMetaStoreBridge.java From incubator-atlas with Apache License 2.0 | 5 votes |
public static void main(String[] args) throws AtlasHookException { try { Configuration atlasConf = ApplicationProperties.get(); String[] atlasEndpoint = atlasConf.getStringArray(ATLAS_ENDPOINT); if (atlasEndpoint == null || atlasEndpoint.length == 0){ atlasEndpoint = new String[] { DEFAULT_DGI_URL }; } AtlasClient atlasClient; if (!AuthenticationUtil.isKerberosAuthenticationEnabled()) { String[] basicAuthUsernamePassword = AuthenticationUtil.getBasicAuthenticationInput(); atlasClient = new AtlasClient(atlasEndpoint, basicAuthUsernamePassword); } else { UserGroupInformation ugi = UserGroupInformation.getCurrentUser(); atlasClient = new AtlasClient(ugi, ugi.getShortUserName(), atlasEndpoint); } Options options = new Options(); CommandLineParser parser = new BasicParser(); CommandLine cmd = parser.parse( options, args); boolean failOnError = false; if (cmd.hasOption("failOnError")) { failOnError = true; } HiveMetaStoreBridge hiveMetaStoreBridge = new HiveMetaStoreBridge(atlasConf, new HiveConf(), atlasClient); hiveMetaStoreBridge.importHiveMetadata(failOnError); } catch(Exception e) { throw new AtlasHookException("HiveMetaStoreBridge.main() failed.", e); } }
Example #14
Source File: ThreatIntelLoader.java From opensoc-streaming with Apache License 2.0 | 5 votes |
private static CommandLine parseCommandLine(String[] args) { CommandLineParser parser = new BasicParser(); CommandLine cli = null; Options options = new Options(); options.addOption(OptionBuilder.withArgName("s"). withLongOpt("source"). isRequired(true). hasArg(true). withDescription("Source class to use"). create() ); options.addOption(OptionBuilder.withArgName("t"). withLongOpt("table"). isRequired(true). hasArg(true). withDescription("HBase table to load into"). create() ); options.addOption(OptionBuilder.withArgName("c"). withLongOpt("configFile"). hasArg(true). withDescription("Configuration file for source class"). create() ); try { cli = parser.parse(options, args); } catch(org.apache.commons.cli.ParseException e) { HelpFormatter formatter = new HelpFormatter(); formatter.printHelp("ThreatIntelLoader", options, true); System.exit(-1); } return cli; }
Example #15
Source File: App.java From ripme with MIT License | 5 votes |
/** * Tries to parse commandline arguments. * @param args Array of commandline arguments. * @return CommandLine object containing arguments. */ private static CommandLine getArgs(String[] args) { BasicParser parser = new BasicParser(); try { return parser.parse(getOptions(), args, false); } catch (ParseException e) { logger.error("[!] Error while parsing command-line arguments: " + Arrays.toString(args), e); System.exit(-1); return null; } }
Example #16
Source File: XmlDoclet.java From xml-doclet with Apache License 2.0 | 5 votes |
/** * Parse the given options. * * @param optionsArrayArray * The two dimensional array of options. * @return the parsed command line arguments. */ public static CommandLine parseCommandLine(String[][] optionsArrayArray) { try { List<String> argumentList = new ArrayList<String>(); for (String[] optionsArray : optionsArrayArray) { argumentList.addAll(Arrays.asList(optionsArray)); } CommandLineParser commandLineParser = new BasicParser() { @Override protected void processOption(final String arg, @SuppressWarnings("rawtypes") final ListIterator iter) throws ParseException { boolean hasOption = getOptions().hasOption(arg); if (hasOption) { super.processOption(arg, iter); } } }; CommandLine commandLine = commandLineParser.parse(options, argumentList.toArray(new String[] {})); return commandLine; } catch (ParseException e) { LoggingOutputStream loggingOutputStream = new LoggingOutputStream(log, LoggingLevelEnum.INFO); PrintWriter printWriter = new PrintWriter(loggingOutputStream); HelpFormatter helpFormatter = new HelpFormatter(); helpFormatter.printHelp(printWriter, 74, "javadoc -doclet " + XmlDoclet.class.getName() + " [options]", null, options, 1, 3, null, false); return null; } }
Example #17
Source File: CmdLineOpts.java From yb-sample-apps with Apache License 2.0 | 5 votes |
private static void parseHelpOverview(String[] args, Options options) throws Exception { Options helpOptions = new Options(); helpOptions.addOption("help", false, "Print help."); CommandLineParser helpParser = new BasicParser(); CommandLine helpCommandLine = null; try { helpCommandLine = helpParser.parse(helpOptions, args); } catch (ParseException e) { return; } if (helpCommandLine.hasOption("help")) { printUsage(options, "Usage:"); System.exit(0); } }
Example #18
Source File: GenerateSplitsFile.java From datawave with Apache License 2.0 | 5 votes |
@SuppressWarnings("static-access") public static void main(String[] args) { AccumuloCliOptions accumuloOptions = new AccumuloCliOptions(); Options options = accumuloOptions.getOptions(); options.addOption(OptionBuilder.isRequired(true).hasArg().withDescription("Config directory path").create("cd")); options.addOption(OptionBuilder.isRequired(false).hasArg().withDescription("Config file suffix").create("cs")); options.addOption(OptionBuilder.isRequired(false).hasArg().withDescription("Splits file path").create("sp")); Configuration conf = accumuloOptions.getConf(args, true); CommandLine cl; String configDirectory = null; String configSuffix; try { cl = new BasicParser().parse(options, args); if (cl.hasOption("cd")) { configDirectory = cl.getOptionValue("cd"); log.info("Set configDirectory to " + configDirectory); } else { HelpFormatter helpFormatter = new HelpFormatter(); helpFormatter.printHelp("Generate Splits", options); System.exit(1); } if (cl.hasOption("sp")) { conf.set(MetadataTableSplits.SPLITS_CACHE_DIR, cl.getOptionValue("sp")); log.info("Set " + MetadataTableSplits.SPLITS_CACHE_DIR + " to " + cl.getOptionValue("sp")); } if (cl.hasOption("cs")) { configSuffix = cl.getOptionValue("cs"); } else { configSuffix = "config.xml"; } log.info("Set configSuffix to " + configSuffix); ConfigurationFileHelper.setConfigurationFromFiles(conf, configDirectory, configSuffix); MetadataTableSplits splitsFile = new MetadataTableSplits(conf); splitsFile.update(); } catch (ParseException ex) { log.error(GenerateSplitsFile.class.getName(), ex); } }
Example #19
Source File: GenerateKafkaEvents.java From samza with Apache License 2.0 | 5 votes |
public static void main(String[] args) throws UnsupportedEncodingException, InterruptedException { randValueGenerator = new RandomValueGenerator(System.currentTimeMillis()); Options options = new Options(); options.addOption( CommandLineHelper.createOption(OPT_SHORT_TOPIC_NAME, OPT_LONG_TOPIC_NAME, OPT_ARG_TOPIC_NAME, true, OPT_DESC_TOPIC_NAME)); options.addOption( CommandLineHelper.createOption(OPT_SHORT_BROKER, OPT_LONG_BROKER, OPT_ARG_BROKER, false, OPT_DESC_BROKER)); options.addOption( CommandLineHelper.createOption(OPT_SHORT_NUM_EVENTS, OPT_LONG_NUM_EVENTS, OPT_ARG_NUM_EVENTS, false, OPT_DESC_NUM_EVENTS)); options.addOption( CommandLineHelper.createOption(OPT_SHORT_EVENT_TYPE, OPT_LONG_EVENT_TYPE, OPT_ARG_EVENT_TYPE, false, OPT_DESC_EVENT_TYPE)); CommandLineParser parser = new BasicParser(); CommandLine cmd; try { cmd = parser.parse(options, args); } catch (Exception e) { HelpFormatter formatter = new HelpFormatter(); formatter.printHelp(String.format("Error: %s%ngenerate-events.sh", e.getMessage()), options); return; } String topicName = cmd.getOptionValue(OPT_SHORT_TOPIC_NAME); String broker = cmd.getOptionValue(OPT_SHORT_BROKER, DEFAULT_BROKER); long numEvents = Long.parseLong(cmd.getOptionValue(OPT_SHORT_NUM_EVENTS, String.valueOf(Long.MAX_VALUE))); String eventType = cmd.getOptionValue(OPT_SHORT_EVENT_TYPE); generateEvents(broker, topicName, eventType, numEvents); }
Example #20
Source File: SamzaSqlConsole.java From samza with Apache License 2.0 | 5 votes |
public static void main(String[] args) { Options options = new Options(); options.addOption( CommandLineHelper.createOption(OPT_SHORT_SQL_FILE, OPT_LONG_SQL_FILE, OPT_ARG_SQL_FILE, false, OPT_DESC_SQL_FILE)); options.addOption( CommandLineHelper.createOption(OPT_SHORT_SQL_STMT, OPT_LONG_SQL_STMT, OPT_ARG_SQL_STMT, false, OPT_DESC_SQL_STMT)); CommandLineParser parser = new BasicParser(); CommandLine cmd; try { cmd = parser.parse(options, args); if (!cmd.hasOption(OPT_SHORT_SQL_STMT) && !cmd.hasOption(OPT_SHORT_SQL_FILE)) { throw new Exception( String.format("One of the (%s or %s) options needs to be set", OPT_SHORT_SQL_FILE, OPT_SHORT_SQL_STMT)); } } catch (Exception e) { HelpFormatter formatter = new HelpFormatter(); formatter.printHelp(String.format("Error: %s%nsamza-sql-console.sh", e.getMessage()), options); return; } List<String> sqlStmts; if (cmd.hasOption(OPT_SHORT_SQL_FILE)) { String sqlFile = cmd.getOptionValue(OPT_SHORT_SQL_FILE); sqlStmts = SqlFileParser.parseSqlFile(sqlFile); } else { String sql = cmd.getOptionValue(OPT_SHORT_SQL_STMT); System.out.println("Executing sql " + sql); sqlStmts = Collections.singletonList(sql); } executeSql(sqlStmts); }
Example #21
Source File: Generator.java From gce2retrofit with Apache License 2.0 | 5 votes |
private static CommandLine getCommandLine(Options options, String... args) { CommandLineParser parser = new BasicParser(); try { CommandLine cmd = parser.parse(options, args); return cmd; } catch (ParseException e) { System.out.println("Unexpected exception:" + e.getMessage()); } return null; }
Example #22
Source File: MergeConfigurationCLI.java From rya with Apache License 2.0 | 5 votes |
/** * * @param args * @throws MergeConfigurationException */ public MergeConfigurationCLI(final String[] args) throws MergeConfigurationException { checkNotNull(args); final Options cliOptions = getOptions(); final CommandLineParser parser = new BasicParser(); try { cmd = parser.parse(cliOptions, args); } catch (final ParseException pe) { throw new MergeConfigurationException("Improperly formatted options.", pe); } }
Example #23
Source File: JointParerTester.java From fnlp with GNU Lesser General Public License v3.0 | 5 votes |
public static void main(String[] args) throws Exception { Options opt = new Options(); opt.addOption("h", false, "Print help for this application"); BasicParser parser = new BasicParser(); CommandLine cl; try { cl = parser.parse(opt, args); } catch (Exception e) { System.err.println("Parameters format error"); return; } if (args.length == 0 || cl.hasOption('h')) { HelpFormatter f = new HelpFormatter(); f.printHelp( "Tagger:\n" + "ParserTester [option] model_file test_file result_file;\n", opt); return; } String[] args1 = cl.getArgs(); String modelfile = args1[0]; String testfile = args1[1]; String resultfile = args1[2]; JointParerTester tester = new JointParerTester(modelfile); tester.test(testfile, resultfile, "UTF-8"); }
Example #24
Source File: JointParerTrainer.java From fnlp with GNU Lesser General Public License v3.0 | 5 votes |
/** * 主文件 * * @param args * : 训练文件;模型文件;循环次数 * @throws Exception */ public static void main(String[] args) throws Exception { // args = new String[2]; // args[0] = "./tmp/malt.train"; // args[1] = "./tmp/Malt2Model.gz"; Options opt = new Options(); opt.addOption("h", false, "Print help for this application"); opt.addOption("iter", true, "iterative num, default 50"); opt.addOption("c", true, "parameters 1, default 1"); BasicParser parser = new BasicParser(); CommandLine cl; try { cl = parser.parse(opt, args); } catch (Exception e) { System.err.println("Parameters format error"); return; } if (args.length == 0 || cl.hasOption('h')) { HelpFormatter f = new HelpFormatter(); f.printHelp( "Tagger:\n" + "ParserTrainer [option] train_file model_file;\n", opt); return; } args = cl.getArgs(); String datafile = args[0]; String modelfile = args[1]; int maxite = Integer.parseInt(cl.getOptionValue("iter", "50")); float c = Float.parseFloat(cl.getOptionValue("c", "1")); JointParerTrainer trainer = new JointParerTrainer(modelfile); trainer.train(datafile, maxite, c); }
Example #25
Source File: ParserTrainer.java From fnlp with GNU Lesser General Public License v3.0 | 5 votes |
/** * 主文件 * * @param args * : 训练文件;模型文件;循环次数 * @throws Exception */ public static void main(String[] args) throws Exception { args = new String[2]; args[0] = "./tmp/CoNLL2009-ST-Chinese-train.txt"; args[1] = "./tmp/modelConll.gz"; Options opt = new Options(); opt.addOption("h", false, "Print help for this application"); opt.addOption("iter", true, "iterative num, default 50"); opt.addOption("c", true, "parameters 1, default 1"); BasicParser parser = new BasicParser(); CommandLine cl; try { cl = parser.parse(opt, args); } catch (Exception e) { System.err.println("Parameters format error"); return; } if (args.length == 0 || cl.hasOption('h')) { HelpFormatter f = new HelpFormatter(); f.printHelp( "Tagger:\n" + "ParserTrainer [option] train_file model_file;\n", opt); return; } args = cl.getArgs(); String datafile = args[0]; String modelfile = args[1]; int maxite = Integer.parseInt(cl.getOptionValue("iter", "50")); float c = Float.parseFloat(cl.getOptionValue("c", "1")); ParserTrainer trainer = new ParserTrainer(modelfile); trainer.train(datafile, maxite, c); }
Example #26
Source File: AsyncMagicCommandOptions.java From beakerx with Apache License 2.0 | 5 votes |
public OptionsResult parseOptions(String[] args) { CommandLineParser parser = new BasicParser(); List<AsyncMagicCommand.AsyncOptionCommand> commands = new ArrayList<>(); try { CommandLine cmd = parser.parse(asyncOptions.getOptions(), args); if (cmd.hasOption(AsyncOptions.THEN)) { commands.add(() -> BeakerXClientManager.get().runByTag(cmd.getOptionValue(AsyncOptions.THEN))); } } catch (ParseException e) { return new ErrorOptionsResult(e.getMessage()); } return new AsyncOptionsResult(commands); }
Example #27
Source File: Balancer.java From RDFS with Apache License 2.0 | 5 votes |
/** parse command line arguments */ private void parse(String[] args) { Options cliOpts = setupOptions(); BasicParser parser = new BasicParser(); CommandLine cl = null; try { try { cl = parser.parse(cliOpts, args); } catch (ParseException ex) { throw new IllegalArgumentException("args = " + Arrays.toString(args)); } int newThreshold = Integer.parseInt(cl.getOptionValue("threshold", "10")); int iterationTime = Integer.parseInt(cl.getOptionValue("iter_len", String.valueOf(maxIterationTime/(60 * 1000)))); maxConcurrentMoves = Integer.parseInt(cl.getOptionValue("node_par_moves", String.valueOf(MAX_NUM_CONCURRENT_MOVES))); moveThreads = Integer.parseInt(cl.getOptionValue("par_moves", String.valueOf(MOVER_THREAD_POOL_SIZE))); maxIterationTime = iterationTime * 60 * 1000L; threshold = checkThreshold(newThreshold); System.out.println("Running with threshold of " + threshold + " and iteration time of " + maxIterationTime + " milliseconds"); } catch (RuntimeException e) { printUsage(cliOpts); throw e; } }
Example #28
Source File: SimpleExample.java From hadoop-sstable with Apache License 2.0 | 5 votes |
@Override public int run(String[] args) throws Exception { long startTime = System.currentTimeMillis(); Options options = buildOptions(); CommandLineParser cliParser = new BasicParser(); CommandLine cli = cliParser.parse(options, args); if (cli.getArgs().length < 2) { printUsage(options); } Job job = getJobConf(cli); job.setJobName("Simple Example"); job.setJarByClass(SimpleExample.class); job.setOutputKeyClass(Text.class); job.setOutputValueClass(Text.class); job.setMapperClass(SimpleExampleMapper.class); job.setReducerClass(SimpleExampleReducer.class); job.setInputFormatClass(SSTableRowInputFormat.class); job.setOutputFormatClass(SequenceFileOutputFormat.class); SequenceFileOutputFormat.setCompressOutput(job, true); SequenceFileOutputFormat.setOutputCompressorClass(job, GzipCodec.class); SequenceFileOutputFormat.setOutputCompressionType(job, SequenceFile.CompressionType.BLOCK); String inputPaths = cli.getArgs()[0]; LOG.info("Setting initial input paths to {}", inputPaths); SSTableInputFormat.addInputPaths(job, inputPaths); final String outputPath = cli.getArgs()[1]; LOG.info("Setting initial output paths to {}", outputPath); FileOutputFormat.setOutputPath(job, new Path(outputPath)); boolean success = job.waitForCompletion(true); LOG.info("Total runtime: {}s", (System.currentTimeMillis() - startTime) / 1000); return success ? 0 : 1; }
Example #29
Source File: Main.java From cassandra-opstools with Apache License 2.0 | 5 votes |
public static void main(String[] args) throws IOException, InterruptedException, ParseException { final Options options = new Options(); options.addOption("f", "force", false, "Force auto balance"); options.addOption("d", "dryrun", false, "Dry run"); options.addOption("r", "noresolve", false, "Don't resolve host names"); options.addOption("h", "host", true, "Host to connect to (default: localhost)"); options.addOption("p", "port", true, "Port to connect to (default: 7199)"); CommandLineParser parser = new BasicParser(); CommandLine cmd = parser.parse(options, args); new Main().run(cmd); }
Example #30
Source File: ImageIngesterCLI.java From aws-dynamodb-mars-json-demo with Apache License 2.0 | 5 votes |
/** * Parses command line arguments to load the configuration file. * * @throws ExitException * Help option specified, syntax error, or error loading configuration file */ private void parse() throws ExitException { final BasicParser parser = new BasicParser(); CommandLine cl = null; try { cl = parser.parse(OPTIONS, args); } catch (final ParseException e) { help(); } if (cl.hasOption(OPTION_HELP_SHORT)) { help(); } if (cl.hasOption(OPTION_FILE_SHORT) && cl.hasOption(OPTION_CLASSPATH_SHORT)) { throw new ExitException("May not specify both of the command line options " + OPTION_FILE_SHORT + " and " + OPTION_CLASSPATH_SHORT); } if (cl.hasOption(OPTION_FILE_SHORT)) { final String filePath = cl.getOptionValue(OPTION_FILE_SHORT); config = loadConfigFromFilepath(filePath); } else { config = loadConfigFromClasspath(DEFAULT_CONFIG_FILE_NAME); } if (cl.hasOption(OPTION_CLASSPATH_SHORT)) { final String file = cl.getOptionValue(OPTION_CLASSPATH_SHORT); config = loadConfigFromClasspath(file); } }