Skip to content

Commit

Permalink
Fix parameters on cli and bump kotlinx.cli
Browse files Browse the repository at this point in the history
  • Loading branch information
MarcinAman committed Feb 23, 2021
1 parent e07f411 commit 08e6478
Show file tree
Hide file tree
Showing 5 changed files with 74 additions and 11 deletions.
2 changes: 1 addition & 1 deletion docs/src/doc/docs/user_guide/cli/usage.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ Dokka supports the following command line arguments:
* `-includeNonPublic` - include protected and private code
* `-skipDeprecated` - if set, deprecated elements are not included in the generated documentation
* `-reportUndocumented` - warn about undocumented members
* `-skipEmptyPackages` - do not create index pages for empty packages
* `-noSkipEmptyPackages` - create index pages for empty packages
* `-packageOptions` - list of package options in format `matchingRegex,-deprecated,-privateApi,+reportUndocumented;matchingRegex, ...`, separated by `;`
* `-links` - list of external documentation links in format `url^packageListUrl^^url2...`, separated by `;`
* `-srcLink` - mapping between a source directory and a Web site for browsing the code in format `<path>=<url>[#lineSuffix]`
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
package emptypackagetest
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,7 @@ package org.jetbrains.dokka.it.cli

import org.jetbrains.dokka.it.awaitProcessResult
import java.io.File
import kotlin.test.BeforeTest
import kotlin.test.Test
import kotlin.test.assertEquals
import kotlin.test.assertTrue
import kotlin.test.*

class CliIntegrationTest : AbstractCliIntegrationTest() {

Expand Down Expand Up @@ -86,5 +83,68 @@ class CliIntegrationTest : AbstractCliIntegrationTest() {
assertNoEmptyLinks(file)
assertNoEmptySpans(file)
}

assertFalse(
projectDir.resolve("output").resolve("index.html").readText().contains("emptypackagetest"),
"Expected not to render empty packages"
)
}

@Test
fun failCli() {
val dokkaOutputDir = File(projectDir, "output")
assertTrue(dokkaOutputDir.mkdirs())
val process = ProcessBuilder(
"java", "-jar", cliJarFile.path,
"-outputDir", dokkaOutputDir.path,
"-pluginsClasspath", basePluginJarFile.path,
"-moduleName", "Basic Project",
"-failOnWarning",
"-sourceSet",
buildString {
append(" -sourceSetName cliMain")
append(" -src ${File(projectDir, "src").path}")
append(" -jdkVersion 8")
append(" -analysisPlatform jvm")
append(" -reportUndocumented")
}
)
.redirectErrorStream(true)
.start()

val result = process.awaitProcessResult()
assertEquals(1, result.exitCode, "Expected exitCode 1 (Fail)")

assertTrue(result.output.contains("Exception in thread \"main\" org.jetbrains.dokka.DokkaException: Failed with warningCount"))
}

@Test
fun emptyPackagesTest() {
val dokkaOutputDir = File(projectDir, "output")
assertTrue(dokkaOutputDir.mkdirs())
val process = ProcessBuilder(
"java", "-jar", cliJarFile.path,
"-outputDir", dokkaOutputDir.path,
"-pluginsClasspath", basePluginJarFile.path,
"-moduleName", "Basic Project",
"-sourceSet",
buildString {
append(" -sourceSetName cliMain")
append(" -src ${File(projectDir, "src").path}")
append(" -jdkVersion 8")
append(" -analysisPlatform jvm")
append(" -noSkipEmptyPackages")
}
)
.redirectErrorStream(true)
.start()

val result = process.awaitProcessResult()
assertEquals(0, result.exitCode, "Expected exitCode 0 (Success)")

assertTrue(
projectDir.resolve("output").resolve("index.html").readText().contains("emptypackagetest"),
"Expected to render empty packages"
)
}
}
2 changes: 1 addition & 1 deletion runners/cli/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ repositories {
}

dependencies {
implementation("org.jetbrains.kotlinx:kotlinx-cli-jvm:0.2.1")
implementation("org.jetbrains.kotlinx:kotlinx-cli-jvm:0.3.1")
implementation(project(":core"))
implementation(kotlin("stdlib"))
}
Expand Down
12 changes: 7 additions & 5 deletions runners/cli/src/main/kotlin/cli/main.kt
Original file line number Diff line number Diff line change
Expand Up @@ -56,12 +56,12 @@ class GlobalArguments(args: Array<String>) : DokkaConfiguration {

override val offlineMode by parser.option(
ArgType.Boolean,
"Offline mode (do not download package lists from the Internet)"
description = "Offline mode (do not download package lists from the Internet)"
).default(DokkaDefaults.offlineMode)

override val failOnWarning by parser.option(
ArgType.Boolean,
"Throw an exception if the generation exited with warnings"
description = "Throw an exception if the generation exited with warnings"
).default(DokkaDefaults.failOnWarning)

override val delayTemplateSubstitution by parser.option(
Expand Down Expand Up @@ -166,10 +166,12 @@ private fun parseSourceSet(moduleName: String, args: Array<String>): DokkaConfig
val reportUndocumented by parser.option(ArgType.Boolean, description = "Report undocumented members")
.default(DokkaDefaults.reportUndocumented)

val skipEmptyPackages by parser.option(
val noSkipEmptyPackages by parser.option(
ArgType.Boolean,
description = "Do not create index pages for empty packages"
).default(DokkaDefaults.skipEmptyPackages)
description = "Create index pages for empty packages"
).default(!DokkaDefaults.skipEmptyPackages)

val skipEmptyPackages by lazy { !noSkipEmptyPackages }

val skipDeprecated by parser.option(ArgType.Boolean, description = "Do not output deprecated members")
.default(DokkaDefaults.skipDeprecated)
Expand Down

0 comments on commit 08e6478

Please sign in to comment.