Beautify kotlinc -help output

This commit is contained in:
Alexander Udalov
2014-06-23 16:46:21 +04:00
parent 5e994778d1
commit ca219f9880
11 changed files with 226 additions and 192 deletions
@@ -18,8 +18,10 @@ package org.jetbrains.jet.cli.common.arguments;
import com.intellij.util.SmartList;
import com.sampullara.cli.Argument;
import org.jetbrains.annotations.NotNull;
import java.util.List;
import static org.jetbrains.jet.cli.common.arguments.CommonArgumentConstants.SUPPRESS_WARNINGS;
public abstract class CommonCompilerArguments {
@@ -35,7 +37,8 @@ public abstract class CommonCompilerArguments {
@Argument(value = "help", alias = "h", description = "Print a synopsis of standard options")
public boolean help;
@Argument(value = "suppress", description = "Suppress compiler messages by severity (" + SUPPRESS_WARNINGS + ")")
@Argument(value = "suppress", description = "Suppress all compiler warnings")
@ValueDescription(SUPPRESS_WARNINGS)
public String suppress;
@Argument(value = "printArgs", description = "Print command line arguments")
@@ -47,6 +50,11 @@ public abstract class CommonCompilerArguments {
return SUPPRESS_WARNINGS.equalsIgnoreCase(suppress);
}
@NotNull
public String executableScriptFileName() {
return "kotlinc";
}
// Used only for serialize and deserialize settings. Don't use in other places!
public static final class DummyImpl extends CommonCompilerArguments {}
}
@@ -17,6 +17,7 @@
package org.jetbrains.jet.cli.common.arguments;
import com.sampullara.cli.Argument;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import static org.jetbrains.jet.cli.common.arguments.K2JsArgumentConstants.CALL;
@@ -27,28 +28,40 @@ import static org.jetbrains.jet.cli.common.arguments.K2JsArgumentConstants.NO_CA
*/
public class K2JSCompilerArguments extends CommonCompilerArguments {
@Argument(value = "output", description = "Output file path")
@ValueDescription("<path>")
public String outputFile;
@Argument(value = "libraryFiles", description = "Path to zipped lib sources or kotlin files")
@Argument(value = "libraryFiles", description = "Path to zipped library sources or kotlin files separated by commas")
@ValueDescription("<path[,]>")
public String[] libraryFiles;
@Argument(value = "sourceFiles", description = "Source files (dir or file)")
@Argument(value = "sourceFiles", description = "Source files or directories separated by commas")
@ValueDescription("<path[,]>")
public String[] sourceFiles;
@Argument(value = "sourcemap", description = "Generate SourceMap")
public boolean sourcemap;
@Argument(value = "target", description = "Generate JS files for specific ECMA version (only ECMA 5 is supported)")
@ValueDescription("<version>")
public String target;
@Nullable
@Argument(value = "main", description = "Whether a main function should be called; either '" + CALL +
"' or '" + NO_CALL + "', default '" + CALL + "' (main function will be auto detected)")
@Argument(value = "main", description = "Whether a main function should be called; default '" + CALL + "' (main function will be auto detected)")
@ValueDescription("{" + CALL + "," + NO_CALL + "}")
public String main;
@Argument(value = "outputPrefix", description = "Path to file which will be added to the beginning of output file")
@ValueDescription("<path>")
public String outputPrefix;
@Argument(value = "outputPostfix", description = "Path to file which will be added to the end of output file")
@ValueDescription("<path>")
public String outputPostfix;
@Override
@NotNull
public String executableScriptFileName() {
return "kotlinc-js";
}
}
@@ -19,6 +19,7 @@
package org.jetbrains.jet.cli.common.arguments;
import com.sampullara.cli.Argument;
import org.jetbrains.annotations.NotNull;
/**
* Command line arguments for K2JVMCompiler
@@ -26,18 +27,23 @@ import com.sampullara.cli.Argument;
@SuppressWarnings("UnusedDeclaration")
public class K2JVMCompilerArguments extends CommonCompilerArguments {
@Argument(value = "src", description = "Source file or directory (allows many paths separated by the system path separator)")
@ValueDescription("<path>")
public String src;
@Argument(value = "jar", description = "Resulting .jar file path")
@ValueDescription("<path>")
public String jar;
@Argument(value = "output", description = "Output directory path for .class files")
@ValueDescription("<path>")
public String outputDir;
@Argument(value = "classpath", description = "Paths where to find user class files")
@ValueDescription("<path>")
public String classpath;
@Argument(value = "annotations", description = "Paths to external annotations")
@ValueDescription("<path>")
public String annotations;
@Argument(value = "includeRuntime", description = "Include Kotlin runtime in to resulting .jar")
@@ -59,14 +65,23 @@ public class K2JVMCompilerArguments extends CommonCompilerArguments {
public boolean notNullParamAssertions;
@Argument(value = "module", description = "Path to the module file to compile")
@ValueDescription("<path>")
public String module;
@Argument(value = "script", description = "Evaluate the script file")
public boolean script;
@Argument(value = "kotlinHome", description = "Path to Kotlin compiler home directory, used for annotations and runtime libraries discovery")
@ValueDescription("<path>")
public String kotlinHome;
@Argument(value = "inline", description = "Inlining mode: on/off (default is on)")
@Argument(value = "inline", description = "Inlining mode (default is on)")
@ValueDescription("{on,off}")
public String inline;
@Override
@NotNull
public String executableScriptFileName() {
return "kotlinc-jvm";
}
}
@@ -0,0 +1,28 @@
/*
* Copyright 2010-2014 JetBrains s.r.o.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.jetbrains.jet.cli.common.arguments;
import org.jetbrains.annotations.NotNull;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
@Retention(RetentionPolicy.RUNTIME)
public @interface ValueDescription {
@NotNull
String value();
}
@@ -20,94 +20,58 @@ import com.sampullara.cli.Argument;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import org.jetbrains.jet.cli.common.arguments.CommonCompilerArguments;
import org.jetbrains.jet.cli.common.arguments.ValueDescription;
import java.io.PrintStream;
import java.lang.reflect.Array;
import java.lang.reflect.Field;
import java.util.ArrayList;
import java.util.List;
class Usage {
private final PrintStream out;
private Usage(@NotNull PrintStream out) {
this.out = out;
}
// 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) {
new Usage(target).print(arguments);
}
private void print(@NotNull CommonCompilerArguments arguments) {
Class<?> clazz = arguments.getClass();
out.println("Usage: " + clazz.getName());
for (Class<?> currentClass = clazz; currentClass != null; currentClass = currentClass.getSuperclass()) {
for (Field field : currentClass.getDeclaredFields()) {
Argument argument = field.getAnnotation(Argument.class);
if (argument == null) continue;
try {
printFieldUsage(field, field.get(arguments), argument);
}
catch (IllegalAccessException e) {
throw new IllegalArgumentException("Could not use the field " + field + " as an argument field", e);
target.println("Usage: " + arguments.executableScriptFileName() + " <options> <source files>");
target.println("where possible options include:");
for (Class<?> clazz = arguments.getClass(); clazz != null; clazz = clazz.getSuperclass()) {
for (Field field : clazz.getDeclaredFields()) {
String usage = fieldUsage(field);
if (usage != null) {
target.println(usage);
}
}
}
}
private void printFieldUsage(@NotNull Field field, @Nullable Object defaultValue, @NotNull Argument argument) {
@Nullable
private static String fieldUsage(@NotNull Field field) {
Argument argument = field.getAnnotation(Argument.class);
if (argument == null) return null;
ValueDescription description = field.getAnnotation(ValueDescription.class);
String prefix = argument.prefix();
Class<?> type = field.getType();
String description = argument.description();
StringBuilder sb = new StringBuilder(" ");
sb.append(prefix);
if (argument.value().equals("")) {
if (argument.value().isEmpty()) {
sb.append(field.getName());
}
else {
sb.append(argument.value());
}
if (!argument.alias().equals("")) {
if (!argument.alias().isEmpty()) {
sb.append(" (");
sb.append(prefix);
sb.append(argument.alias());
sb.append(")");
}
if (type == Boolean.TYPE || type == Boolean.class) {
sb.append(" [flag] ");
sb.append(description);
if (description != null) {
sb.append(" ");
sb.append(description.value());
}
else {
sb.append(" [");
if (type.isArray()) {
sb.append(type.getComponentType().getSimpleName());
sb.append("[");
sb.append(argument.delimiter());
sb.append("]");
}
else {
sb.append(type.getSimpleName());
}
sb.append("] ");
sb.append(description);
if (defaultValue != null) {
sb.append(" (");
if (type.isArray()) {
int len = Array.getLength(defaultValue);
List<Object> list = new ArrayList<Object>(len);
for (int i = 0; i < len; i++) {
list.add(Array.get(defaultValue, i));
}
sb.append(list);
}
else {
sb.append(defaultValue);
}
sb.append(")");
}
while (sb.length() < OPTION_NAME_PADDING_WIDTH) {
sb.append(" ");
}
out.println(sb);
sb.append(argument.description());
return sb.toString();
}
}
+16 -15
View File
@@ -1,16 +1,17 @@
Usage: org.jetbrains.jet.cli.common.arguments.K2JSCompilerArguments
-output [String] Output file path
-libraryFiles [String[,]] Path to zipped lib sources or kotlin files
-sourceFiles [String[,]] Source files (dir or file)
-sourcemap [flag] Generate SourceMap
-target [String] Generate JS files for specific ECMA version (only ECMA 5 is supported)
-main [String] Whether a main function should be called; either 'call' or 'noCall', default 'call' (main function will be auto detected)
-outputPrefix [String] Path to file which will be added to the beginning of output file
-outputPostfix [String] Path to file which will be added to the end of output file
-tags [flag] Demarcate each compilation message (error, warning, etc) with an open and close tag
-verbose [flag] Enable verbose logging output
-version [flag] Display compiler version
-help (-h) [flag] Print a synopsis of standard options
-suppress [String] Suppress compiler messages by severity (warnings)
-printArgs [flag] Print command line arguments
Usage: kotlinc-js <options> <source files>
where possible options include:
-output <path> Output file path
-libraryFiles <path[,]> Path to zipped library sources or kotlin files separated by commas
-sourceFiles <path[,]> Source files or directories separated by commas
-sourcemap Generate SourceMap
-target <version> Generate JS files for specific ECMA version (only ECMA 5 is supported)
-main {call,noCall} Whether a main function should be called; default 'call' (main function will be auto detected)
-outputPrefix <path> Path to file which will be added to the beginning of output file
-outputPostfix <path> Path to file which will be added to the end of output file
-tags Demarcate each compilation message (error, warning, etc) with an open and close tag
-verbose Enable verbose logging output
-version Display compiler version
-help (-h) Print a synopsis of standard options
-suppress warnings Suppress all compiler warnings
-printArgs Print command line arguments
OK
+23 -22
View File
@@ -1,23 +1,24 @@
Usage: org.jetbrains.jet.cli.common.arguments.K2JVMCompilerArguments
-src [String] Source file or directory (allows many paths separated by the system path separator)
-jar [String] Resulting .jar file path
-output [String] Output directory path for .class files
-classpath [String] Paths where to find user class files
-annotations [String] Paths to external annotations
-includeRuntime [flag] Include Kotlin runtime in to resulting .jar
-noJdk [flag] Don't include Java runtime into classpath
-noStdlib [flag] Don't include Kotlin runtime into classpath
-noJdkAnnotations [flag] Don't include JDK external annotations into classpath
-notNullAssertions [flag] Generate not-null assertion after each invocation of method returning not-null
-notNullParamAssertions [flag] Generate not-null assertions on parameters of methods accessible from Java
-module [String] Path to the module file to compile
-script [flag] Evaluate the script file
-kotlinHome [String] Path to Kotlin compiler home directory, used for annotations and runtime libraries discovery
-inline [String] Inlining mode: on/off (default is on)
-tags [flag] Demarcate each compilation message (error, warning, etc) with an open and close tag
-verbose [flag] Enable verbose logging output
-version [flag] Display compiler version
-help (-h) [flag] Print a synopsis of standard options
-suppress [String] Suppress compiler messages by severity (warnings)
-printArgs [flag] Print command line arguments
Usage: kotlinc-jvm <options> <source files>
where possible options include:
-src <path> Source file or directory (allows many paths separated by the system path separator)
-jar <path> Resulting .jar file path
-output <path> Output directory path for .class files
-classpath <path> Paths where to find user class files
-annotations <path> Paths to external annotations
-includeRuntime Include Kotlin runtime in to resulting .jar
-noJdk Don't include Java runtime into classpath
-noStdlib Don't include Kotlin runtime into classpath
-noJdkAnnotations Don't include JDK external annotations into classpath
-notNullAssertions Generate not-null assertion after each invocation of method returning not-null
-notNullParamAssertions Generate not-null assertions on parameters of methods accessible from Java
-module <path> Path to the module file to compile
-script Evaluate the script file
-kotlinHome <path> Path to Kotlin compiler home directory, used for annotations and runtime libraries discovery
-inline {on,off} Inlining mode (default is on)
-tags Demarcate each compilation message (error, warning, etc) with an open and close tag
-verbose Enable verbose logging output
-version Display compiler version
-help (-h) Print a synopsis of standard options
-suppress warnings Suppress all compiler warnings
-printArgs Print command line arguments
OK
+23 -22
View File
@@ -1,23 +1,24 @@
Usage: org.jetbrains.jet.cli.common.arguments.K2JVMCompilerArguments
-src [String] Source file or directory (allows many paths separated by the system path separator)
-jar [String] Resulting .jar file path
-output [String] Output directory path for .class files
-classpath [String] Paths where to find user class files
-annotations [String] Paths to external annotations
-includeRuntime [flag] Include Kotlin runtime in to resulting .jar
-noJdk [flag] Don't include Java runtime into classpath
-noStdlib [flag] Don't include Kotlin runtime into classpath
-noJdkAnnotations [flag] Don't include JDK external annotations into classpath
-notNullAssertions [flag] Generate not-null assertion after each invocation of method returning not-null
-notNullParamAssertions [flag] Generate not-null assertions on parameters of methods accessible from Java
-module [String] Path to the module file to compile
-script [flag] Evaluate the script file
-kotlinHome [String] Path to Kotlin compiler home directory, used for annotations and runtime libraries discovery
-inline [String] Inlining mode: on/off (default is on)
-tags [flag] Demarcate each compilation message (error, warning, etc) with an open and close tag
-verbose [flag] Enable verbose logging output
-version [flag] Display compiler version
-help (-h) [flag] Print a synopsis of standard options
-suppress [String] Suppress compiler messages by severity (warnings)
-printArgs [flag] Print command line arguments
Usage: kotlinc-jvm <options> <source files>
where possible options include:
-src <path> Source file or directory (allows many paths separated by the system path separator)
-jar <path> Resulting .jar file path
-output <path> Output directory path for .class files
-classpath <path> Paths where to find user class files
-annotations <path> Paths to external annotations
-includeRuntime Include Kotlin runtime in to resulting .jar
-noJdk Don't include Java runtime into classpath
-noStdlib Don't include Kotlin runtime into classpath
-noJdkAnnotations Don't include JDK external annotations into classpath
-notNullAssertions Generate not-null assertion after each invocation of method returning not-null
-notNullParamAssertions Generate not-null assertions on parameters of methods accessible from Java
-module <path> Path to the module file to compile
-script Evaluate the script file
-kotlinHome <path> Path to Kotlin compiler home directory, used for annotations and runtime libraries discovery
-inline {on,off} Inlining mode (default is on)
-tags Demarcate each compilation message (error, warning, etc) with an open and close tag
-verbose Enable verbose logging output
-version Display compiler version
-help (-h) Print a synopsis of standard options
-suppress warnings Suppress all compiler warnings
-printArgs Print command line arguments
OK
+23 -22
View File
@@ -1,23 +1,24 @@
Usage: org.jetbrains.jet.cli.common.arguments.K2JVMCompilerArguments
-src [String] Source file or directory (allows many paths separated by the system path separator)
-jar [String] Resulting .jar file path
-output [String] Output directory path for .class files
-classpath [String] Paths where to find user class files
-annotations [String] Paths to external annotations
-includeRuntime [flag] Include Kotlin runtime in to resulting .jar
-noJdk [flag] Don't include Java runtime into classpath
-noStdlib [flag] Don't include Kotlin runtime into classpath
-noJdkAnnotations [flag] Don't include JDK external annotations into classpath
-notNullAssertions [flag] Generate not-null assertion after each invocation of method returning not-null
-notNullParamAssertions [flag] Generate not-null assertions on parameters of methods accessible from Java
-module [String] Path to the module file to compile
-script [flag] Evaluate the script file
-kotlinHome [String] Path to Kotlin compiler home directory, used for annotations and runtime libraries discovery
-inline [String] Inlining mode: on/off (default is on)
-tags [flag] Demarcate each compilation message (error, warning, etc) with an open and close tag
-verbose [flag] Enable verbose logging output
-version [flag] Display compiler version
-help (-h) [flag] Print a synopsis of standard options
-suppress [String] Suppress compiler messages by severity (warnings)
-printArgs [flag] Print command line arguments
Usage: kotlinc-jvm <options> <source files>
where possible options include:
-src <path> Source file or directory (allows many paths separated by the system path separator)
-jar <path> Resulting .jar file path
-output <path> Output directory path for .class files
-classpath <path> Paths where to find user class files
-annotations <path> Paths to external annotations
-includeRuntime Include Kotlin runtime in to resulting .jar
-noJdk Don't include Java runtime into classpath
-noStdlib Don't include Kotlin runtime into classpath
-noJdkAnnotations Don't include JDK external annotations into classpath
-notNullAssertions Generate not-null assertion after each invocation of method returning not-null
-notNullParamAssertions Generate not-null assertions on parameters of methods accessible from Java
-module <path> Path to the module file to compile
-script Evaluate the script file
-kotlinHome <path> Path to Kotlin compiler home directory, used for annotations and runtime libraries discovery
-inline {on,off} Inlining mode (default is on)
-tags Demarcate each compilation message (error, warning, etc) with an open and close tag
-verbose Enable verbose logging output
-version Display compiler version
-help (-h) Print a synopsis of standard options
-suppress warnings Suppress all compiler warnings
-printArgs Print command line arguments
OK
+23 -22
View File
@@ -1,24 +1,25 @@
Wrong value for inline option: 'wrong'. Should be 'on'/'off' or 'true'/'false'
Usage: org.jetbrains.jet.cli.common.arguments.K2JVMCompilerArguments
-src [String] Source file or directory (allows many paths separated by the system path separator)
-jar [String] Resulting .jar file path
-output [String] Output directory path for .class files
-classpath [String] Paths where to find user class files
-annotations [String] Paths to external annotations
-includeRuntime [flag] Include Kotlin runtime in to resulting .jar
-noJdk [flag] Don't include Java runtime into classpath
-noStdlib [flag] Don't include Kotlin runtime into classpath
-noJdkAnnotations [flag] Don't include JDK external annotations into classpath
-notNullAssertions [flag] Generate not-null assertion after each invocation of method returning not-null
-notNullParamAssertions [flag] Generate not-null assertions on parameters of methods accessible from Java
-module [String] Path to the module file to compile
-script [flag] Evaluate the script file
-kotlinHome [String] Path to Kotlin compiler home directory, used for annotations and runtime libraries discovery
-inline [String] Inlining mode: on/off (default is on)
-tags [flag] Demarcate each compilation message (error, warning, etc) with an open and close tag
-verbose [flag] Enable verbose logging output
-version [flag] Display compiler version
-help (-h) [flag] Print a synopsis of standard options
-suppress [String] Suppress compiler messages by severity (warnings)
-printArgs [flag] Print command line arguments
Usage: kotlinc-jvm <options> <source files>
where possible options include:
-src <path> Source file or directory (allows many paths separated by the system path separator)
-jar <path> Resulting .jar file path
-output <path> Output directory path for .class files
-classpath <path> Paths where to find user class files
-annotations <path> Paths to external annotations
-includeRuntime Include Kotlin runtime in to resulting .jar
-noJdk Don't include Java runtime into classpath
-noStdlib Don't include Kotlin runtime into classpath
-noJdkAnnotations Don't include JDK external annotations into classpath
-notNullAssertions Generate not-null assertion after each invocation of method returning not-null
-notNullParamAssertions Generate not-null assertions on parameters of methods accessible from Java
-module <path> Path to the module file to compile
-script Evaluate the script file
-kotlinHome <path> Path to Kotlin compiler home directory, used for annotations and runtime libraries discovery
-inline {on,off} Inlining mode (default is on)
-tags Demarcate each compilation message (error, warning, etc) with an open and close tag
-verbose Enable verbose logging output
-version Display compiler version
-help (-h) Print a synopsis of standard options
-suppress warnings Suppress all compiler warnings
-printArgs Print command line arguments
INTERNAL_ERROR
+23 -22
View File
@@ -1,24 +1,25 @@
Invalid argument: -wrongArgument
Usage: org.jetbrains.jet.cli.common.arguments.K2JVMCompilerArguments
-src [String] Source file or directory (allows many paths separated by the system path separator)
-jar [String] Resulting .jar file path
-output [String] Output directory path for .class files
-classpath [String] Paths where to find user class files
-annotations [String] Paths to external annotations
-includeRuntime [flag] Include Kotlin runtime in to resulting .jar
-noJdk [flag] Don't include Java runtime into classpath
-noStdlib [flag] Don't include Kotlin runtime into classpath
-noJdkAnnotations [flag] Don't include JDK external annotations into classpath
-notNullAssertions [flag] Generate not-null assertion after each invocation of method returning not-null
-notNullParamAssertions [flag] Generate not-null assertions on parameters of methods accessible from Java
-module [String] Path to the module file to compile
-script [flag] Evaluate the script file
-kotlinHome [String] Path to Kotlin compiler home directory, used for annotations and runtime libraries discovery
-inline [String] Inlining mode: on/off (default is on)
-tags [flag] Demarcate each compilation message (error, warning, etc) with an open and close tag
-verbose [flag] Enable verbose logging output
-version [flag] Display compiler version
-help (-h) [flag] Print a synopsis of standard options
-suppress [String] Suppress compiler messages by severity (warnings)
-printArgs [flag] Print command line arguments
Usage: kotlinc-jvm <options> <source files>
where possible options include:
-src <path> Source file or directory (allows many paths separated by the system path separator)
-jar <path> Resulting .jar file path
-output <path> Output directory path for .class files
-classpath <path> Paths where to find user class files
-annotations <path> Paths to external annotations
-includeRuntime Include Kotlin runtime in to resulting .jar
-noJdk Don't include Java runtime into classpath
-noStdlib Don't include Kotlin runtime into classpath
-noJdkAnnotations Don't include JDK external annotations into classpath
-notNullAssertions Generate not-null assertion after each invocation of method returning not-null
-notNullParamAssertions Generate not-null assertions on parameters of methods accessible from Java
-module <path> Path to the module file to compile
-script Evaluate the script file
-kotlinHome <path> Path to Kotlin compiler home directory, used for annotations and runtime libraries discovery
-inline {on,off} Inlining mode (default is on)
-tags Demarcate each compilation message (error, warning, etc) with an open and close tag
-verbose Enable verbose logging output
-version Display compiler version
-help (-h) Print a synopsis of standard options
-suppress warnings Suppress all compiler warnings
-printArgs Print command line arguments
INTERNAL_ERROR