public SavepointOptions(CommandLine line) { super(line); args = line.getArgs(); dispose = line.hasOption(SAVEPOINT_DISPOSE_OPTION.getOpt()); disposeSavepointPath = line.getOptionValue(SAVEPOINT_DISPOSE_OPTION.getOpt()); jarFile = line.getOptionValue(JAR_OPTION.getOpt()); }
/** * Parses the input args with a command line format, using * {@link org.apache.commons.cli.CommandLineParser}. * * @param args the input args * @return true if parsing succeeded */ private static boolean parseInputArgs(String[] args) { CommandLineParser parser = new DefaultParser(); CommandLine cmd; try { cmd = parser.parse(OPTIONS, args); } catch (ParseException e) { System.out.println("Failed to parse input args: " + e); return false; } sHelp = cmd.hasOption("help"); sMaster = cmd.getOptionValue("master", "FileSystemMaster"); sStart = Long.decode(cmd.getOptionValue("start", "0")); sEnd = Long.decode(cmd.getOptionValue("end", Long.valueOf(Long.MAX_VALUE).toString())); sJournalFile = cmd.getOptionValue("journalFile", ""); return true; }
private static void cmdInstallFramework(CommandLine cli) throws AndrolibException { int paraCount = cli.getArgList().size(); String apkName = cli.getArgList().get(paraCount - 1); ApkOptions apkOptions = new ApkOptions(); if (cli.hasOption("p") || cli.hasOption("frame-path")) { apkOptions.frameworkFolderLocation = cli.getOptionValue("p"); } if (cli.hasOption("t") || cli.hasOption("tag")) { apkOptions.frameworkTag = cli.getOptionValue("t"); } new Androlib(apkOptions).installFramework(new File(apkName)); }
private static String getMasterPassword(CommandLine cl) { if (cl.hasOption(MASTER_PWD_OPTION)) { if (cl.hasOption(MASTER_PWD_FILE_OPTION)) { System.out.println(String.format("both -%s and -%s are provided. Using -%s", MASTER_PWD_OPTION, MASTER_PWD_FILE_OPTION, MASTER_PWD_OPTION)); } return cl.getOptionValue(MASTER_PWD_OPTION); } Path masterPwdLoc = new Path(cl.getOptionValue(MASTER_PWD_FILE_OPTION)); Optional<String> masterPwd = PasswordManager.getMasterPassword(masterPwdLoc); if (masterPwd.isPresent()) { return masterPwd.get(); } throw new RuntimeException("Failed to get master password from " + masterPwdLoc); }
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()); } } }
if (cmd.hasOption(flinkJar.getOpt())) { String userPath = cmd.getOptionValue(flinkJar.getOpt()); if (!userPath.startsWith("file://")) { userPath = "file://" + userPath; localJarPath = new Path(new File(decodedPath).toURI()); } else { localJarPath = null; if (cmd.hasOption(queue.getOpt())) { yarnClusterDescriptor.setQueue(cmd.getOptionValue(queue.getOpt())); if (cmd.hasOption(name.getOpt())) { yarnClusterDescriptor.setName(cmd.getOptionValue(name.getOpt())); if (cmd.hasOption(zookeeperNamespace.getOpt())) { String zookeeperNamespaceValue = cmd.getOptionValue(this.zookeeperNamespace.getOpt()); yarnClusterDescriptor.setZookeeperNamespace(zookeeperNamespaceValue); if (cmd.hasOption(nodeLabel.getOpt())) { String nodeLabelValue = cmd.getOptionValue(this.nodeLabel.getOpt()); yarnClusterDescriptor.setNodeLabel(nodeLabelValue);
public boolean process_stage2(CliSessionState ss) { ss.getConf(); if (commandLine.hasOption('H')) { printUsage(); return false; } ss.setIsSilent(commandLine.hasOption('S')); ss.database = commandLine.getOptionValue("database"); ss.execString = commandLine.getOptionValue('e'); ss.fileName = commandLine.getOptionValue('f'); ss.setIsVerbose(commandLine.hasOption('v')); String[] initFiles = commandLine.getOptionValues('i'); if (null != initFiles) { ss.initFiles = Arrays.asList(initFiles); } if (ss.execString != null && ss.fileName != null) { System.err.println("The '-e' and '-f' options cannot be specified simultaneously"); printUsage(); return false; } if (commandLine.hasOption("hiveconf")) { Properties confProps = commandLine.getOptionProperties("hiveconf"); for (String propKey : confProps.stringPropertyNames()) { ss.cmdProperties.setProperty(propKey, confProps.getProperty(propKey)); } } return true; }
@Override void run(String[] args) { try { CommandLine cli = parseOptions(args); if (!paramsAreValid(cli)) { return; } String keystoreLocation = cli.getOptionValue(KEYSTORE_LOCATION.getOpt()); JCEKSKeystoreCredentialStore credentialStore = loadKeystore(keystoreLocation); Map<String, byte[]> keys = credentialStore.getAllEncodedKeys(); System.out.println("Keystore " + keystoreLocation + " has " + String.valueOf(keys.size()) + " keys."); } catch (IOException | ParseException e) { throw new RuntimeException(e); } }
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); }
public static ShutdownArgs parse(final String[] args) { try { CommandLineParser parser = new DefaultParser(); CommandLine cmd = parser.parse(createShutdownOptions(), args); return new ShutdownArgs(StartArgsParser.getPort(cmd.getOptionValue("s"))); } catch (ParseException e) { throw new ParseArgException("fail to parse arguments", e); } }
Options options = ServerUtil.buildCommandlineOptions(new Options()); commandLine = ServerUtil.parseCmdLine("mqnamesrv", args, buildCommandlineOptions(options), new PosixParser()); if (null == commandLine) { final NettyServerConfig nettyServerConfig = new NettyServerConfig(); nettyServerConfig.setListenPort(9876); if (commandLine.hasOption('c')) { String file = commandLine.getOptionValue('c'); if (file != null) { InputStream in = new BufferedInputStream(new FileInputStream(file)); if (commandLine.hasOption('p')) { InternalLogger console = InternalLoggerFactory.getLogger(LoggerName.NAMESRV_CONSOLE_NAME); MixAll.printObjectProperties(console, namesrvConfig);
@Test public void testNegativeOption() throws Exception { String[] args = new String[] { "-b", "-1"} ; options.addOption("1", false, null); CommandLine cl = parser.parse(options, args); assertEquals("-1", cl.getOptionValue("b")); }
Options options = new Options(); options.addOption(input); options.addOption(output); cmd = parser.parse(options, args); } catch (ParseException e) { System.out.println(e.getMessage()); formatter.printHelp("utility-name", options); String inputFilePath = cmd.getOptionValue("input"); String outputFilePath = cmd.getOptionValue("output"); System.out.println(inputFilePath); System.out.println(outputFilePath);
private ConfigProvider getFileSystemProvider(CommandLine commandLine, Properties defaultProperties) throws IOException { File directory = commandLine.hasOption(FILESYSTEM_CONFIG_DIRECTORY) ? new File(commandLine.getOptionValue(FILESYSTEM_CONFIG_DIRECTORY)) : new File(System.getProperty("user.dir")); String name = commandLine.hasOption(FILESYSTEM_CONFIG_NAME) ? commandLine.getOptionValue(FILESYSTEM_CONFIG_NAME) : DEFAULT_FILESYSTEMCONFIG_NAME; String lockPrefix = commandLine.hasOption(FILESYSTEM_CONFIG_LOCK_PREFIX) ? commandLine.getOptionValue(FILESYSTEM_CONFIG_LOCK_PREFIX) : DEFAULT_FILESYSTEMCONFIG_LOCK_PREFIX; return new FileSystemConfigProvider(directory, name, defaultProperties, new AutoManageLockArguments(lockPrefix)); }
@Override public void parse(String[] args) { super.parse(args); // support the old syntax "hivemetastore [port]" but complain args = commandLine.getArgs(); if (args.length > 0) { // complain about the deprecated syntax -- but still run System.err.println( "This usage has been deprecated, consider using the new command " + "line syntax (run with -h to see usage information)"); this.port = new Integer(args[0]); } // notice that command line options take precedence over the // deprecated (old style) naked args... if (commandLine.hasOption('p')) { this.port = Integer.parseInt(commandLine.getOptionValue('p')); } else { // legacy handling String metastorePort = System.getenv("METASTORE_PORT"); if (metastorePort != null) { this.port = Integer.parseInt(metastorePort); } } }
public OptionsResult parseOptions(String[] args) { CommandLineParser parser = new BasicParser(); List<AsyncMagicCommand.AsyncOptionCommand> commands = new ArrayList<>(); try { CommandLine cmd = parser.parse(asyncOptions.getOptions(), args); if (cmd.hasOption(AsyncOptions.THEN)) { commands.add(() -> BeakerXClientManager.get().runByTag(cmd.getOptionValue(AsyncOptions.THEN))); } } catch (ParseException e) { return new ErrorOptionsResult(e.getMessage()); } return new AsyncOptionsResult(commands); }
public CancelOptions(CommandLine line) { super(line); this.args = line.getArgs(); this.withSavepoint = line.hasOption(CANCEL_WITH_SAVEPOINT_OPTION.getOpt()); this.targetDirectory = line.getOptionValue(CANCEL_WITH_SAVEPOINT_OPTION.getOpt()); }
@Test public void testBasic() throws Exception { String[] args = new String[] { "-a", "Caesar", "-k", "A" }; CommandLine line = parser.parse( options, args); assertEquals( "Caesar", line.getOptionValue("a") ); assertEquals( "A", line.getOptionValue("k") ); }
/** * Parses the input args with a command line format, using * {@link org.apache.commons.cli.CommandLineParser}. * * @param args the input args * @return true if parsing succeeded */ private static boolean parseInputArgs(String[] args) { CommandLineParser parser = new DefaultParser(); CommandLine cmd; try { cmd = parser.parse(OPTIONS, args); } catch (ParseException e) { System.out.println("Failed to parse input args: " + e); return false; } sHelp = cmd.hasOption("help"); sType = OperationType.valueOf(cmd.getOptionValue("type", "READ")); sFileSize = FormatUtils.parseSpaceSize(cmd.getOptionValue("fileSize", "1KB")); sIterations = Integer.parseInt(cmd.getOptionValue("iterations", "1")); sConcurrency = Integer.parseInt(cmd.getOptionValue("concurrency", "1")); return true; }
protected void parseCommandLine(CommandLine cmdline) throws ParseException { if (!cmdline.hasOption("u")) { throw new ParseException("No distributedlog uri provided."); } uri = URI.create(cmdline.getOptionValue("u")); if (cmdline.hasOption("c")) { String configFile = cmdline.getOptionValue("c"); try { dlConf.loadConf(new File(configFile).toURI().toURL()); } catch (ConfigurationException e) { throw new ParseException("Failed to load distributedlog configuration from " + configFile + "."); } catch (MalformedURLException e) { throw new ParseException("Failed to load distributedlog configuration from " + configFile + ": malformed uri."); } } if (cmdline.hasOption("a")) { zkAclId = cmdline.getOptionValue("a"); } if (cmdline.hasOption("f")) { force = true; } }