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();
}
Aggregations