Java Code Examples for picocli.CommandLine.Model.CommandSpec#versionProvider()

The following examples show how to use picocli.CommandLine.Model.CommandSpec#versionProvider() . 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: VersionProviderTest.java    From picocli with Apache License 2.0 6 votes vote down vote up
@Test
public void testInitVersionProvider() {
    CommandLine.IVersionProvider versionProvider1 = new CommandLine.IVersionProvider() {
        public String[] getVersion() { return new String[0]; }
    };
    CommandLine.IVersionProvider versionProvider2 = new CommandLine.IVersionProvider() {
        public String[] getVersion() { return new String[0];  }
    };

    CommandSpec spec = CommandSpec.wrapWithoutInspection(null);
    spec.versionProvider(versionProvider1);

    CommandSpec mixin = CommandSpec.wrapWithoutInspection(null);
    mixin.versionProvider(versionProvider2);

    spec.addMixin("helper", mixin);
    assertSame(versionProvider1, spec.versionProvider());
}
 
Example 2
Source File: VersionProviderMetaData.java    From picocli with Apache License 2.0 5 votes vote down vote up
/**
 * Sets the specified {@code CommandSpec}'s
 * {@linkplain CommandSpec#versionProvider(picocli.CommandLine.IVersionProvider)}  version provider}
 * to an {@code VersionProviderMetaData} instance if the annotation attribute was present on the
 * specified {@code Command} annotation.
 *
 * @param result the command spec to initialize
 * @param cmd the {@code @Command} annotation to inspect
 */
public static void initVersionProvider(CommandSpec result, Command cmd) {
    try {
        // this is a hack to get access to the TypeMirror of the version provider class
        cmd.versionProvider();
    } catch (MirroredTypeException ex) {
        VersionProviderMetaData provider = new VersionProviderMetaData(ex.getTypeMirror());
        if (!provider.isDefault()) {
            result.versionProvider(provider);
        }
    }
}