Turn CLI commands into objects, self register subcommands (#935)

Usages of `RootCommand` no longer need to initialize a new instance, nor register subcommands.
This commit is contained in:
Daniel Chao
2025-02-05 09:18:23 -08:00
committed by GitHub
parent aadcccd0fc
commit 9784cd7265
15 changed files with 229 additions and 253 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) }
}
class DocCommand :
object DocCommand :
BaseCommand(name = "pkldoc", helpLink = Release.current().documentation().homepage()) {
private val modules: List<URI> by

View File

@@ -1,5 +1,5 @@
/*
* Copyright © 2024 Apple Inc. and the Pkl project authors. All rights reserved.
* Copyright © 2024-2025 Apple Inc. and the Pkl project authors. All rights reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -21,12 +21,9 @@ import org.junit.jupiter.api.assertThrows
import org.pkl.commons.cli.CliException
class CliMainTest {
private val docCommand = DocCommand()
@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`")
}