private boolean parseCommandLine(String[] args) throws ParseException { Options options = new Options(); .addOption("h", "help", false, "display help text"); CommandLineParser parser = new GnuParser(); CommandLine commandLine = parser.parse(options, args); if (commandLine.hasOption('h')) { new HelpFormatter().printHelp("flume-ng avro-client", "", options, "The --dirname option assumes that a spooling directory exists " + "where immutable log files are dropped.", true); if (commandLine.hasOption("filename") && commandLine.hasOption("dirname")) { throw new ParseException( "--filename and --dirname options cannot be used simultaneously"); if (!commandLine.hasOption("port") && !commandLine.hasOption("host") && !commandLine.hasOption("rpcProps")) { throw new ParseException("Either --rpcProps or both --host and --port " + "must be specified."); if (!commandLine.hasOption("port")) { throw new ParseException( "You must specify a port to connect to with --port");
CommandLine cli = new GnuParser().parse(opts, args); if (cli.hasOption('h')) { HelpFormatter formatter = new HelpFormatter(); formatter.printHelp("fixacidkeyindex", opts); return; if (cli.hasOption("backup-path")) { backupPath = cli.getOptionValue("backup-path");
@Override protected void processOption(final String arg, final ListIterator iter) throws ParseException { boolean hasOption = getOptions().hasOption(arg); if (hasOption) { super.processOption(arg, iter); } else { remainingArgs.add(arg); remainingArgs.add(iter.next().toString()); } }
public boolean process(String []argv){ try { commandLine = new GnuParser().parse(options, argv); if(commandLine.hasOption("help")){ printCliUsage(); return false; } } catch (ParseException e) { System.err.println(e.getMessage()); printCliUsage(); return false; } return true; }
/** * 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; }
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); }
/** * Parse the user-specified options, get the generic options, and modify * configuration accordingly. * * @param opts Options to use for parsing args. * @param args User-specified arguments * @return true if the parse was successful */ private boolean parseGeneralOptions(Options opts, String[] args) throws IOException { opts = buildGeneralOptions(opts); CommandLineParser parser = new GnuParser(); boolean parsed = false; try { commandLine = parser.parse(opts, preProcessForWindows(args), true); processGeneralOptions(commandLine); parsed = true; } catch(ParseException e) { LOG.warn("options parsing failed: "+e.getMessage()); HelpFormatter formatter = new HelpFormatter(); formatter.printHelp("general options are: ", opts); } return parsed; }
public static void main(String[] args) throws Exception { UpgradeTool tool = new UpgradeTool(); tool.init(); CommandLineParser parser = new GnuParser(); CommandLine line ; String outputDir = "."; boolean execute = false; try { line = parser.parse(tool.cmdLineOptions, args); } catch (ParseException e) { System.err.println("UpgradeTool: Parsing failed. Reason: " + e.getLocalizedMessage()); printAndExit(tool); return; if (line.hasOption("help")) { HelpFormatter formatter = new HelpFormatter(); formatter.printHelp("upgrade-acid", tool.cmdLineOptions); return; if(line.hasOption("location")) { outputDir = line.getOptionValue("location"); if(line.hasOption("execute")) {
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");
Option option_S = OptionBuilder.withArgName("opt2").hasArg().withDescription("The S option").create("S"); Option option_test = new Option("test", "The test option"); Options options = new Options(); CommandLineParser parser = new GnuParser(); "arg3", "arg4", "--test", "-A", "opt3", }; options.addOption(option_A); options.addOption(option_r); options.addOption(option_S); options.addOption(option_test); commandLine = parser.parse(options, testArgs); if (commandLine.hasOption("A")) System.out.println(commandLine.getOptionValue("A")); if (commandLine.hasOption("r"))
/** * app entry point */ public static void main(String[] args) throws Exception { Options options = new Options(); try { options.addOption("h", HELP_OPTION, false, "show this page"); CommandLine cline = new GnuParser().parse(options, args); String[] argList = cline.getArgs(); if (cline.hasOption(HELP_OPTION)) { throw new ParseException("Printing help page:"); } else if(2 == argList.length) { new DirDeltaPatcher().patch(new File(argList[0]), new File(argList[1])); } else { throw new ParseException("Incorrect arguments received!"); } } catch (ParseException e) { HelpFormatter formatter = new HelpFormatter(); out.println(e.getMessage()); formatter.printHelp("java -jar delta-patch.jar dir patch.zip", options); } } }
Options options = new Options(); options.addOption(OptionBuilder .hasArg() .withArgName("abort-pct") .create('a')); options.addOption(OptionBuilder .hasArgs() .withArgName("column-names") Parser parser = new GnuParser(); CommandLine cmdline = null; try { cmdline = parser.parse(options, args); } catch (ParseException e) { System.err.println(e.getMessage()); usage(options); boolean pause = cmdline.hasOption('x'); String db = cmdline.getOptionValue('d'); String table = cmdline.getOptionValue('t'); String uri = cmdline.getOptionValue('m'); int txnsPerBatch = Integer.parseInt(cmdline.getOptionValue('n', "100"));
public ListModulesCommandArgsImpl(String[] args) throws CLParserException { options = new Options(); addState(); CommandLineParser parser = new GnuParser(); try { commandLine = parser.parse(options, args, true); } catch (ParseException e) { throw new CLParserException(e.getMessage(), e); } }
Options options = new Options(); options.addOption(new Option("confLocation", true, "Location of HCat/Hive Server's hive-site.")); options.addOption(new Option("delete", false, "Delete delegation token.")); options.addOption(new Option("list", false, "List delegation tokens.")); options.addOption(new Option("olderThan", true, "Filter for token's issue-date. (e.g. 3d, 1h or 4m).")); options.addOption(new Option("serverMode", true, "The service from which to read delegation tokens. Should be either of [METASTORE, HIVESERVER2].")); CommandLine commandLine = new GnuParser().parse(options, args, false // Stop on non-existent option. ); if (commandLine.hasOption("confLocation")) { confLocation = commandLine.getOptionValue("confLocation"); if (commandLine.hasOption("list")) { opType = OpType.LIST;
Options options = new Options(); options.addOption(OptionBuilder .hasArg() .withArgName("exec") options.addOption(OptionBuilder .hasArg() .withArgName("file") options.addOption(new Option("h", "help", false, "Print help information")); Parser parser = new GnuParser(); CommandLine cmdLine = null; setConfProperties(conf, cmdLine.getOptionProperties("D")); if (cmdLine.hasOption('h')) { printUsage(options, ss.out); sysExit(ss, 0); String execString = (String) cmdLine.getOptionValue('e');
Options mainOptions = new Options(); mainOptions.addOptionGroup(grp); Options execOptions = new Options(); execOptions.addOption("exec_opt1", false, " desc"); execOptions.addOption("exec_opt2", false, " desc"); GnuParser parser = new GnuParser(); CommandLine cmd = parser.parse(mainOptions,argv,true); argv = cmd.getArgs(); if(cmd.hasOption("exec")) cmd = parser.parse(execOptions,argv,false); assertTrue( cmd.hasOption("exec_opt1") ); assertTrue( cmd.hasOption("exec_opt2") ); else if(cmd.hasOption("rep")) cmd = parser.parse(repOptions,argv,false);
public static CommandLine parseAndHelp(String appName, Options options, String[] args) { options.addOption(HELP_OPTION); Parser parser = new GnuParser(); CommandLine line = null; try { line = parser.parse(options, args); } catch (MissingOptionException e) { new HelpFormatter().printHelp(appName, options, true); throw new IllegalArgumentException(); } catch (MissingArgumentException e) { new HelpFormatter().printHelp(appName, options, true); throw new IllegalArgumentException(); } catch (ParseException e) { System.err.println("Unexpected Exception: " + e); throw new IllegalArgumentException(); } if (line.hasOption("help")) { new HelpFormatter().printHelp(appName, options, true); throw new IllegalArgumentException(); } return line; }
@Override public JmxTransConfiguration parseOptions(@Nonnull String[] args) throws OptionsException, org.apache.commons.cli.ParseException { CommandLineParser parser = new GnuParser(); CommandLine cl = parser.parse(getOptions(), args); Option[] options = cl.getOptions(); configuration.setAdditionalJars(option.getValuesList()); } else if (option.getOpt().equals("h")) { HelpFormatter formatter = new HelpFormatter(); formatter.printHelp("java -jar jmxtrans-all.jar", getOptions()); configuration.setHelp(true);
Options opts = new Options(); 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, CommandLine cliParser = new GnuParser().parse(opts, args); JstormYarnUtils.checkAndSetMasterOptions(cliParser, jstormMasterContext, this.conf); } catch (Exception e) {