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

io.redskap.swagger.brake.cli.options.handler.OutputFormatHandler Maven / Gradle / Ivy

There is a newer version: 2.4.0
Show newest version
package io.redskap.swagger.brake.cli.options.handler;

import static java.lang.String.format;
import static java.util.stream.Collectors.toList;

import java.util.Arrays;
import java.util.List;

import io.redskap.swagger.brake.cli.options.CliOptions;
import io.redskap.swagger.brake.runner.Options;
import io.redskap.swagger.brake.runner.OutputFormat;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Component;

@Component
@Slf4j
public class OutputFormatHandler implements CliOptionHandler {
    @Override
    public void handle(String propertyValue, Options options) {
        OutputFormat format = OutputFormat.STDOUT;

        if (!StringUtils.isBlank(propertyValue)) {
            try {
                format = OutputFormat.valueOf(propertyValue.toUpperCase());
            } catch (IllegalArgumentException e) {
                log.debug("Format cannot be resolved", e);
            }
        }

        options.setOutputFormat(format);
    }

    @Override
    public String getHandledPropertyName() {
        return CliOptions.OUTPUT_FORMAT;
    }

    @Override
    public String getHelpMessage() {
        List values = Arrays.stream(OutputFormat.values()).map(Enum::name).map(String::toLowerCase).collect(toList());
        return format("Specifies the output format. Possible values are: %s", StringUtils.join(values, ", "));
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy