Make commands classes instead of objects (#946)

Making these classes caused native-image to statically initialize
them at build time, which included CLI argument default values
(like working dir).

This turns them back into classes.

Co-authored-by: Islon Scherer <islonscherer@gmail.com>
This commit is contained in:
Daniel Chao
2025-02-11 06:38:19 -08:00
committed by GitHub
parent ad99e4a7f7
commit 7ed710c226
13 changed files with 36 additions and 37 deletions

View File

@@ -34,10 +34,10 @@ import org.pkl.core.Release
/** Main method for the Pkldoc CLI. */
internal fun main(args: Array<String>) {
cliMain { DocCommand.main(args) }
cliMain { DocCommand().main(args) }
}
object DocCommand :
class DocCommand :
BaseCommand(name = "pkldoc", helpLink = Release.current().documentation().homepage()) {
private val modules: List<URI> by

View File

@@ -23,7 +23,8 @@ import org.pkl.commons.cli.CliException
class CliMainTest {
@Test
fun `CLI run test`() {
val e = assertThrows<CliException> { DocCommand.parse(arrayOf("foo", "--output-dir", "/tmp")) }
val e =
assertThrows<CliException> { DocCommand().parse(arrayOf("foo", "--output-dir", "/tmp")) }
assertThat(e)
.hasMessageContaining("must contain at least one module named `doc-package-info.pkl`")
}