private static CommandLine parseArgs(String[] args) throws ParseException { Options options = new Options(); options.addOption(OptionBuilder.withLongOpt("file") .withDescription("sequence file to read") .hasArg() .withArgName("<sequence_file_name>") .withType(String.class) .create("f")); options.addOption("o", "print_offsets_only", false, "whether to print only offsets " + "ignoring the message payload"); CommandLineParser parser = new GnuParser(); return parser.parse(options, args); }
private CommandLine parseOpts(String cmdName, Options opts, String[] argv) { try { // Strip off the first arg, since that's just the command name argv = Arrays.copyOfRange(argv, 1, argv.length); return new GnuParser().parse(opts, argv); } catch (ParseException pe) { errOut.println(cmdName.substring(1) + ": incorrect arguments"); printUsage(errOut, cmdName); return null; } }
/** * Parse the command line arguments */ public boolean parse(String[] args) { try { commandLine = new GnuParser().parse(options, args); execString = commandLine.getOptionValue('e'); fileName = commandLine.getOptionValue('f'); main = commandLine.getOptionValue("main"); Properties p = commandLine.getOptionProperties("hiveconf"); for(String key : p.stringPropertyNames()) { vars.put(key, p.getProperty(key)); } p = commandLine.getOptionProperties("hivevar"); for(String key : p.stringPropertyNames()) { vars.put(key, p.getProperty(key)); } p = commandLine.getOptionProperties("define"); for(String key : p.stringPropertyNames()) { vars.put(key, p.getProperty(key)); } } catch (ParseException e) { System.err.println(e.getMessage()); return false; } return true; }
public static void main(String[] args) throws Exception { if (args == null || args.length < 1) { System.out.println("Invalid parameter"); usage(); return; CommandLineParser parser = new GnuParser(); Options r = buildGeneralOptions(new Options()); CommandLine commandLine = parser.parse(r, str2, true); if (commandLine.hasOption("n")) { workerNum = Integer.valueOf(commandLine.getOptionValue("n")); if (commandLine.hasOption("p")) { component = commandLine.getOptionValue("p"); if (commandLine.hasOption("w")) { String w = commandLine.getOptionValue("w"); if (!StringUtils.isBlank(w)) { workers = Lists.newArrayList();
/** * Parse command line options */ public boolean init(String[] args) throws ParseException { CommandLine cliParser = new GnuParser().parse(jstormClientContext.opts, args); if (cliParser.hasOption(JOYConstants.HELP)) { printUsage(); return false; } jstormClientContext.appName = cliParser.getOptionValue(JOYConstants.APP_NAME_KEY, JOYConstants.CLIIENT_CLASS); jstormClientContext.amPriority = Integer.parseInt(cliParser.getOptionValue(JOYConstants.PRIORITY, JOYConstants.DEFAULT_PRIORITY)); jstormClientContext.amQueue = cliParser.getOptionValue(JOYConstants.QUEUE, JOYConstants.QUEUE_NAME); jstormClientContext.amMemory = Integer.parseInt(cliParser.getOptionValue(JOYConstants.MASTER_MEMORY, JOYConstants.DEFAULT_MASTER_MEMORY)); jstormClientContext.amVCores = Integer.parseInt(cliParser.getOptionValue(JOYConstants.MASTER_VCORES, JOYConstants.DEFAULT_MASTER_VCORES)); jstormClientContext.appMasterJar = cliParser.getOptionValue(JOYConstants.JAR); jstormClientContext.libJars = cliParser.getOptionValue(JOYConstants.LIB_JAR); jstormClientContext.homeDir = cliParser.getOptionValue(JOYConstants.HOME_DIR); jstormClientContext.confFile = cliParser.getOptionValue(JOYConstants.CONF_FILE); jstormClientContext.rmHost = cliParser.getOptionValue(JOYConstants.RM_ADDRESS, JOYConstants.EMPTY); jstormClientContext.nameNodeHost = cliParser.getOptionValue(JOYConstants.NN_ADDRESS, JOYConstants.EMPTY); jstormClientContext.deployPath = cliParser.getOptionValue(JOYConstants.DEPLOY_PATH, JOYConstants.EMPTY); jstormClientContext.hadoopConfDir = cliParser.getOptionValue(JOYConstants.HADOOP_CONF_DIR, JOYConstants.EMPTY); jstormClientContext.instanceName = cliParser.getOptionValue(JOYConstants.INSTANCE_NAME, JOYConstants.EMPTY); JstormYarnUtils.checkAndSetOptions(cliParser, jstormClientContext); return true; }
private void parseCommandLine(String[] args) throws ParseException { CommandLine cl = new GnuParser().parse(OPTIONS, args); listFSRoot = cl.hasOption(LIST_FS_ROOT.getOpt()); jdoqlQuery = cl.getOptionValue(EXECUTE_JDOQL.getOpt()); updateLocationParams = cl.getOptionValues(UPDATE_LOCATION.getOpt()); dryRun = cl.hasOption(DRY_RUN.getOpt()); serdePropKey = cl.getOptionValue(SERDE_PROP_KEY.getOpt()); tablePropKey = cl.getOptionValue(TABLE_PROP_KEY.getOpt()); help = cl.hasOption(HELP.getOpt()); int commandCount = (isListFSRoot() ? 1 : 0) + (isExecuteJDOQL() ? 1 : 0) + (isUpdateLocation() ? 1 : 0); if (commandCount != 1) { throw new IllegalArgumentException("exectly one of -listFSRoot, -executeJDOQL, -updateLocation must be set"); } if (updateLocationParams != null && updateLocationParams.length != 2) { throw new IllegalArgumentException("HiveMetaTool:updateLocation takes in 2 arguments but was passed " + updateLocationParams.length + " arguments"); } if ((dryRun || serdePropKey != null || tablePropKey != null) && !isUpdateLocation()) { throw new IllegalArgumentException("-dryRun, -serdePropKey, -tablePropKey may be used only for the " + "-updateLocation command"); } }
opts.addOption(JOYConstants.APP_ATTEMPT_ID, true, "App Attempt ID. Not to be used unless for testing purposes"); opts.addOption(JOYConstants.SHELL_SCRIPT, true, "Environment for shell script. Specified as env_key=env_val pairs"); opts.addOption(JOYConstants.CONTAINER_MEMORY, true, "Amount of memory in MB to be requested to run the shell command"); opts.addOption(JOYConstants.CONTAINER_VCORES, true, CommandLine cliParser = new GnuParser().parse(opts, args); JstormYarnUtils.checkAndSetMasterOptions(cliParser, jstormMasterContext, this.conf); } catch (Exception e) {
private CommandLine parseCli(String[] args) throws IllegalArgumentException, IOException { this.initializeOptions(); CommandLineParser parser = new GnuParser(); CommandLine line = null; try { line = parser.parse(options, args); } catch (ParseException e) { printHelp(""); } this.setInputPath(line.getOptionValue(INPUT_PATH)); this.setOutputPath(line.getOptionValue(OUTPUT_PATH)); this.setOutputBlockSize(this.outputPath); return line; }
execOptions.addOption("exec_opt1", false, " desc"); execOptions.addOption("exec_opt2", false, " desc"); repOptions.addOption("repopto", false, "desc"); repOptions.addOption("repoptt", false, "desc"); GnuParser parser = new GnuParser(); if(cmd.hasOption("exec")) assertTrue( cmd.hasOption("exec_opt1") ); assertTrue( cmd.hasOption("exec_opt2") ); else if(cmd.hasOption("rep"))
public static void main(String[] args) throws Exception { RunOptions runOptions; try { Options opts = createOptions(); CommandLine cli = new GnuParser().parse(opts, args); if (cli.hasOption('h')) { HelpFormatter formatter = new HelpFormatter(); formatter.printHelp(HiveStrictManagedMigration.class.getName(), opts); return; } runOptions = createRunOptions(cli); } catch (Exception err) { throw new Exception("Error processing options", err); } int rc = 0; HiveStrictManagedMigration migration = null; try { migration = new HiveStrictManagedMigration(runOptions); migration.run(); } catch (Exception err) { LOG.error("Failed with error", err); rc = -1; } finally { if (migration != null) { migration.cleanup(); } } // TODO: Something is preventing the process from terminating after main(), adding exit() as hacky solution. System.exit(rc); }
public static CommandLine processCommandLineArgs(String[] cliArgs, Options cliOptions) throws Exception { CommandLineParser cliParser = new GnuParser(); try { return cliParser.parse(cliOptions, cliArgs); } catch (ParseException pe) { System.err.println("CommandLineClient: failed to parse command-line options: " + pe.toString()); printUsage(cliOptions); System.exit(1); } return null; } }
/** * Parse the arguments. * @param args */ public void parse(String[] args) { try { commandLine = new GnuParser().parse(OPTIONS, args); if (commandLine.hasOption('h')) { printUsage(); System.exit(1); } if (commandLine.hasOption('v')) { verbose = true; } } catch (ParseException e) { System.err.println(e.getMessage()); printUsage(); System.exit(1); } }
/** * Parses the command line arguments. * * @param argv the command line arguments * @return true, if successful */ public boolean parse(String[] argv) { try { commandLine = new GnuParser().parse(options, argv); } catch (ParseException ex) { System.err.println(ex.getMessage()); //NOSONAR printUsage(); return false; } return true; }
public static void main(String[] args) { if (args == null || args.length < 3) { System.out.println("Invalid parameter"); usage(); return; } String topologyName = args[0]; try { String[] str2 = Arrays.copyOfRange(args, 1, args.length); CommandLineParser parser = new GnuParser(); Options r = buildGeneralOptions(new Options()); CommandLine commandLine = parser.parse(r, str2, true); String pathConf = null; String pathJar = null; if (commandLine.hasOption("conf")) { pathConf = (commandLine.getOptionValues("conf"))[0]; } if (commandLine.hasOption("jar")) { pathJar = (commandLine.getOptionValues("jar"))[0]; } if (pathConf != null || pathJar != null) updateTopology(topologyName, pathJar, pathConf); } catch (Exception e) { e.printStackTrace(); } } }
public LlapOptions processOptions(String argv[]) throws ParseException, IOException { commandLine = new GnuParser().parse(options, argv); if (commandLine.hasOption('H') || false == commandLine.hasOption("instances")) { int instances = Integer.parseInt(commandLine.getOptionValue(OPTION_INSTANCES)); String directory = commandLine.getOptionValue(OPTION_DIRECTORY); String jars = commandLine.getOptionValue(OPTION_AUXJARS); String name = commandLine.getOptionValue(OPTION_NAME, null); final boolean isHiveAux = Boolean.parseBoolean( commandLine.getOptionValue(OPTION_AUXHIVE, "true")); final boolean doStart = commandLine.hasOption(OPTION_START); final String output = commandLine.getOptionValue(OPTION_OUTPUT_DIR, null);
private static CommandLine parseArgs(String[] args) throws ParseException { Options options = new Options(); options.addOption(OptionBuilder.withLongOpt("command") .withDescription("command name. One of \"delete_committed_offsets\"") .hasArg() .withArgName("<command>") .withType(String.class) .create("c")); options.addOption(OptionBuilder.withLongOpt("topic") .withDescription("topic whose offset should be read") .hasArg() .withArgName("<topic>") .withType(String.class) .create("t")); options.addOption(OptionBuilder.withLongOpt("partition") .withDescription("kafka partition whose offset should be read") .hasArg() .withArgName("<partition>") .withType(Number.class) .create("p")); CommandLineParser parser = new GnuParser(); return parser.parse(options, args); }