Options options = new Options(); options.addOption(Option.builder("a") .longOpt("anonymize") .desc("Strip out any possibly identifiable information") .build()); options.addOption(Option.builder("o") .longOpt("output-dir") .argName("<file>") boolean printHelp = false; try { cmd = parser.parse(options, args); } catch (ParseException e) { System.err.println("ERROR " + e.getMessage()); printHelp = true; if (printHelp || cmd.hasOption('h')) { new HelpFormatter().printHelp("CaptureLoad [options] [topologyName]*", options); return; int exitStatus = -1; String outputDir = DEFAULT_OUT_DIR; if (cmd.hasOption('o')) { outputDir = cmd.getOptionValue('o');
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"); if (!commandLine.hasOption("host")) { throw new ParseException( "You must specify a hostname to connect to with --host");
public VaultTool(String[] args) { initOptions(); parser = new PosixParser(); try { cmdLine = parser.parse(options, args, true); } catch (ParseException e) { System.out.println(SecurityLogger.ROOT_LOGGER.problemParsingCommandLineParameters()); e.printStackTrace(System.err); System.exit(2); } }
private String parseConfigLocation(String[] args) { Options options = new Options(); options.addOption(CLEANER_CONFIG); CommandLine cli; try { CommandLineParser parser = new DefaultParser(); cli = parser.parse(options, Arrays.copyOfRange(args, 1, args.length)); } catch (ParseException pe) { System.out.println("Command line parse exception: " + pe.getMessage()); printUsage(options); throw new RuntimeException(pe); } return cli.getOptionValue(CLEANER_CONFIG.getOpt()); }
Map<String, SlowExecutorPattern> topoSpecificImbalance = new HashMap<>(); try { cmd = parser.parse(options, args); if (cmd.hasOption("t")) { executeTime = Double.valueOf(cmd.getOptionValue("t")); if (cmd.hasOption("parallel")) { for (String stringParallel : cmd.getOptionValues("parallel")) { Matcher m = MULTI_PATTERN.matcher(stringParallel); if (!m.matches()) { throw new ParseException("--parallel " + stringParallel + " is not in the format MULTIPLIER(:TOPO:COMP)?"); Matcher m = MULTI_PATTERN.matcher(stringThroughput); if (!m.matches()) { throw new ParseException("--throughput " + stringThroughput + " is not in the format MULTIPLIER(:TOPO:COMP)?"); throw new ParseException(stringImbalance + " does not appear to match the expected pattern"); } else if (parts.length == 3) { topoSpecificImbalance.put(parts[1] + ":" + parts[2], SlowExecutorPattern.fromString(parts[0])); System.err.println("ERROR " + commandLineException.getMessage()); new HelpFormatter().printHelp("GenLoad [options] [captured_file]*", options); return;
public OptionsResult parseOptions(String[] args) { CommandLineParser parser = new BasicParser(); List<EnableSparkSupportCommand> commands = new ArrayList<>(); try { CommandLine cmd = parser.parse(sparkOptions.getOptions(), args); if (cmd.hasOption(VERSION)) { String version = cmd.getOptionValue(VERSION); commands.add((parent) -> actions.loadSpark(parent, version)); } } catch (ParseException e) { return new ErrorOptionsResult(e.getMessage()); } return new SparkOptionsResult(commands); }
@Override protected void parseCommandLine(CommandLine cmdline) throws ParseException { super.parseCommandLine(cmdline); if (!cmdline.hasOption("s")) { throw new ParseException("No stream name provided."); } streamName = cmdline.getOptionValue("s"); }
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")) {
public static void main(String[] args) { SwingUtil.installDefaults(); Options options = new Options(); options.addOption(OptionBuilder.withArgName("splash").hasArg() .withDescription( "use given image URL for splash (Supports classpath: pseudo URLs)") .create("splash")); options.addOption(OptionBuilder.withArgName("applicationClass").hasArg() .withDescription("use given class name as startup class.").isRequired() .create("applicationClass")); boolean splashed = false; try { CommandLine cmd = parser.parse(options, args); IStartup startup = instanciateStartup(cmd .getOptionValue("applicationClass")); if (cmd.hasOption("splash")) { SplashWindow.splash(UrlHelper.createURL(cmd.getOptionValue("splash"))); splashed = true; System.err.println(ex.getLocalizedMessage()); HelpFormatter formatter = new HelpFormatter(); formatter.printHelp(SwingLauncher.class.getSimpleName(), options); } catch (InstantiationException ex) { ex.printStackTrace(System.err);
/** * 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... argv) throws IOException { Options options = new Options(); options.addOption(o); options.addOption(o); cmd = parser.parse(options, argv); pe.printStackTrace(); final HelpFormatter usageFormatter = new HelpFormatter(); usageFormatter.printHelp(LatencySummarizer.class.getSimpleName().toLowerCase(), null, options, null, true); System.exit(-1); if( cmd.hasOption("h") ){ final HelpFormatter usageFormatter = new HelpFormatter(); usageFormatter.printHelp(LatencySummarizer.class.getSimpleName().toLowerCase(), null, options, null, true); System.exit(0); updateStats(statsMap, doc); statsMap.printSummary(cmd.hasOption('m'));
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); } }
@Override public T buildObject(String[] args, int offset, boolean printUsage, String usage) throws IOException { Options options = new Options(); options.addOption(HELP); options.addOption(USE_LOG); for (Option opt : getOptions().getOptions()) { options.addOption(opt); try { CommandLineParser parser = new DefaultParser(); cli = parser.parse(options, Arrays.copyOfRange(args, offset, args.length)); } catch (ParseException pe) { if (printUsage) { System.out.println("Command line parse exception: " + pe.getMessage()); printUsage(usage, options); if (cli.hasOption(HELP.getOpt())) { if (printUsage) { printUsage(usage, options); return buildObject(cli); } catch (Throwable t) { if (cli.hasOption(USE_LOG.getOpt())) { log.error("Failed to instantiate " + this.klazz.getName(), t); } else {
/** * 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; }
options.addOption("u", URL_OPTION, true, "NiFI URL to connect to (default: " + URL_OPTION_DEFAULT + ")"); options.addOption("d", DIRECTION_OPTION, true, "Direction (valid directions: " + Arrays.stream(TransferDirection.values()).map(Object::toString).collect(Collectors.joining(", ")) + ") (default: " + DIRECTION_OPTION_DEFAULT + ")"); options.addOption("n", PORT_NAME_OPTION, true, "Port name"); options.addOption("i", PORT_IDENTIFIER_OPTION, true, "Port id"); options.addOption(null, TIMEOUT_OPTION, true, "Timeout"); CommandLineParser parser = new DefaultParser(); CommandLine commandLine; commandLine = parser.parse(options, args); if (commandLine.hasOption(HELP_OPTION)) { printUsage(null, options); System.exit(1); builder.url(commandLine.getOptionValue(URL_OPTION, URL_OPTION_DEFAULT)); if (commandLine.hasOption(PORT_NAME_OPTION)) { builder.portName(commandLine.getOptionValue(PORT_NAME_OPTION)); builder.keystorePass(commandLine.getOptionValue(KEY_STORE_PASSWORD_OPTION)); } else { throw new ParseException("Must specify keystore password"); builder.truststorePass(commandLine.getOptionValue(TRUST_STORE_PASSWORD_OPTION)); } else { throw new ParseException("Must specify truststore password");
public static CliOptions parseGatewayModeClient(String[] args) { try { DefaultParser parser = new DefaultParser(); CommandLine line = parser.parse(GATEWAY_MODE_CLIENT_OPTIONS, args, true); return new CliOptions( line.hasOption(CliOptionsParser.OPTION_HELP.getOpt()), checkSessionId(line), checkUrl(line, CliOptionsParser.OPTION_ENVIRONMENT), null, checkUrls(line, CliOptionsParser.OPTION_JAR), checkUrls(line, CliOptionsParser.OPTION_LIBRARY), line.getOptionValue(CliOptionsParser.OPTION_UPDATE.getOpt()) ); } catch (ParseException e) { throw new SqlClientException(e.getMessage()); } }
public OptionsResult parseOptions(String[] args) { CommandLineParser parser = new BasicParser(); List<SparkMagicCommand.SparkOptionCommand> commands = new ArrayList<>(); try { CommandLine cmd = parser.parse(sparkOptions.getOptions(), args); if (cmd.hasOption(START)) { commands.add((sparkUI, parent) -> sparkMagicCommand.connectToSparkSession(sparkUI, parent)); } } catch (ParseException e) { return new ErrorOptionsResult(e.getMessage()); } return new SparkOptionsResult(commands); }
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; }
commandLine = parser.parse(allOptions, args, false); } catch (ParseException ex) { System.err.println(ex.getMessage()); usage(); return; if (commandLine.hasOption("-v") || commandLine.hasOption("--verbose")) { verbosity = Verbosity.VERBOSE; } else if (commandLine.hasOption("-q") || commandLine.hasOption("--quiet")) { verbosity = Verbosity.QUIET;