/** * Main method. * * @param args * @throws IOException * @throws ParseException */ public static void main(String[] args) throws Exception { java.util.logging.Logger l = java.util.logging.Logger.getLogger("org.glassfish.grizzly.http.server.HttpHandler"); l.setLevel(java.util.logging.Level.FINE); l.setUseParentHandlers(false); java.util.logging.ConsoleHandler ch = new java.util.logging.ConsoleHandler(); ch.setLevel(java.util.logging.Level.ALL); l.addHandler(ch); CommandLineParser parser = new GnuParser(); Options options = new Options(); options.addOption("h", "host", true, "Server hostname."); options.addOption("p", "port", true, "TCP port to listen."); options.addOption("s", "storage_path", true, "Storage path."); options.addOption("w", "wat_gcube_token", true, "WAT gcube authentication token"); CommandLine line = parser.parse(options, args); String serverUri = String.format("http://%s:%d/smaph", line.getOptionValue("host", "localhost"), Integer.parseInt(line.getOptionValue("port", "8080"))); Path storage = Paths.get(line.getOptionValue("storage_path")); startServer(serverUri, storage, line.getOptionValue("wat_gcube_token")); }
public MyOptions(String[] args) { seed = System.nanoTime(); try { Options opts = buildOptions(); CommandLineParser parser = new GnuParser(); CommandLine line = parser.parse(opts, args, true); processOptions(line, opts); validateOptions(); } catch (ParseException e) { System.out.println(e.getMessage()); System.out.println("Try \"--help\" option for details."); setStopProceed(); } }
private void handleNetezzaImportExtraArgs(ImportJobContext context) throws ParseException { SqoopOptions opts = context.getOptions(); Configuration conf = opts.getConf(); String[] extraArgs = opts.getExtraArgs(); conf.setBoolean(NETEZZA_DATASLICE_ALIGNED_ACCESS_OPT, false); if (extraArgs != null && extraArgs.length > 0 && ConfigurationHelper.getConfNumMaps(conf) > 1) { RelatedOptions netezzaOpts = getNetezzaExtraOpts(); CommandLine cmdLine = new GnuParser().parse(netezzaOpts, extraArgs, true); if (cmdLine.hasOption(NETEZZA_DATASLICE_ALIGNED_ACCESS_LONG_ARG)) { conf.setBoolean(NETEZZA_DATASLICE_ALIGNED_ACCESS_OPT, true); context.setInputFormat(NetezzaDataDrivenDBInputFormat.class); } } }
public static void main(String[] args) throws Exception { CommandLine cmd = new GnuParser().parse(opts, args); if (cmd.hasOption("help")) { new HelpFormatter().printHelp("Usage: hbgen [OPTIONS]", opts); return; } // defaults Class<?> specClass = HamletSpec.class; Class<?> implClass = HamletImpl.class; String outputClass = "HamletTmp"; String outputPackage = implClass.getPackage().getName(); if (cmd.hasOption("spec-class")) { specClass = Class.forName(cmd.getOptionValue("spec-class")); } if (cmd.hasOption("impl-class")) { implClass = Class.forName(cmd.getOptionValue("impl-class")); } if (cmd.hasOption("output-class")) { outputClass = cmd.getOptionValue("output-class"); } if (cmd.hasOption("output-package")) { outputPackage = cmd.getOptionValue("output-package"); } new HamletGen().generate(specClass, implClass, outputClass, outputPackage); }
public static void main(String[] argv) throws Exception { CommandLine cliParser = new GnuParser().parse(opts, argv); if (cliParser.hasOption("put")) { String path = cliParser.getOptionValue("put"); if (path != null && path.length() > 0) { if (cliParser.hasOption(ENTITY_DATA_TYPE)) { putTimelineDataInJSONFile(path, ENTITY_DATA_TYPE); return; } else if (cliParser.hasOption(DOMAIN_DATA_TYPE)) { putTimelineDataInJSONFile(path, DOMAIN_DATA_TYPE); return; } } } printUsage(); }
private void utility(String... args) throws Exception { final Options options = new Options(); options.addOption("sp", true, "sourcePath"); options.addOption("tp", true, "targetPath"); options.addOption("threshold", true, "thresholdInBytes"); final CommandLineParser commandLineParser = new GnuParser(); final CommandLine commandLine = commandLineParser.parse(options, args); log.info("source Path " + commandLine.getOptionValue("sp")); log.info("Target Path " + commandLine.getOptionValue("tp")); log.info("Threshold " + commandLine.getOptionValue("threshold")); final Map<String, String> optionsMap = new HashMap<String, String>(); optionsMap.put("sourcePath", commandLine.getOptionValue("sp")); optionsMap.put("targetPath", commandLine.getOptionValue("tp")); optionsMap.put("thresholdInBytes", commandLine.getOptionValue("threshold")); final CompactionManager compactionManager = CompactionManagerFactory.create(optionsMap); final CompactionResponse compactionResponse = compactionManager.compact(); log.info("Compaction Response Success {}", compactionResponse.isSuccessful()); log.info("Compaction Response FileType {}", compactionResponse.getTargetFileType()); log.info("Compaction Response Target Path {}", compactionResponse.getTargetPath()); }
public static void main(String[] args) throws Exception { CommandLineParser parser = new GnuParser(); Options options = createWebAppOptions(); CommandLine commandLine = null; HelpFormatter formatter = new HelpFormatter(); try { commandLine = parser.parse(options, args); } catch (Exception e) { formatter.printHelp("NutchUiServer", options, true); StringUtils.stringifyException(e); } if (commandLine.hasOption("help")) { formatter.printHelp("NutchUiServer", options, true); return; } if (commandLine.hasOption(CMD_PORT)) { port = Integer.parseInt(commandLine.getOptionValue(CMD_PORT)); } startServer(); }
public static void main(String args[]) throws IOException, ParseException { Options options = new Options(); options.addOption("i","insdist",false,"print insert size distribution"); options.addOption("s","stats",false,"print mapping stats"); options.addOption("l","readlen",false,"read length"); options.addOption("c","readcount",false,"read count"); options.addOption("bt2",false,"input is from bowtie2"); options.addOption("bt1",false,"input is from bowtie1 (tested for --best --strata -m 1)"); CommandLineParser parser = new GnuParser(); CommandLine cl = parser.parse( options, args, false ); SAMStats s = new SAMStats(cl.hasOption("bt1"), cl.hasOption("bt2")); if(cl.hasOption("insdist")) s.printInsertDistrib(); if(cl.hasOption("stats")) s.printStats(); if(cl.hasOption("readlen")) s.printReadLength(); if(cl.hasOption("readcount")) s.printReadCount(); }
@Override public boolean init(String[] args) throws ParseException { CommandLine cliParser = new GnuParser().parse(opts, args); if (!cliParser.hasOption("jar")) { throw new IllegalArgumentException("No jar file specified for application master"); } appMasterJar = cliParser.getOptionValue("jar"); if (!cliParser.hasOption("configFile")) { throw new IllegalArgumentException("No config file specified"); } configFile = cliParser.getOptionValue("configFile"); String configFileContent = readConfigFileContent(configFile); yacopConfig = parseConfigFile(configFileContent); if (yacopConfig == null) { return false; } return true; }
@Override public boolean init(String[] args) throws ParseException { CommandLine cliParser = new GnuParser().parse(opts, args); if (!cliParser.hasOption("applicationId")) { throw new IllegalArgumentException("no application id specified"); } applicationId = cliParser.getOptionValue("applicationId"); if (!cliParser.hasOption("containerHost")) { throw new IllegalArgumentException("no container host specified"); } containerHost = cliParser.getOptionValue("containerHost"); if (!cliParser.hasOption("containerId")) { throw new IllegalArgumentException("no container id specified"); } containerId = cliParser.getOptionValue("containerId"); if (!cliParser.hasOption("containerPort")) { throw new IllegalArgumentException("no container port specified"); } containerPort = cliParser.getOptionValue("containerPort"); return true; }
@Override public int run(String[] args) throws Exception { Options options = new Options(); options.addOption("c", "concurrent", false, "run concurrently with generation"); GnuParser parser = new GnuParser(); CommandLine cmd = null; try { cmd = parser.parse(options, args); if (cmd.getArgs().length != 2) { throw new ParseException("Did not see expected # of arguments, saw " + cmd.getArgs().length); } } catch (ParseException e) { LOG.error("Failed to parse command line {}", e.getMessage()); HelpFormatter formatter = new HelpFormatter(); formatter.printHelp(getClass().getSimpleName() + " <output dir> <num reducers>", options); System.exit(-1); } String outputDir = cmd.getArgs()[0]; int numReducers = Integer.parseInt(cmd.getArgs()[1]); return run(outputDir, numReducers, cmd.hasOption("c")); }
@Override public int run(String[] args) throws Exception { Options options = new Options(); options.addOption("c", "concurrent", false, "update secondary table with information that allows verification to run concurrently"); GnuParser parser = new GnuParser(); CommandLine cmd = null; try { cmd = parser.parse(options, args); if (cmd.getArgs().length != 2) { throw new ParseException("Did not see expected # of arguments, saw " + cmd.getArgs().length); } } catch (ParseException e) { LOG.error("Failed to parse command line {}", e.getMessage()); HelpFormatter formatter = new HelpFormatter(); formatter.printHelp(getClass().getSimpleName() + " <num mappers> <num nodes per map>", options); System.exit(-1); } int numMappers = Integer.parseInt(cmd.getArgs()[0]); long numNodes = Long.parseLong(cmd.getArgs()[1]); return run(numMappers, numNodes, cmd.hasOption("c")); }
/** * Non-static version of main so that we can define anonymous local classes to override or extend * the above. * @param args a String array of input options */ public void runMain(String[] args) { Options o = this.getCliOptions(); try { new GnuParser().parse(o, args); } catch (ParseException pe) { // The message from pe is ugly, so we omit it. System.err.println("Error parsing command line"); new HelpFormatter().printHelp(this.getClassName(), o); System.exit(1); } try { float ratio = 0.8f; if (this.oratio.getValue() != null) { ratio = Float.parseFloat(this.oratio.getValue()); } this.runSubsampler(this.otest.getValues(), 12, 20, ratio); } catch (Exception e) { e.printStackTrace(); System.exit(1); } }
/** * Parses the arguments. The valid arguments are: * --help or -h : prints out help message for this main class. * --json or -j : the JSON file. * @param args the arguments passed in as options. */ @Override public void parseArgs(String [] args) throws AdeUsageException{ Options options = new Options(); buildOptions(options); CommandLineParser parser = new GnuParser(); CommandLine line = parseLine(parser,options,args); if (line.hasOption('h')) { new HelpFormatter().printHelp(this.getClass().getSimpleName(), options); System.exit(0); } if (line.hasOption('j')){ String jsonFile = line.getOptionValue("j"); inputJSONFile = new File(jsonFile); validateFile(inputJSONFile); } else{ new HelpFormatter().printHelp(this.getClass().getSimpleName(), options); throw new AdeUsageException("Must specify a JSON file path using the -j option."); } }
protected CommandLine parseArgs(CliContext context, String[] stringArgs) { GnuParser parser = new GnuParser(); CommandLine args; Options options = getOptions(); Io io = context.getIo(); try { args = parser.parse(options, stringArgs); } catch (ParseException e) { logger.warn("Invalid command line arguments.", e); io.errorln("Invalid command line arguments."); io.errorln(e.getMessage()); return null; } if (args.hasOption("h")) { printHelp(context); return null; } return args; }
/** * Parse the user-specified options, get the generic options, and modify * configuration accordingly * @param conf Configuration to be modified * @param args User-specified arguments * @return Command-specific arguments */ private String[] parseGeneralOptions(Options opts, Configuration conf, String[] args) { opts = buildGeneralOptions(opts); CommandLineParser parser = new GnuParser(); try { commandLine = parser.parse(opts, args, true); processGeneralOptions(conf, commandLine); return commandLine.getArgs(); } catch(ParseException e) { LOG.warn("options parsing failed: "+e.getMessage()); HelpFormatter formatter = new HelpFormatter(); formatter.printHelp("general options are: ", opts); } return args; }
/** * Starts this command line utility with the command line arguments * provided by the {@code main} method. The command line arguments are * parsed into a {@link org.apache.commons.cli.CommandLine} object and the {@code run} method is * invoked. * <p> * At the start of this method, a specialized uncaught exception handler * is registered with the calling thread. This exception handler is * responsible for formatting and displaying any errors on the command * line. Note that this exception handler is not removed at the end of * this method; its removal is not necessary when this utility is invoked * on the command line. * * @param args the command line arguments */ public void start(String[] args) throws Exception { Thread.currentThread().setUncaughtExceptionHandler( new CommandLineUncaughtExceptionHandler()); // trim last argument because of an error with Windows newline // characters if (args.length > 0) { args[args.length - 1] = args[args.length - 1].trim(); } Options options = getOptions(); CommandLineParser commandLineParser = new GnuParser(); CommandLine commandLine = commandLineParser.parse(options, args); if (commandLine.hasOption("help")) { showHelp(); } else { run(commandLine); } }
public boolean parse(String[] args) { // in an older version, we parsed <options> <appsOrFiles> <appArgs>... String[] cojacArgs = args; try { CommandLine commandLine = new GnuParser().parse(options, cojacArgs); for (Arg arg : Arg.values()) { if (commandLine.hasOption(arg.shortOpt())) { values.get(arg).setSpecified(); values.get(arg).setValue(commandLine.getOptionValue(arg.shortOpt())); verifyOptionFormat(arg); } } } catch (ParseException e) { System.out.println("Invalid command line. Reason: " + e.getMessage()); return false; } setDefaults(); return true; }
@Override public int run(String[] args) throws Exception { Options opts = new Options(); opts.addOption(STATUS_CMD, true, "Prints the status report of the node."); opts.addOption(LIST_CMD, false, "Lists all the nodes in the RUNNING state."); CommandLine cliParser = new GnuParser().parse(opts, args); int exitCode = -1; if (cliParser.hasOption("status")) { if (args.length != 2) { printUsage(opts); return exitCode; } printNodeStatus(cliParser.getOptionValue("status")); } else if (cliParser.hasOption("list")) { listClusterNodes(); } else { syserr.println("Invalid Command Usage : "); printUsage(opts); } return 0; }