private static Params parseCommand(String[] args) { try { Options options = new Options(); options.addOption(new Option("l", "language", true, "language")); options.addOption(new Option("t", "thread", true, "thread")); options.addOption(new Option("f", "file", true, "script file")); options.addOption(new Option("i", "input", true, "input file")); options.addOption(new Option("s", "sleep", true, "sleep time")); options.addOption(new Option("g", "logger", true, "sleep time")); CommandLineParser commandLineParser = new PosixParser(); CommandLine commandLine = commandLineParser.parse(options, args); return readOptions(commandLine); } catch (Exception e) { e.printStackTrace(); exit(); return null; } }
public static void setFromCommandLineArgs(Options options, String[] args) { CommandLineParser parser = new PosixParser(); try { CommandLine cl = parser.parse(options, args); THE_INSTANCE.windowLength = new Duration(Integer.parseInt( cl.getOptionValue(LogAnalyzerAppMain.WINDOW_LENGTH, "30")) * 1000); THE_INSTANCE.slideInterval = new Duration(Integer.parseInt( cl.getOptionValue(LogAnalyzerAppMain.SLIDE_INTERVAL, "5")) * 1000); THE_INSTANCE.logsDirectory = cl.getOptionValue( LogAnalyzerAppMain.LOGS_DIRECTORY, "/tmp/logs"); THE_INSTANCE.outputHtmlFile = cl.getOptionValue( LogAnalyzerAppMain.OUTPUT_HTML_FILE, "/tmp/log_stats.html"); THE_INSTANCE.checkpointDirectory = cl.getOptionValue( LogAnalyzerAppMain.CHECKPOINT_DIRECTORY, "/tmp/log-analyzer-streaming"); THE_INSTANCE.indexHtmlTemplate = cl.getOptionValue( LogAnalyzerAppMain.INDEX_HTML_TEMPLATE, "./src/main/resources/index.html.template"); THE_INSTANCE.outputDirectory = cl.getOptionValue( LogAnalyzerAppMain.OUTPUT_DIRECTORY, "/tmp/pandaout"); THE_INSTANCE.initialized = true; } catch (ParseException e) { THE_INSTANCE.initialized = false; System.err.println("Parsing failed. Reason: " + e.getMessage()); } } }
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); } }
@Test public void testShortOptionalArgValues() throws Exception { String[] args = new String[] { "-j", "ink", "idea" }; Parser parser = new PosixParser(); CommandLine cmd = parser.parse(opts,args); assertTrue( cmd.hasOption("j") ); assertEquals( "ink", cmd.getOptionValue("j") ); assertEquals( "ink", cmd.getOptionValues("j")[0] ); assertEquals( "idea", cmd.getOptionValues("j")[1] ); assertEquals( cmd.getArgs().length, 0 ); }
leaving = null; members = null; Parser parser = new PosixParser(); try { cl = parser.parse(options, cmdArgs); throw new CliParseException(ex); if (!(cl.hasOption("file") || cl.hasOption("members")) && !cl.hasOption("add") && !cl.hasOption("remove")) { throw new CliParseException(getUsageStr()); if (cl.hasOption("v")) { try{ version = Long.parseLong(cl.getOptionValue("v"), 16); } catch (NumberFormatException e){ throw new CliParseException("-v must be followed by a long (configuration version)"); if (cl.hasOption("add")) { joining = cl.getOptionValue("add").toLowerCase(); if (cl.hasOption("remove")) { leaving = cl.getOptionValue("remove").toLowerCase(); if (cl.hasOption("members")) {
@Before public void setUp() { options = new Options().addOption("p", false, "Option p").addOption("attr", true, "Option accepts argument"); parser = new PosixParser(); }
Command command = commandsMap.get(commandString); if (command != null) { CommandLineParser cmdLinePosixParser = new PosixParser(); String[] commandArgs = new String[args.length - 1]; System.arraycopy(args, 1, commandArgs, 0, args.length - 1); try { CommandLine commandLine = cmdLinePosixParser.parse( command.getOptions(), commandArgs); if (commandLine.hasOption('h')) { printHelp(command, writer); } else {
public static void main(String[] args) { // startup checks and logging EnvironmentInformation.logEnvironmentInfo(LOG, MesosSessionClusterEntrypoint.class.getSimpleName(), args); SignalHandler.register(LOG); JvmShutdownSafeguard.installAsShutdownHook(LOG); // load configuration incl. dynamic properties CommandLineParser parser = new PosixParser(); CommandLine cmd; try { cmd = parser.parse(ALL_OPTIONS, args); } catch (Exception e){ LOG.error("Could not parse the command-line options.", e); System.exit(STARTUP_FAILURE_RETURN_CODE); return; } Configuration dynamicProperties = BootstrapTools.parseDynamicProperties(cmd); Configuration configuration = MesosEntrypointUtils.loadConfiguration(dynamicProperties, LOG); MesosSessionClusterEntrypoint clusterEntrypoint = new MesosSessionClusterEntrypoint(configuration, dynamicProperties); ClusterEntrypoint.runClusterEntrypoint(clusterEntrypoint); }
@Test public void testWorkaround1() throws Exception { CommandLineParser parser = new PosixParser(); String[] args = new String[]{ "-t-something" }; CommandLine commandLine = parser.parse(options, args); assertEquals("-something", commandLine.getOptionValue('t')); }
@Override public CliCommand parse(String[] cmdArgs) throws CliParseException { Parser parser = new PosixParser(); try { cl = parser.parse(options, cmdArgs); } catch (ParseException ex) { throw new CliParseException(ex); } args = cl.getArgs(); if (cl.hasOption("?")) { printHelp(); } retainCompatibility(cmdArgs); return this; }
CommandLineParser cmdLineParser = new PosixParser(); Options options = new Options(); options.addOption(OptionBuilder.withLongOpt("integer-option") .withDescription("description") .withType(Number.class) .hasArg() .withArgName("argname") .create()); try { CommandLine cmdLine = cmdLineParser.parse(options, args); int value = 0; // initialize to some meaningful default value if (cmdLine.hasOption("integer-option")) { value = ((Number)cmdLine.getParsedOptionValue("integer-option")).intValue(); } System.out.println(value); } catch (ParseException e) { e.printStackTrace(); }
private void parseOptions(String[] args) { Options options = getOptions(); CommandLineParser parser = new PosixParser(); CommandLine cmdLine = null; try { cmdLine = parser.parse(options, args); } catch (ParseException e) { printHelpAndExit("Error parsing command line options: " + e.getMessage(), options); if (cmdLine.hasOption(HELP_OPT.getOpt())) { printHelpAndExit(options, 0); if (cmdLine.hasOption(HTTPD_PORT.getOpt())) { String portValue = cmdLine.getOptionValue(HTTPD_PORT.getOpt()); if (portValue.matches("\\d+")) { port = Integer.parseInt(portValue); if (cmdLine.hasOption(CRAWLER_NAMES.getOpt())) { String crawlerNames = cmdLine.getOptionValue(CRAWLER_NAMES.getOpt()); crawlers = crawlerNames.split(",");
public void parseWithPosixParser(final String[] args) { final CommandLineParser cmdLinePosixParser = new PosixParser(); final Options posixOptions = getPosixOptions(); try { commandLine = cmdLinePosixParser.parse(posixOptions, args); } catch (ParseException parseException) { System.err .println("Exception while parsing using commandling with PosixParser:\n" + parseException.getMessage()); } }
@Test public void testLongOptionalArgValues() throws Exception { String[] args = new String[] { "--gravy", "gold", "garden" }; Parser parser = new PosixParser(); CommandLine cmd = parser.parse(opts,args); assertTrue( cmd.hasOption("gravy") ); assertEquals( "gold", cmd.getOptionValue("gravy") ); assertEquals( "gold", cmd.getOptionValues("gravy")[0] ); assertEquals( "garden", cmd.getOptionValues("gravy")[1] ); assertEquals( cmd.getArgs().length, 0 ); }
@Test public void testLongOptionalArgValue() throws Exception { String[] args = new String[] { "--fish", "face" }; Parser parser = new PosixParser(); CommandLine cmd = parser.parse(opts,args); assertTrue( cmd.hasOption("fish") ); assertEquals( "face", cmd.getOptionValue("fish") ); }
@Before public void setUp() { options = new Options(); Option algorithm = new Option("a" , "algo", true, "the algorithm which it to perform executing"); algorithm.setArgName("algorithm name"); options.addOption(algorithm); Option key = new Option("k" , "key", true, "the key the setted algorithm uses to process"); algorithm.setArgName("value"); options.addOption(key); parser = new PosixParser(); }
@Test public void testUntypedPattern() throws Exception { Options options = PatternOptionBuilder.parsePattern("abc"); CommandLineParser parser = new PosixParser(); CommandLine line = parser.parse(options, new String[] { "-abc" }); assertTrue(line.hasOption('a')); assertNull("value a", line.getOptionObject('a')); assertTrue(line.hasOption('b')); assertNull("value b", line.getOptionObject('b')); assertTrue(line.hasOption('c')); assertNull("value c", line.getOptionObject('c')); }
public static void main(String[] args) { // startup checks and logging EnvironmentInformation.logEnvironmentInfo(LOG, MesosJobClusterEntrypoint.class.getSimpleName(), args); SignalHandler.register(LOG); JvmShutdownSafeguard.installAsShutdownHook(LOG); // load configuration incl. dynamic properties CommandLineParser parser = new PosixParser(); CommandLine cmd; try { cmd = parser.parse(ALL_OPTIONS, args); } catch (Exception e){ LOG.error("Could not parse the command-line options.", e); System.exit(STARTUP_FAILURE_RETURN_CODE); return; } Configuration dynamicProperties = BootstrapTools.parseDynamicProperties(cmd); Configuration configuration = MesosEntrypointUtils.loadConfiguration(dynamicProperties, LOG); MesosJobClusterEntrypoint clusterEntrypoint = new MesosJobClusterEntrypoint(configuration, dynamicProperties); ClusterEntrypoint.runClusterEntrypoint(clusterEntrypoint); } }
@Test public void testWorkaround2() throws Exception { CommandLineParser parser = new PosixParser(); String[] args = new String[]{ "-t", "\"-something\"" }; CommandLine commandLine = parser.parse(options, args); assertEquals("-something", commandLine.getOptionValue('t')); } }
Options options = new Options(); options.addOption(searchApp); PosixParser parser = new PosixParser(); CommandLine cmd = parser.parse( options, args); String[] searchArgs = cmd.getOptionValues("t");