All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.tngtech.configbuilder.annotation.valueextractor.CommandLineValueProcessor Maven / Gradle / Ivy

Go to download

The Config Builder creates fully configured instances of config classes, using values from various sources like properties files, command line arguments etc.

There is a newer version: 1.8.1
Show newest version
package com.tngtech.configbuilder.annotation.valueextractor;

import com.tngtech.configbuilder.configuration.BuilderConfiguration;
import com.tngtech.configbuilder.util.ConfigBuilderFactory;
import org.apache.commons.cli.CommandLine;

import java.lang.annotation.Annotation;

/**
 * Processes CommandLineValue annotations, implements ValueExtractorProcessor
 */
public class CommandLineValueProcessor implements ValueExtractorProcessor {

    public String getValue(Annotation annotation, ConfigBuilderFactory configBuilderFactory) {
        CommandLine commandLine = configBuilderFactory.getInstance(BuilderConfiguration.class).getCommandLine();
        CommandLineValue commandLineValue = (CommandLineValue) annotation;
        if (commandLineValue.hasArg()) {
            return commandLine.getOptionValue(commandLineValue.shortOpt());
        } else {
            boolean hasOption = commandLine.hasOption(commandLineValue.shortOpt()) || commandLine.hasOption(commandLineValue.longOpt());
            return String.valueOf(hasOption);
        }
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy