Drop cli-parser, use simple reflection-based parser instead

The main reason of this change is that major changes are required in how
command line arguments are parsed in kotlinc, and it's much easier to
make them in our own codebase (given that the code is short and simple
enough) than in a third-party library
This commit is contained in:
Alexander Udalov
2017-04-05 12:20:29 +03:00
parent 007408c792
commit 78c0111c6e
16 changed files with 225 additions and 857 deletions
@@ -18,9 +18,9 @@ package org.jetbrains.kotlin.cli.common;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import org.jetbrains.kotlin.cli.common.arguments.Argument;
import org.jetbrains.kotlin.cli.common.arguments.CommonCompilerArguments;
import org.jetbrains.kotlin.cli.common.arguments.ValueDescription;
import org.jetbrains.kotlin.cli.common.parser.com.sampullara.cli.Argument;
import org.jetbrains.kotlin.cli.common.arguments.ParseCommandLineArgumentsKt;
import java.io.PrintStream;
import java.lang.reflect.Field;
@@ -59,29 +59,24 @@ class Usage {
Argument argument = field.getAnnotation(Argument.class);
if (argument == null) return null;
ValueDescription description = field.getAnnotation(ValueDescription.class);
String argumentValue = argument.value();
// TODO: this is a dirty hack, provide better mechanism for keys that can have several values
boolean isXCoroutinesKey = argumentValue.contains("Xcoroutines");
String value = isXCoroutinesKey ? "Xcoroutines={enable|warn|error}" : argument.value();
boolean extraOption = value.startsWith("X") && value.length() > 1;
if (extraHelp != extraOption) return null;
String prefix = argument.prefix();
String value = isXCoroutinesKey ? "-Xcoroutines={enable|warn|error}" : argumentValue;
if (extraHelp != ParseCommandLineArgumentsKt.isAdvanced(argument)) return null;
StringBuilder sb = new StringBuilder(" ");
sb.append(prefix);
sb.append(value);
if (!argument.alias().isEmpty()) {
if (!argument.shortName().isEmpty()) {
sb.append(" (");
sb.append(prefix);
sb.append(argument.alias());
sb.append(argument.shortName());
sb.append(")");
}
if (description != null) {
if (!argument.valueDescription().isEmpty()) {
sb.append(" ");
sb.append(description.value());
sb.append(argument.valueDescription());
}
if (isXCoroutinesKey) {