Do not print usage if wrong argument is passed, do not exit with INTERNAL_ERROR
This is a normal situation, not an internal error of the compiler, so return COMPILATION_ERROR instead
This commit is contained in:
@@ -65,20 +65,19 @@ public abstract class CLICompiler<A extends CommonCompilerArguments> {
|
||||
}
|
||||
|
||||
@Nullable
|
||||
private A parseArguments(@NotNull PrintStream errStream, @NotNull MessageRenderer messageRenderer, @NotNull String[] args) {
|
||||
private A parseArguments(@NotNull MessageCollector messageCollector, @NotNull String[] args) {
|
||||
try {
|
||||
A arguments = createArguments();
|
||||
parseArguments(args, arguments);
|
||||
return arguments;
|
||||
}
|
||||
catch (IllegalArgumentException e) {
|
||||
errStream.println(e.getMessage());
|
||||
Usage.print(errStream, createArguments(), false);
|
||||
throw e;
|
||||
}
|
||||
catch (Throwable t) {
|
||||
errStream.println(messageRenderer.render(EXCEPTION, OutputMessageUtil.renderException(t), null));
|
||||
messageCollector.report(EXCEPTION, OutputMessageUtil.renderException(t), null);
|
||||
return null;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
// Used in kotlin-maven-plugin (KotlinCompileMojoBase) and in kotlin-gradle-plugin (KotlinJvmOptionsImpl, KotlinJsOptionsImpl)
|
||||
@@ -98,13 +97,20 @@ public abstract class CLICompiler<A extends CommonCompilerArguments> {
|
||||
) {
|
||||
K2JVMCompiler.Companion.resetInitStartTime();
|
||||
|
||||
A arguments = parseArguments(errStream, messageRenderer, args);
|
||||
if (arguments == null) {
|
||||
return INTERNAL_ERROR;
|
||||
MessageCollector parseArgumentsCollector = new PrintingMessageCollector(errStream, messageRenderer, false);
|
||||
A arguments;
|
||||
try {
|
||||
arguments = parseArguments(parseArgumentsCollector, args);
|
||||
if (arguments == null) return INTERNAL_ERROR;
|
||||
}
|
||||
catch (IllegalArgumentException e) {
|
||||
parseArgumentsCollector.report(ERROR, e.getMessage(), null);
|
||||
parseArgumentsCollector.report(INFO, "Use -help for more information", null);
|
||||
return COMPILATION_ERROR;
|
||||
}
|
||||
|
||||
if (arguments.help || arguments.extraHelp) {
|
||||
Usage.print(errStream, createArguments(), arguments.extraHelp);
|
||||
Usage.print(errStream, arguments);
|
||||
return OK;
|
||||
}
|
||||
|
||||
|
||||
@@ -29,19 +29,19 @@ class Usage {
|
||||
// The magic number 29 corresponds to the similar padding width in javac and scalac command line compilers
|
||||
private static final int OPTION_NAME_PADDING_WIDTH = 29;
|
||||
|
||||
public static void print(@NotNull PrintStream target, @NotNull CommonCompilerArguments arguments, boolean extraHelp) {
|
||||
public static void print(@NotNull PrintStream target, @NotNull CommonCompilerArguments arguments) {
|
||||
target.println("Usage: " + arguments.executableScriptFileName() + " <options> <source files>");
|
||||
target.println("where " + (extraHelp ? "advanced" : "possible") + " options include:");
|
||||
target.println("where " + (arguments.extraHelp ? "advanced" : "possible") + " options include:");
|
||||
for (Class<?> clazz = arguments.getClass(); clazz != null; clazz = clazz.getSuperclass()) {
|
||||
for (Field field : clazz.getDeclaredFields()) {
|
||||
String usage = fieldUsage(field, extraHelp);
|
||||
String usage = fieldUsage(field, arguments.extraHelp);
|
||||
if (usage != null) {
|
||||
target.println(usage);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (extraHelp) {
|
||||
if (arguments.extraHelp) {
|
||||
target.println();
|
||||
target.println("Advanced options are non-standard and may be changed or removed without any notice.");
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user