List<String> args) throws Exception { OptionParser p = new OptionParser(); OptionSpec<String> keyOption = p.accepts("key", "Metadata key") .withOptionalArg() .ofType(String.class); OptionSet opts = p.parse(args.toArray(new String[0])); String keyName = keyOption.value(opts); List<String> nargs = (List<String>)opts.nonOptionArguments(); if (nargs.size() != 1) { err.println("Expected 1 arg: input_file");
@Override public String[] getPropertyNames() { List<String> names = new ArrayList<>(); for (OptionSpec<?> spec : this.source.specs()) { String lastOption = CollectionUtils.lastElement(spec.options()); if (lastOption != null) { // Only the longest name is used for enumerating names.add(lastOption); } } return StringUtils.toStringArray(names); }
public static void main(String... args) throws Exception { final OptionParser parser = new OptionParser(); final OptionSpec<Void> help = parser.accepts("help").forHelp(); final OptionSpec<Double> wgsLongitudeOpt = parser.acceptsAll(Arrays.asList("longitude")) .withRequiredArg().ofType(Double.class).required().describedAs("The WGS Longitude"); final OptionSpec<Double> wgsLatitudeOpt = parser.acceptsAll(Arrays.asList("latitude")) .withRequiredArg().ofType(Double.class).required().describedAs("The WGS Latitude"); OptionSet options = null; try { options = parser.parse(args); } catch (final OptionException e) { System.out.println(e.getMessage()); parser.printHelpOn(System.out); throw e; } if (options.has(help)) { parser.printHelpOn(System.out); return; } UTM fromWGS = UTM.fromWGS84(wgsLatitudeOpt.value(options), wgsLongitudeOpt.value(options)); System.out.println(fromWGS.toString()); } }
String uri = mongouri.value(options); if (uri == null) { String db = dbName.value(options); if (db == null) { db = OakFixture.getUniqueDatabaseName(OakFixture.OAK_MONGO); uri = "mongodb://" + host.value(options) + ":" + port.value(options) + "/" + db; StatisticsProvider statsProvider = options.has(metrics) ? getStatsProvider() : StatisticsProvider.NOOP; int cacheSize = cache.value(options); RepositoryFixture[] allFixtures = new RepositoryFixture[] { new JackrabbitRepositoryFixture(base.value(options), cacheSize), OakRepositoryFixture.getMemoryNS(cacheSize * MB), OakRepositoryFixture.getMongo(uri, dropDBAfterTest.value(options), cacheSize * MB), OakRepositoryFixture.getMongoWithDS(uri, dropDBAfterTest.value(options), cacheSize * MB, base.value(options), fdsCache.value(options)), OakRepositoryFixture.getMongoNS(uri, dropDBAfterTest.value(options), cacheSize * MB), OakRepositoryFixture.getSegmentTar(base.value(options), 256, cacheSize, mmap.value(options)), OakRepositoryFixture.getSegmentTarWithDataStore(base.value(options), 256, cacheSize, mmap.value(options), fdsCache.value(options)), OakRepositoryFixture.getSegmentTarWithColdStandby(base.value(options), 256, cacheSize, mmap.value(options), coldUseDataStore.value(options), fdsCache.value(options),
switch (netFlag.value(options)) { case MAIN: case PROD: mode = modeFlag.value(options); chainFileName = new File(chainFlag.value(options)); condition = new Condition(conditionFlag.value(options)); password = passwordFlag.value(options); walletFile = new File(walletFileName.value(options)); if (action == ActionEnum.CREATE) { createWallet(options, params, walletFile); send(outputFlag.values(options), feePerKb, lockTime, allowUnconfirmed); } else if (options.has(paymentRequestLocation)) { sendPaymentRequest(paymentRequestLocation.value(options), !options.has("no-pki")); } else { System.err.println("You must specify a --payment-request or at least one --output=addr:value."); sendCLTVPaymentChannel(refundFlag.value(options), outputFlag.value(options), feePerKb, lockTime, allowUnconfirmed); } break; case SETTLE_CLTVPAYMENTCHANNEL: { settleCLTVPaymentChannel(txHashFlag.value(options), outputFlag.value(options), feePerKb, allowUnconfirmed); } break; case REFUND_CLTVPAYMENTCHANNEL: {
public void run(String[] args) throws Exception { OptionParser parser = new OptionParser(); parser.formatHelpWith(new OptionFormatter(label())); OptionSpec<String> optClassPath = parser.accepts("cp", "Additional classpath entries, where to look for the referenced classes.") .withRequiredArg().ofType(String.class).describedAs("classpath").withValuesSeparatedBy(getProperty("path.separator")); OptionSpec<String> optClasses = parser.nonOptions("Class names to work on."); try { OptionSet set = parser.parse(args); classes = set.valuesOf(optClasses); if (classes.isEmpty()) { System.err.println("Need class name(s) as the arguments."); if (set.has(optClassPath)) { ClassUtils.addClasspathEntries(optClassPath.values(set));
ProxyOptions(final String[] args) { final OptionParser parser = new OptionParser(); final OptionSpec<Void> help = parser.acceptsAll(Arrays.asList("h", "help"), "Print help") .forHelp(); final OptionSpec<Integer> port = parser.acceptsAll(Arrays.asList("p", "port"), "Specify the bind port to be used. The configuration bind port will be ignored.") .withRequiredArg().ofType(Integer.class); final OptionSet set = parser.parse(args); this.help = set.has(help); this.port = port.value(set); if (this.help) { try { parser.printHelpOn(System.out); } catch (final IOException e) { logger.error("Could not print help", e); } } }
final OptionParser parser = new OptionParser(false); OptionSpecBuilder bld = parser.acceptsAll(arg.getNames(), arg.doc); if (arg.isFlag()) { bld.withOptionalArg().withValuesConvertedBy(new StrictBooleanConverter()); } else { bld.withRequiredArg(); parser.nonOptions(); if (parsedArguments.has(SpecialArgumentsCollection.ARGUMENTS_FILE_FULLNAME)) { final List<String> argfiles = parsedArguments.valuesOf(SpecialArgumentsCollection.ARGUMENTS_FILE_FULLNAME).stream() .map(f -> (String)f) .collect(Collectors.toList()); for (OptionSpec<?> optSpec : parsedArguments.asMap().keySet()) { if (parsedArguments.has(optSpec)) { ArgumentDefinition argDef = argumentMap.get(optSpec.options().get(0)); setArgument(argDef, (List<String>) optSpec.values(parsedArguments));
/** * * @param line */ public ExecJavaCliParser(String line){ this.optionParser = new OptionParser("D:X:"); this.optionParser.allowsUnrecognizedOptions(); this.xVmOptions = this.optionParser.accepts("X").withRequiredArg(); this.sysPropOptions = this.optionParser.accepts("D").withRequiredArg(); this.mainArgumentsOptions = this.optionParser.nonOptions(); this.optionSet = this.optionParser.parse(line.split(" ")); Pattern p = Pattern.compile("([\\p{L}_$][\\p{L}\\p{N}_$]*\\.)*[\\p{L}_$][\\p{L}\\p{N}_$]*"); this.mainArguments = new ArrayList<String>(this.mainArgumentsOptions.values(this.optionSet)); Iterator<String> mainArgumentsIter = this.mainArguments.iterator(); boolean mainFound = false; while (mainArgumentsIter.hasNext()){ String value = mainArgumentsIter.next(); Matcher m = p.matcher(value); boolean matches = m.matches(); if (matches && !mainFound){ mainFound = true; this.main = value; mainArgumentsIter.remove(); break; } else if (!mainFound){ mainArgumentsIter.remove(); } } }
data.setTestPlugin(userArgs.valueOf(this.testPluginSpec)); data.setReportDir(userArgs.valueOf(this.reportDirSpec)); data.setTargetClasses(this.targetClassesSpec.values(userArgs)); data.setTargetTests(FCollection.map(this.targetTestsSpec.values(userArgs), Glob.toGlobPredicate())); data.setSourceDirs(this.sourceDirSpec.values(userArgs)); data.setMutators(this.mutators.values(userArgs)); data.setFeatures(this.features.values(userArgs)); data.setDependencyAnalysisMaxDistance(this.depth.value(userArgs)); data.addChildJVMArgs(this.jvmArgs.values(userArgs)); data.setFullMutationMatrix(this.fullMutationMatrixSpec.value(userArgs)); data.setNumberOfThreads(this.threadsSpec.value(userArgs)); data.setTimeoutFactor(this.timeoutFactorSpec.value(userArgs)); data.setTimeoutConstant(this.timeoutConstSpec.value(userArgs)); data.setLoggingClasses(this.avoidCallsSpec.values(userArgs)); data.setExcludedMethods(this.excludedMethodsSpec.values(userArgs)); data.setExcludedClasses(this.excludedClassesSpec.values(userArgs)); data.setExcludedTestClasses(FCollection.map( this.excludedTestClassesSpec.values(userArgs), Glob.toGlobPredicate())); data.addOutputFormats(this.outputFormatSpec.values(userArgs)); data.setFailWhenNoMutations(this.failWhenNoMutations.value(userArgs)); data.setCodePaths(this.codePaths.values(userArgs)); data.setMutationUnitSize(this.mutationUnitSizeSpec.value(userArgs)); data.setHistoryInputLocation(this.historyInputSpec.value(userArgs)); data.setHistoryOutputLocation(this.historyOutputSpec.value(userArgs));
public OptionSet parse(String... args) throws IOException { try { parser.accepts("version", "Display connector version information."); handleVersionAndHelp(parser, args); final OptionSet options = parser.parse(args); final File configFile = this.configFile.value(options); if (!configFile.exists()) { System.err.println("ERROR: Config file not found at " + configFile.getAbsoluteFile()); System.err.println(" Please create this file, or use the --config option to specify a different file."); System.err.println(" Examples may be found in the 'config' directory."); System.exit(1); } return options; } catch (OptionException e) { System.err.println(e.getMessage()); System.err.println(); parser.printHelpOn(System.err); System.exit(1); throw new AssertionError("unreachable"); } }
KeyStoreWrapper keystore = KeyStoreWrapper.load(env.configFile()); if (keystore == null) { if (options.has(forceOption) == false && terminal.promptYesNo("The elasticsearch keystore does not exist. Do you want to create it?", false) == false) { terminal.println("Exiting without creating keystore."); List<String> argumentValues = arguments.values(options); if (argumentValues.size() == 0) { throw new UserException(ExitCodes.USAGE, "Missing setting name"); if (keystore.getSettingNames().contains(setting) && options.has(forceOption) == false) { if (terminal.promptYesNo("Setting " + setting + " already exists. Overwrite?", false) == false) { terminal.println("Exiting without modifying keystore.");
final int toNodeId; if (options.has(folderOption)) { final Path path = getPath(folderOption.value(options)).getParent(); final Path shardParent = path.getParent(); final Path shardParentParent = shardParent.getParent(); indexName = Objects.requireNonNull(indexNameOption.value(options), "Index name is required"); shardId = Objects.requireNonNull(shardIdOption.value(options), "Shard ID is required");
@Override protected void execute(Terminal terminal, OptionSet options, Environment env) throws UserException { if (options.nonOptionArguments().isEmpty() == false) { throw new UserException(ExitCodes.USAGE, "Positional arguments not allowed, found " + options.nonOptionArguments()); if (options.has(versionOption)) { final String versionOutput = String.format( Locale.ROOT, final boolean daemonize = options.has(daemonizeOption); final Path pidFile = pidfileOption.value(options); final boolean quiet = options.has(quietOption);
/** * Gives the argument associated with the given option. * * <p>This method recognizes only instances of options returned from the fluent interface methods.</p> * * @param <V> represents the type of the arguments the given option accepts * @param option the option to search for * @return the argument of the given option; {@code null} if no argument is present, or that option was not * detected * @throws OptionException if more than one argument was detected for the option * @throws NullPointerException if {@code option} is {@code null} * @throws ClassCastException if the arguments of this option are not of the expected type */ public <V> V valueOf( OptionSpec<V> option ) { ensureNotNull( option ); List<V> values = valuesOf( option ); switch ( values.size() ) { case 0: return null; case 1: return values.get( 0 ); default: throw new MultipleArgumentsForOptionException( option.options() ); } }
public String getPassword(){ return rdbjdbcpasswd.value(options); } }
static CodecFactory codecFactory(OptionSet opts, OptionSpec<String> codec, OptionSpec<Integer> level, String defaultCodec) { String codecName = opts.hasArgument(codec) ? codec.value(opts) : defaultCodec; if(codecName.equals(DEFLATE_CODEC)) { return CodecFactory.deflateCodec(level.value(opts)); } else if(codecName.equals(DataFileConstants.XZ_CODEC)) { return CodecFactory.xzCodec(level.value(opts)); } else { return CodecFactory.fromString(codec.value(opts)); } } }
private Collection<String> processArgs(OptionSpec<String> op, OptionSet set) { if (set.hasArgument(op)) { try { List<String> vals = op.values(set); if (vals.size() != 1) { return vals; } else { return StringUtils.splitQuotedEscape(op.value(set)); } } catch (OptionException e) { return StringUtils.splitQuotedEscape(op.value(set)); } } else { return null; } }
@Override public String toString() { if (optionSet == null) return ""; String nonOptionArgs = ""; if (optionSet.nonOptionArguments() != null) { int i = 0; for (Object object : optionSet.nonOptionArguments()) { if (i > 0) nonOptionArgs += " "; nonOptionArgs += "\"" + object.toString() + "\""; i++; } } String optionArgs = ""; if (optionSet.asMap() != null) { int i = 0; for (Map.Entry<OptionSpec<?>, List<?>> entry : optionSet.asMap().entrySet()) { if (entry.getValue().size() > 0) { if (i > 0) optionArgs += " "; optionArgs += "--" + entry.getKey().options().get(0) + "=\"" + entry.getValue().get(0) + "\""; i++; } } } return nonOptionArgs + " " + optionArgs; }