Search in sources :

Example 6 with UnparsedOptionValueDescription

use of com.google.devtools.common.options.OptionsParser.UnparsedOptionValueDescription in project bazel by bazelbuild.

the class OptionsUtils method asShellEscapedString.

/**
   * Returns a string representation of the non-hidden specified options; option values are
   * shell-escaped.
   */
public static String asShellEscapedString(Iterable<UnparsedOptionValueDescription> optionsList) {
    StringBuilder result = new StringBuilder();
    for (UnparsedOptionValueDescription option : optionsList) {
        if (option.isHidden()) {
            continue;
        }
        if (result.length() != 0) {
            result.append(' ');
        }
        String value = option.getUnparsedValue();
        if (option.isBooleanOption()) {
            boolean isEnabled = false;
            try {
                isEnabled = new Converters.BooleanConverter().convert(value);
            } catch (OptionsParsingException e) {
                throw new RuntimeException("Unexpected parsing exception", e);
            }
            result.append(isEnabled ? "--" : "--no").append(option.getName());
        } else {
            result.append("--").append(option.getName());
            if (value != null) {
                // Can be null for Void options.
                result.append("=").append(ShellEscaper.escapeString(value));
            }
        }
    }
    return result.toString();
}
Also used : UnparsedOptionValueDescription(com.google.devtools.common.options.OptionsParser.UnparsedOptionValueDescription) OptionsParsingException(com.google.devtools.common.options.OptionsParsingException)

Aggregations

UnparsedOptionValueDescription (com.google.devtools.common.options.OptionsParser.UnparsedOptionValueDescription)6 OptionsParser.newOptionsParser (com.google.devtools.common.options.OptionsParser.newOptionsParser)2 Test (org.junit.Test)2 ImmutableList (com.google.common.collect.ImmutableList)1 Subscribe (com.google.common.eventbus.Subscribe)1 BuildData (com.google.devtools.build.lib.bazel.dash.DashProtos.BuildData)1 OptionsParsingException (com.google.devtools.common.options.OptionsParsingException)1 ByteString (com.google.protobuf.ByteString)1 Field (java.lang.reflect.Field)1 LinkedHashMap (java.util.LinkedHashMap)1 List (java.util.List)1 Map (java.util.Map)1