picocli.CommandLine.IDefaultValueProvider Java Examples
The following examples show how to use
picocli.CommandLine.IDefaultValueProvider.
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: ConfigOptionSearchAndRunHandler.java From besu with Apache License 2.0 | 5 votes |
@VisibleForTesting IDefaultValueProvider createDefaultValueProvider( final CommandLine commandLine, final Optional<File> configFile) { if (configFile.isPresent()) { return new CascadingDefaultProvider( new EnvironmentVariableDefaultProvider(environment), new TomlConfigFileDefaultProvider(commandLine, configFile.get())); } else { return new EnvironmentVariableDefaultProvider(environment); } }
Example #2
Source File: ConfigOptionSearchAndRunHandlerTest.java From besu with Apache License 2.0 | 5 votes |
@Test public void handle() throws Exception { when(mockConfigOptionGetter.get()).thenReturn(temp.newFile()); final List<Object> result = configParsingHandler.handle(mockParseResult); verify(mockCommandLine).setDefaultValueProvider(any(IDefaultValueProvider.class)); verify(mockCommandLine).parseWithHandlers(eq(resultHandler), eq(exceptionHandler), anyString()); assertThat(result).isEmpty(); }
Example #3
Source File: ConfigOptionSearchAndRunHandlerTest.java From besu with Apache License 2.0 | 5 votes |
@Test public void shouldRetrieveConfigFromEnvironmentWhenConfigFileSpecified() throws Exception { final IDefaultValueProvider defaultValueProvider = configParsingHandler.createDefaultValueProvider( mockCommandLine, Optional.of(new File("foo"))); final String value = defaultValueProvider.defaultValue(OptionSpec.builder("--logging").build()); assertThat(value).isEqualTo("ERROR"); }
Example #4
Source File: ConfigOptionSearchAndRunHandlerTest.java From besu with Apache License 2.0 | 5 votes |
@Test public void shouldRetrieveConfigFromEnvironmentWhenConfigFileNotSpecified() throws Exception { final IDefaultValueProvider defaultValueProvider = configParsingHandler.createDefaultValueProvider(mockCommandLine, Optional.empty()); final String value = defaultValueProvider.defaultValue(OptionSpec.builder("--logging").build()); assertThat(value).isEqualTo("ERROR"); }
Example #5
Source File: DefaultProviderTest.java From picocli with Apache License 2.0 | 5 votes |
@SuppressWarnings("unchecked") @Test(expected = UnsupportedOperationException.class) public void testNoDefaultProviderThrowsUnsupportedOperation() throws Exception { Class<IDefaultValueProvider> c = (Class<IDefaultValueProvider>) Class.forName("picocli.CommandLine$NoDefaultProvider"); IDefaultValueProvider provider = CommandLine.defaultFactory().create(c); assertNotNull(provider); provider.defaultValue(CommandLine.Model.PositionalParamSpec.builder().build()); }
Example #6
Source File: DefaultProviderTest.java From picocli with Apache License 2.0 | 5 votes |
@Test public void testDefaultValueInDescriptionAfterSetProvider() { String expected2 = String.format("" + "Usage: <main class> [OPTIONS] [<paramStringFieldWithoutDefaultNorInitialValue>] [<paramStringFieldWithAnnotatedDefault>] [<paramStringFieldWithInitDefault>]%n" + " [<paramStringFieldWithoutDefaultNorInitialValue>]%n" + " Default: XYZ%n" + " Default: XYZ%n" + " [<paramStringFieldWithAnnotatedDefault>]%n" + " Default: XYZ%n" + " [<paramStringFieldWithInitDefault>]%n" + " Default: XYZ%n" + " -a=<optionStringFieldWithoutDefaultNorInitialValue>%n" + " Default: XYZ%n" + " -b=<optionStringFieldWithAnnotatedDefault>%n" + " Default: XYZ%n" + " -c=<optionStringFieldWithInitDefault>%n" + " Default: XYZ%n" + " Default: XYZ%n" + " -d=<string> Default: XYZ%n"); CommandLine cmd = new CommandLine(App.class); cmd.setDefaultValueProvider(new IDefaultValueProvider() { public String defaultValue(ArgSpec argSpec) throws Exception { return "XYZ"; } }); assertEquals(expected2, cmd.getUsageMessage(CommandLine.Help.Ansi.OFF)); }
Example #7
Source File: DefaultProviderTest.java From picocli with Apache License 2.0 | 5 votes |
@Test public void testDefaultValueInDescriptionWithErrorProvider() { String expected2 = String.format("" + "Usage: <main class> [OPTIONS] [<paramStringFieldWithoutDefaultNorInitialValue>] [<paramStringFieldWithAnnotatedDefault>] [<paramStringFieldWithInitDefault>]%n" + " [<paramStringFieldWithoutDefaultNorInitialValue>]%n" + " Default: null%n" + " Default: null%n" + " [<paramStringFieldWithAnnotatedDefault>]%n" + " Default: Annotated default value%n" + " [<paramStringFieldWithInitDefault>]%n" + " Default: Initial default value%n" + " -a=<optionStringFieldWithoutDefaultNorInitialValue>%n" + " Default: null%n" + " -b=<optionStringFieldWithAnnotatedDefault>%n" + " Default: Annotated default value%n" + " -c=<optionStringFieldWithInitDefault>%n" + " Default: Initial default value%n" + " Default: Initial default value%n" + " -d=<string> Default: Annotated setter default value%n"); CommandLine cmd = new CommandLine(App.class); cmd.setDefaultValueProvider(new IDefaultValueProvider() { public String defaultValue(ArgSpec argSpec) throws Exception { throw new IllegalStateException("abc"); } }); assertEquals(expected2, cmd.getUsageMessage(CommandLine.Help.Ansi.OFF)); }
Example #8
Source File: CascadingDefaultProvider.java From besu with Apache License 2.0 | 4 votes |
public CascadingDefaultProvider(final IDefaultValueProvider... defaultValueProviders) { this.defaultValueProviders = asList(defaultValueProviders); }
Example #9
Source File: CascadingDefaultProvider.java From teku with Apache License 2.0 | 4 votes |
public CascadingDefaultProvider(final IDefaultValueProvider... defaultValueProviders) { this.defaultValueProviders = asList(defaultValueProviders); }