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
|
@Nullable
|
||||||
private A parseArguments(@NotNull PrintStream errStream, @NotNull MessageRenderer messageRenderer, @NotNull String[] args) {
|
private A parseArguments(@NotNull MessageCollector messageCollector, @NotNull String[] args) {
|
||||||
try {
|
try {
|
||||||
A arguments = createArguments();
|
A arguments = createArguments();
|
||||||
parseArguments(args, arguments);
|
parseArguments(args, arguments);
|
||||||
return arguments;
|
return arguments;
|
||||||
}
|
}
|
||||||
catch (IllegalArgumentException e) {
|
catch (IllegalArgumentException e) {
|
||||||
errStream.println(e.getMessage());
|
throw e;
|
||||||
Usage.print(errStream, createArguments(), false);
|
|
||||||
}
|
}
|
||||||
catch (Throwable t) {
|
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)
|
// 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();
|
K2JVMCompiler.Companion.resetInitStartTime();
|
||||||
|
|
||||||
A arguments = parseArguments(errStream, messageRenderer, args);
|
MessageCollector parseArgumentsCollector = new PrintingMessageCollector(errStream, messageRenderer, false);
|
||||||
if (arguments == null) {
|
A arguments;
|
||||||
return INTERNAL_ERROR;
|
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) {
|
if (arguments.help || arguments.extraHelp) {
|
||||||
Usage.print(errStream, createArguments(), arguments.extraHelp);
|
Usage.print(errStream, arguments);
|
||||||
return OK;
|
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
|
// 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;
|
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("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 (Class<?> clazz = arguments.getClass(); clazz != null; clazz = clazz.getSuperclass()) {
|
||||||
for (Field field : clazz.getDeclaredFields()) {
|
for (Field field : clazz.getDeclaredFields()) {
|
||||||
String usage = fieldUsage(field, extraHelp);
|
String usage = fieldUsage(field, arguments.extraHelp);
|
||||||
if (usage != null) {
|
if (usage != null) {
|
||||||
target.println(usage);
|
target.println(usage);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (extraHelp) {
|
if (arguments.extraHelp) {
|
||||||
target.println();
|
target.println();
|
||||||
target.println("Advanced options are non-standard and may be changed or removed without any notice.");
|
target.println("Advanced options are non-standard and may be changed or removed without any notice.");
|
||||||
}
|
}
|
||||||
|
|||||||
+3
-28
@@ -1,28 +1,3 @@
|
|||||||
Invalid argument: -wrong-argument
|
error: invalid argument: -wrong-argument
|
||||||
Usage: kotlinc-jvm <options> <source files>
|
info: use -help for more information
|
||||||
where possible options include:
|
COMPILATION_ERROR
|
||||||
-d <directory|jar> Destination for generated class files
|
|
||||||
-classpath (-cp) <path> Paths where to find user class files
|
|
||||||
-include-runtime Include Kotlin runtime in to resulting .jar
|
|
||||||
-jdk-home <path> Path to JDK home directory to include into classpath, if differs from default JAVA_HOME
|
|
||||||
-no-jdk Don't include Java runtime into classpath
|
|
||||||
-no-stdlib Don't include Kotlin runtime into classpath
|
|
||||||
-no-reflect Don't include Kotlin reflection implementation into classpath
|
|
||||||
-module <path> Path to the module file to compile
|
|
||||||
-script Evaluate the script file
|
|
||||||
-script-templates <fully qualified class name[,]>
|
|
||||||
Script definition template classes
|
|
||||||
-kotlin-home <path> Path to Kotlin compiler home directory, used for runtime libraries discovery
|
|
||||||
-module-name Module name
|
|
||||||
-jvm-target <version> Target version of the generated JVM bytecode (1.6 or 1.8), default is 1.6
|
|
||||||
-java-parameters Generate metadata for Java 1.8 reflection on method parameters
|
|
||||||
-language-version <version> Provide source compatibility with specified language version
|
|
||||||
-api-version <version> Allow to use declarations only from the specified version of bundled libraries
|
|
||||||
-nowarn Generate no warnings
|
|
||||||
-verbose Enable verbose logging output
|
|
||||||
-version Display compiler version
|
|
||||||
-help (-h) Print a synopsis of standard options
|
|
||||||
-X Print a synopsis of advanced options
|
|
||||||
-P plugin:<pluginId>:<optionName>=<value>
|
|
||||||
Pass an option to a plugin
|
|
||||||
INTERNAL_ERROR
|
|
||||||
Reference in New Issue
Block a user