final Menu m = Menu.builder() .addHelpOption("h", "help", "Hi") .add(Option.builder("i", ArgumentParser.prefixedIntList("t")).build(), consumer, new ArgHandler<List<String>, List<String>>() {
static OptionArg<List<String>> createIncludeOption( Map<String, Path> pathMap, Builder builder) { final StringBuilder sb = new StringBuilder(); printPathOptions(pathMap, sb); sb.append("This option can not be used together with --exclude."); return Option .builder("i", ArgumentParser.stringListParser()) .longName("include") .description(sb.toString()) .build(); }
.add(Option.builder("a", ArgumentParser.longParser()).build(), list, new ArgHandler<List<Object>, Long>() { .longName("add-all") .description("Add all longs, and then some. Please note that " + "using this option may alter the universe " + "beyond recognition. Use at your own risk.\n\n" + "Footer of the message.") .setOptionalArgument() .build(), list, new ArgHandler<List<Object>, List<Long>>() { .add(Option.builder("asl", ArgumentParser.stringListParser()).build(), list, new ArgHandler<List<Object>, List<String>>() { .add(Option.builder("z").build(), list, dummyHandler()) .closeGroup() .add(Option.builder("as", ArgumentParser.stringParser()).build(), list, new ArgHandler<List<Object>, String>() { .add(Option.builder("failure", ArgumentParser .booleanParser()) .build(), list, new ArgHandler<List<Object>, Boolean>() {
.addHelpOption("h", "help", "Hi") .add(Option.builder("e", ArgumentParser.enumListParser("enum list", TestEnum.class)).build(), consumer, new AddToListHandler<List<TestEnum>>())
/** * Tests correct parsing of enum. */ @Test public void testEnum() { final List<TestEnum> consumer = new ArrayList<>(); final Menu m = Menu.builder() .addHelpOption("h", "help", "Hi") .add(Option.builder("e", ArgumentParser.enumParser("testenum", TestEnum.class)).build(), consumer, new AddToListHandler<TestEnum>()) .build(); m.execute("-e", "A"); assertThat(consumer) .containsExactly(TestEnum.A); consumer.clear(); m.execute("-e", "B"); assertThat(consumer) .containsExactly(TestEnum.B); consumer.clear(); testFail(m, "e", CauseType.INVALID_ARG_FORMAT, "-e", "a"); testFail(m, "e", CauseType.INVALID_ARG_FORMAT, "-e", "NON_EXISTING_ENUM"); assertThat(consumer).isEmpty(); }
@SuppressWarnings({"unchecked", "rawtypes"}) static OptionParser adapt(OptionParser exec, String shortPrefix, String longPrefix) { final Option opt = exec.getOption(); if (opt instanceof OptionArg<?>) { final OptionArg<?> adapted = adaptNames( Option.builder((OptionArg<?>) opt), shortPrefix, longPrefix) .build(); return ((ArgParser) exec).newInstance(adapted); } final OptionNoArg adapted = adaptNames( Option.builder((OptionNoArg) opt), shortPrefix, longPrefix) .build(); return ((NoArgParser<?>) exec).newInstance(adapted); }
/** * Test for checking whether duplicate options are detected. */ @Test(expected = IllegalArgumentException.class) public void duplicateOptions() { final Object subject = new Object(); Menu .builder() .add(Option.builder("a").build(), subject, dummyHandler()) .add(Option.builder("aa", ArgumentParser.stringParser()) .longName("a") .build(), subject, CliTest.<Object, String>dummyArgHandler()); }
static OptionArg<String> createFilterOption(Builder ref) { return Option .builder("f", ArgumentParser.stringParser()) .longName("filter") .description( "Sets a filter of which paths to include. The filter is a string " + "of the form 'syntax:pattern', where 'syntax' is either " + "'glob' or 'regex'. The current filter is '" + ref.pathPredicate + "', there are " + ref.getNumberOfFiles() + " files that satisfy this filter. For more information about" + " the supported syntax please review the documentation of the" + " java.nio.file.FileSystem.getPathMatcher(String) method.") .build(); }
static OptionArg<String> createFilterOption(Builder ref) { return Option .builder("f", ArgumentParser.stringParser()) .longName("filter") .description( "Sets a filter of which paths to include. The filter is a string " + "of the form 'syntax:pattern', where 'syntax' is either " + "'glob' or 'regex'. The current filter is '" + ref.pathPredicate + "', there are " + ref.getNumberOfFiles() + " files that satisfy this filter. For more information about" + " the supported syntax please review the documentation of the" + " java.nio.file.FileSystem.getPathMatcher(String) method.") .build(); }
static <T> ArgBuilder<T> builder(OptionArg<T> opt) { return new ArgBuilder<>(opt); }
/** * Create a builder for building {@link OptionArg} instances. * @param shortName The short name to use, must conform to this regular * expression: {@link #NAME_REGEX}. * @param argumentParser The {@link ArgumentParser} defines the type of * argument that the resulting option expects. * @param <T> The type of argument that the resulting {@link OptionArg} will * expect. * @return A new builder instance. */ public static <T> ArgBuilder<T> builder(String shortName, ArgumentParser<T> argumentParser) { return new ArgBuilder<>(shortName, argumentParser); }
/** * Calling this method will make the argument of the option optional. * @return This, as per the builder pattern. */ public ArgBuilder<V> setOptionalArgument() { isArgOptional = true; return self(); }
static OptionArg<Long> createSeedOption(Experiment.Builder builder) { return Option.builder(S, ArgumentParser.longParser()) .longName("seed") .description( "Sets the master random seed, default: ", builder.masterSeed, ".") .build(); }
static OptionArg<Integer> createSeedRepetitionsOpt(Builder builder) { return Option .builder("sr", ArgumentParser.intParser()) .longName("seed-repetitions") .description( "Sets the number of seed repetitions of each setting, default: ", builder.seedRepetitions) .build(); }
static OptionArg<Integer> createCompositeSizeOpt(Builder expBuilder) { return Option.builder("cs", ArgumentParser.intParser()) .longName("composite-size") .description( "Sets the composite task size to use in case of distributed computation" + ", default: ", expBuilder.compositeTaskSize) .build(); }
static OptionArg<Integer> createBatchesOpt(Builder expBuilder) { return Option.builder("b", ArgumentParser.intParser()) .longName("batches") .description( "Sets the number of batches to use in case of distributed " + "computation, default: ", expBuilder.numBatches, ". This option can not be used together with --threads.") .build(); }
static OptionArg<List<String>> createAddOption() { return Option .builder("a", ArgumentParser.stringListParser()) .longName("add") .description( "Adds the specified paths. A path may be a file or a directory. " + "If it is a directory it will be searched recursively.") .build(); }
static OptionArg<List<String>> createExcludeOption( Map<String, Path> pathMap, Builder builder) { final StringBuilder sb = new StringBuilder(); printPathOptions(pathMap, sb); sb.append("This option can not be used together with --include."); return Option.builder("e", ArgumentParser.stringListParser()) .longName("exclude") .description(sb.toString()) .build(); }
static OptionArg<Long> createWarmupOption(Builder builder) { return Option.builder("w", ArgumentParser.longParser()) .longName("warmup") .description( "Sets the warmup period (in ms) of the experiment, default: ", builder.warmupPeriodMs, " ms.") .build(); }
static OptionArg<List<String>> createIncludeOpt( Map<String, MASConfiguration> configMap) { return Option.builder("i", ArgumentParser.prefixedIntList(CONFIG_PREFIX)) .longName("include") .description( "The following configurations can be included in the experiment " + "setup:", createConfigString(configMap), "This option can not be used together with --exclude.") .build(); }