diff options
Diffstat (limited to 'runners/cli/src')
-rw-r--r-- | runners/cli/src/main/kotlin/cli/DokkaArgumentsParser.kt | 17 | ||||
-rw-r--r-- | runners/cli/src/main/kotlin/cli/main.kt | 74 |
2 files changed, 68 insertions, 23 deletions
diff --git a/runners/cli/src/main/kotlin/cli/DokkaArgumentsParser.kt b/runners/cli/src/main/kotlin/cli/DokkaArgumentsParser.kt index 7b8f5fa0..5d795da7 100644 --- a/runners/cli/src/main/kotlin/cli/DokkaArgumentsParser.kt +++ b/runners/cli/src/main/kotlin/cli/DokkaArgumentsParser.kt @@ -3,7 +3,7 @@ package org.jetbrains.dokka import kotlinx.cli.* import kotlin.reflect.KProperty -class ParseContext(private val cli: CommandLineInterface = CommandLineInterface("dokka")) { +class ParseContext(val cli: CommandLineInterface = CommandLineInterface("dokka")) { private val transformActions = mutableMapOf<KProperty<*>, (String) -> Unit>() private val flagActions = mutableMapOf<KProperty<*>, () -> Unit>() @@ -113,10 +113,10 @@ class DokkaArgumentsParser(val args: Array<String>, val parseContext: ParseConte } } - fun <T> parseInto(constructor: (parseContext: DokkaArgumentsParser) -> T): T { - val res = constructor(this) + fun <T> parseInto(dest: T): T { + // TODO: constructor: (DokkaArgumentsParser) -> T parseContext.parse(args) - return res + return dest } fun <T> repeatableOption( @@ -129,7 +129,7 @@ class DokkaArgumentsParser(val args: Array<String>, val parseContext: ParseConte } } - fun <T> repeatableOption( + fun <T : String?> repeatableOption( keys: List<String>, help: String ) = repeatableOption(keys, help) { it as T } @@ -160,7 +160,7 @@ class DokkaArgumentsParser(val args: Array<String>, val parseContext: ParseConte help: String ) = singleFlag(keys, help, { false }, { true }) - fun <T> singleOption( + fun <T : String?> stringOption( keys: List<String>, help: String, defaultValue: T @@ -178,3 +178,8 @@ class DokkaArgumentsParser(val args: Array<String>, val parseContext: ParseConte } } } + + +//`(-perPackage fqName [-include-non-public] [...other flags])*` (edited) +//`(-sourceLink dir url [-urlSuffix value])*` +//`(-extLink url [packageListUrl])*`
\ No newline at end of file diff --git a/runners/cli/src/main/kotlin/cli/main.kt b/runners/cli/src/main/kotlin/cli/main.kt index 0e17c193..655dfde5 100644 --- a/runners/cli/src/main/kotlin/cli/main.kt +++ b/runners/cli/src/main/kotlin/cli/main.kt @@ -1,6 +1,8 @@ package org.jetbrains.dokka +import kotlinx.cli.registerAction import org.jetbrains.dokka.DokkaConfiguration.ExternalDocumentationLink +import org.jetbrains.kotlin.daemon.common.compareDaemonJVMOptionsMemory import java.io.File import java.net.MalformedURLException @@ -8,12 +10,12 @@ import java.net.URL import java.net.URLClassLoader open class GlobalArguments(parser: DokkaArgumentsParser) : DokkaConfiguration { - override val outputDir: String by parser.singleOption( + override val outputDir: String by parser.stringOption( listOf("-output"), "Output directory path", "") - override val format: String by parser.singleOption( + override val format: String by parser.stringOption( listOf("-format"), "Output format (text, html, markdown, jekyll, kotlin-website)", "") @@ -23,7 +25,7 @@ open class GlobalArguments(parser: DokkaArgumentsParser) : DokkaConfiguration { "Generate index page" ) - override val cacheRoot: String? by parser.singleOption( + override val cacheRoot: String? by parser.stringOption( listOf("-cacheRoot"), "Path to cache folder, or 'default' to use ~/.cache/dokka, if not provided caching is disabled", null) @@ -42,7 +44,7 @@ open class GlobalArguments(parser: DokkaArgumentsParser) : DokkaConfiguration { } class Arguments(val parser: DokkaArgumentsParser) : DokkaConfiguration.PassConfiguration { - override val moduleName: String by parser.singleOption( + override val moduleName: String by parser.stringOption( listOf("-module"), "Name of the documentation module", "") @@ -94,12 +96,12 @@ class Arguments(val parser: DokkaArgumentsParser) : DokkaConfiguration.PassConfi { 6 } ) - override val languageVersion: String? by parser.singleOption( + override val languageVersion: String? by parser.stringOption( listOf("-languageVersion"), "Language Version to pass to Kotlin Analysis", null) - override val apiVersion: String? by parser.singleOption( + override val apiVersion: String? by parser.stringOption( listOf("-apiVesion"), "Kotlin Api Version to pass to Kotlin Analysis", null @@ -134,12 +136,13 @@ class Arguments(val parser: DokkaArgumentsParser) : DokkaConfiguration.PassConfi "Generation targets" ) - override val sourceLinks: List<DokkaConfiguration.SourceLinkDefinition> - get() = TODO("not implemented") //To change initializer of created properties use File | Settings | File Templates. - override val perPackageOptions: List<DokkaConfiguration.PackageOptions> - get() = TODO("not implemented") //To change initializer of created properties use File | Settings | File Templates. - override val externalDocumentationLinks: List<DokkaConfiguration.ExternalDocumentationLink> - get() = TODO("not implemented") //To change initializer of created properties use File | Settings | File Templates. + + + override val sourceLinks: MutableList<DokkaConfiguration.SourceLinkDefinition> = mutableListOf() + + override val perPackageOptions: MutableList<DokkaConfiguration.PackageOptions> = mutableListOf() + + override val externalDocumentationLinks: MutableList<DokkaConfiguration.ExternalDocumentationLink> = mutableListOf() } object MainKt { @@ -202,15 +205,52 @@ object MainKt { } } - @JvmStatic - fun main(args: Array<String>) { + fun createConfiguration(args: Array<String>): GlobalArguments { + val parseContext = ParseContext() + val parser = DokkaArgumentsParser(args, parseContext) + + + val configuration = GlobalArguments(parser) + + + parseContext.cli.singleAction( + listOf("-pckageOptions"), + "List of package passConfiguration in format \"prefix,-deprecated,-privateApi,+warnUndocumented,+suppress;...\" " + ) { + configuration.passesConfigurations.last().perPackageOptions.addAll(parsePerPackageOptions(it)) + } + + parseContext.cli.singleAction( + listOf("-links"), + "External documentation links in format url^packageListUrl^^url2..." + ) { + configuration.passesConfigurations.last().externalDocumentationLinks.addAll(MainKt.parseLinks(it)) + } + + parseContext.cli.singleAction( + listOf("-srcLink"), + "Mapping between a source directory and a Web site for browsing the code" + ) { + val newSourceLinks = if (it.isNotEmpty() && it.contains("=")) + listOf(SourceLinkDefinitionImpl.parseSourceLinkDefinition(it)) + else { + if (it.isNotEmpty()) { + println("Warning: Invalid -srcLink syntax. Expected: <path>=<url>[#lineSuffix]. No source links will be generated.") + } + listOf() + } + configuration.passesConfigurations.last().sourceLinks.addAll(newSourceLinks) - val parser = DokkaArgumentsParser(args, ParseContext()) - val parseContext = parser.parseInto(::GlobalArguments) + } - val configuration = parseContext + parser.parseInto(configuration) + return configuration + } + @JvmStatic + fun main(args: Array<String>) { + val configuration = createConfiguration(args) if (configuration.format == "javadoc") startWithToolsJar(configuration) else |