Java Code Examples for picocli.CommandLine.Model.PositionalParamSpec#Builder
The following examples show how to use
picocli.CommandLine.Model.PositionalParamSpec#Builder .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ModelPositionalParamSpecTest.java From picocli with Apache License 2.0 | 6 votes |
@Test public void testPositionalInteractiveNotSupportedForMultiValue() { PositionalParamSpec.Builder[] options = new PositionalParamSpec.Builder[]{ PositionalParamSpec.builder().arity("1").interactive(true), PositionalParamSpec.builder().arity("2").interactive(true), PositionalParamSpec.builder().arity("3").interactive(true), PositionalParamSpec.builder().arity("1..2").interactive(true), PositionalParamSpec.builder().arity("1..*").interactive(true), PositionalParamSpec.builder().arity("0..*").interactive(true), }; for (PositionalParamSpec.Builder opt : options) { try { opt.build(); fail("Expected exception"); } catch (CommandLine.InitializationException ex) { assertEquals("Interactive options and positional parameters are only supported for arity=0 and arity=0..1; not for arity=" + opt.arity(), ex.getMessage()); } } // no errors PositionalParamSpec.builder().arity("0").interactive(true).build(); PositionalParamSpec.builder().arity("0..1").interactive(true).build(); }
Example 2
Source File: ModelArgSpecTest.java From picocli with Apache License 2.0 | 5 votes |
@Test public void testArgSpecBuilderSplitRegexSynopsisLabel() { Builder builder = OptionSpec.builder("-x").splitRegexSynopsisLabel(";"); assertEquals("split regex synopsis label", ";", builder.splitRegexSynopsisLabel()); assertEquals("split regex synopsis label", ";", builder.build().splitRegexSynopsisLabel()); PositionalParamSpec.Builder pb = PositionalParamSpec.builder().splitRegexSynopsisLabel(";"); assertEquals("split regex synopsis label", ";", pb.splitRegexSynopsisLabel()); assertEquals("split regex synopsis label", ";", pb.build().splitRegexSynopsisLabel()); }
Example 3
Source File: ModelPositionalParamSpecTest.java From picocli with Apache License 2.0 | 5 votes |
@Test public void testPositionalParamSpecEquals() { PositionalParamSpec.Builder positional = PositionalParamSpec.builder() .arity("1") .hideParamSyntax(true) .required(true) .splitRegex(";") .description("desc") .descriptionKey("key") .type(Map.class) .auxiliaryTypes(Integer.class, Double.class) .index("1..3"); PositionalParamSpec p1 = positional.build(); assertEquals(p1, p1); assertEquals(p1, positional.build()); assertNotEquals(p1, positional.arity("2").build()); assertNotEquals(p1, positional.arity("1").hideParamSyntax(false).build()); assertNotEquals(p1, positional.hideParamSyntax(true).required(false).build()); assertNotEquals(p1, positional.required(true).splitRegex(",").build()); assertNotEquals(p1, positional.splitRegex(";").description("xyz").build()); assertNotEquals(p1, positional.description("desc").descriptionKey("XX").build()); assertNotEquals(p1, positional.descriptionKey("key").type(List.class).build()); assertNotEquals(p1, positional.type(Map.class).auxiliaryTypes(Short.class).build()); assertEquals(p1, positional.auxiliaryTypes(Integer.class, Double.class).build()); assertNotEquals(p1, positional.index("0..*").build()); assertEquals(p1, positional.index("1..3").build()); }
Example 4
Source File: ModelArgSpecTest.java From picocli with Apache License 2.0 | 5 votes |
@Test public void testArgSpecBuilder_scopeSetter() { IScope scope = new IScope() { public <T> T get() { return null; } public <T> T set(T value) { return null; } }; PositionalParamSpec.Builder builder = PositionalParamSpec.builder().scope(scope); assertSame(scope, builder.scope()); }
Example 5
Source File: ModelArgSpecTest.java From picocli with Apache License 2.0 | 5 votes |
@Test public void testArgSpecBuilder_parameterConsumerSetter() { IParameterConsumer consumer = new IParameterConsumer() { public void consumeParameters(Stack<String> args, ArgSpec argSpec, CommandSpec commandSpec) { } }; PositionalParamSpec.Builder builder = PositionalParamSpec.builder().parameterConsumer(consumer); assertSame(consumer, builder.parameterConsumer()); }
Example 6
Source File: ModelArgSpecTest.java From picocli with Apache License 2.0 | 5 votes |
@Test public void testPositionalParamSpecBuilderCapacity() { PositionalParamSpec.Builder builder = PositionalParamSpec.builder(); assertNull(builder.capacity()); CommandLine.Range value = CommandLine.Range.valueOf("1..2"); builder.capacity(value); assertSame(value, builder.capacity()); }
Example 7
Source File: ModelArgSpecTest.java From picocli with Apache License 2.0 | 5 votes |
@Test public void testArgSpecBuilderSplitRegexAndSplitRegexSynopsisLabel() { Builder builder = OptionSpec.builder("-x").type(String[].class).splitRegex("#").splitRegexSynopsisLabel(";"); assertEquals("split regex synopsis label", ";", builder.splitRegexSynopsisLabel()); assertEquals("split regex synopsis label", ";", builder.build().splitRegexSynopsisLabel()); PositionalParamSpec.Builder pb = PositionalParamSpec.builder().type(String[].class).splitRegex("#").splitRegexSynopsisLabel(";"); assertEquals("split regex synopsis label", ";", pb.splitRegexSynopsisLabel()); assertEquals("split regex synopsis label", ";", pb.build().splitRegexSynopsisLabel()); }
Example 8
Source File: EnvironmentVariableDefaultProviderTest.java From besu with Apache License 2.0 | 5 votes |
@Test public void shouldReturnNullForPositionalParameter() { environment.put("BESU_KEY", "abc"); final PositionalParamSpec.Builder positional = PositionalParamSpec.builder().descriptionKey("key"); assertThat(provider.defaultValue(positional.build())).isNull(); }
Example 9
Source File: ModelArgSpecTest.java From picocli with Apache License 2.0 | 5 votes |
@Test public void testArgSpecBuilderSplitRegex() { Builder builder = OptionSpec.builder("-x").type(String[].class).splitRegex(";"); assertEquals("split regex", ";", builder.splitRegex()); assertEquals("split regex", ";", builder.build().splitRegex()); PositionalParamSpec.Builder pb = PositionalParamSpec.builder().type(String[].class).splitRegex(";"); assertEquals("split regex", ";", pb.splitRegex()); assertEquals("split regex", ";", pb.build().splitRegex()); }
Example 10
Source File: ModelArgSpecTest.java From picocli with Apache License 2.0 | 5 votes |
@Test public void testArgSpecBuilderCompletionCandidates() { List<String> candidates = Arrays.asList("a", "b"); PositionalParamSpec.Builder positional = PositionalParamSpec.builder() .completionCandidates(candidates); assertEquals(candidates, positional.completionCandidates()); }
Example 11
Source File: ModelArgSpecTest.java From picocli with Apache License 2.0 | 5 votes |
@Test public void testArgSpecBuilderHasInitialValue() { PositionalParamSpec.Builder positional = PositionalParamSpec.builder() .hasInitialValue(true); assertEquals(true, positional.hasInitialValue()); assertEquals(false, positional.hasInitialValue(false).hasInitialValue()); }
Example 12
Source File: ModelArgSpecTest.java From picocli with Apache License 2.0 | 5 votes |
@Test public void testArgSpecBuilderHideParamSyntax() { PositionalParamSpec.Builder positional = PositionalParamSpec.builder() .hideParamSyntax(true); assertEquals(true, positional.hideParamSyntax()); assertEquals(false, positional.hideParamSyntax(false).hideParamSyntax()); }
Example 13
Source File: ModelArgSpecTest.java From picocli with Apache License 2.0 | 5 votes |
@Test public void testArgSpecBuilderDescriptionKey() { PositionalParamSpec.Builder positional = PositionalParamSpec.builder() .descriptionKey("key"); assertEquals("key", positional.descriptionKey()); assertEquals("xxx", positional.descriptionKey("xxx").descriptionKey()); }
Example 14
Source File: ModelArgSpecTest.java From picocli with Apache License 2.0 | 5 votes |
@Test public void testArgSpecEquals() { PositionalParamSpec.Builder positional = PositionalParamSpec.builder() .arity("1") .hideParamSyntax(true) .required(true) .splitRegex(";") .description("desc") .descriptionKey("key") .type(Map.class) .auxiliaryTypes(Integer.class, Double.class) .inherited(true) .scopeType(CommandLine.ScopeType.INHERIT); PositionalParamSpec p1 = positional.build(); assertEquals(p1, p1); assertEquals(p1, positional.build()); assertNotEquals(p1, positional.arity("2").build()); assertNotEquals(p1, positional.arity("1").hideParamSyntax(false).build()); assertNotEquals(p1, positional.hideParamSyntax(true).required(false).build()); assertNotEquals(p1, positional.required(true).splitRegex(",").build()); assertNotEquals(p1, positional.splitRegex(";").description("xyz").build()); assertNotEquals(p1, positional.description("desc").descriptionKey("XX").build()); assertNotEquals(p1, positional.descriptionKey("key").type(List.class).build()); assertNotEquals(p1, positional.type(Map.class).auxiliaryTypes(Short.class).build()); assertEquals(p1, positional.auxiliaryTypes(Integer.class, Double.class).build()); assertNotEquals(p1, positional.inherited(false).build()); assertEquals(p1, positional.inherited(true).build()); assertNotEquals(p1, positional.scopeType(CommandLine.ScopeType.LOCAL).build()); assertEquals(p1, positional.scopeType(CommandLine.ScopeType.INHERIT).build()); }
Example 15
Source File: AbstractCommandSpecProcessor.java From picocli with Apache License 2.0 | 5 votes |
private void buildParameter(Element element, Context context) { if (context.parameters.containsKey(element)) { return; } TypedMember typedMember = extractTypedMember(element, "@Parameters"); if (typedMember != null) { PositionalParamSpec.Builder builder = PositionalParamSpec.builder(typedMember, context.factory); builder.completionCandidates(CompletionCandidatesMetaData.extract(element)); builder.converters(TypeConverterMetaData.extract(element)); builder.parameterConsumer(ParameterConsumerMetaData.extract(element)); context.parameters.put(element, builder); } }
Example 16
Source File: ModelArgSpecTest.java From picocli with Apache License 2.0 | 4 votes |
@Test public void testArgSpecBuilder_parameterConsumerGetter() { PositionalParamSpec.Builder builder = PositionalParamSpec.builder(); assertNull(builder.parameterConsumer()); }
Example 17
Source File: ModelArgSpecTest.java From picocli with Apache License 2.0 | 4 votes |
@Test public void testArgSpecBuilder_scopeGetter() { PositionalParamSpec.Builder builder = PositionalParamSpec.builder(); assertNotNull(builder.scope()); }