mirror of
https://github.com/apple/pkl.git
synced 2026-03-27 19:41:18 +01:00
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:
@@ -22,5 +22,5 @@ import org.pkl.commons.cli.cliMain
|
||||
|
||||
/** Main method of the Pkl CLI (command-line evaluator and REPL). */
|
||||
internal fun main(args: Array<String>) {
|
||||
cliMain { RootCommand.main(args) }
|
||||
cliMain { RootCommand().main(args) }
|
||||
}
|
||||
|
||||
@@ -25,7 +25,7 @@ import org.pkl.cli.CliImportAnalyzerOptions
|
||||
import org.pkl.commons.cli.commands.ModulesCommand
|
||||
import org.pkl.commons.cli.commands.single
|
||||
|
||||
object AnalyzeCommand :
|
||||
class AnalyzeCommand :
|
||||
NoOpCliktCommand(
|
||||
name = "analyze",
|
||||
help = "Commands related to static analysis",
|
||||
|
||||
@@ -27,7 +27,7 @@ import org.pkl.commons.cli.commands.ProjectOptions
|
||||
import org.pkl.commons.cli.commands.single
|
||||
import org.pkl.core.packages.PackageUri
|
||||
|
||||
object DownloadPackageCommand :
|
||||
class DownloadPackageCommand :
|
||||
BaseCommand(
|
||||
name = "download-package",
|
||||
helpLink = helpLink,
|
||||
|
||||
@@ -24,7 +24,7 @@ import org.pkl.cli.CliEvaluatorOptions
|
||||
import org.pkl.commons.cli.commands.ModulesCommand
|
||||
import org.pkl.commons.cli.commands.single
|
||||
|
||||
object EvalCommand :
|
||||
class EvalCommand :
|
||||
ModulesCommand(name = "eval", help = "Render pkl module(s)", helpLink = helpLink) {
|
||||
private val outputPath: String? by
|
||||
option(
|
||||
|
||||
@@ -33,18 +33,18 @@ import org.pkl.commons.cli.commands.single
|
||||
|
||||
private const val NEWLINE = '\u0085'
|
||||
|
||||
object ProjectCommand :
|
||||
class ProjectCommand :
|
||||
NoOpCliktCommand(
|
||||
name = "project",
|
||||
help = "Run commands related to projects",
|
||||
epilog = "For more information, visit $helpLink",
|
||||
) {
|
||||
init {
|
||||
subcommands(ResolveCommand, PackageCommand)
|
||||
subcommands(ResolveCommand(), PackageCommand())
|
||||
}
|
||||
}
|
||||
|
||||
object ResolveCommand :
|
||||
class ResolveCommand :
|
||||
BaseCommand(
|
||||
name = "resolve",
|
||||
helpLink = helpLink,
|
||||
@@ -74,7 +74,7 @@ object ResolveCommand :
|
||||
}
|
||||
}
|
||||
|
||||
object PackageCommand :
|
||||
class PackageCommand :
|
||||
BaseCommand(
|
||||
name = "package",
|
||||
helpLink = helpLink,
|
||||
|
||||
@@ -21,8 +21,7 @@ import org.pkl.cli.CliRepl
|
||||
import org.pkl.commons.cli.commands.BaseCommand
|
||||
import org.pkl.commons.cli.commands.ProjectOptions
|
||||
|
||||
object ReplCommand :
|
||||
BaseCommand(name = "repl", help = "Start a REPL session", helpLink = helpLink) {
|
||||
class ReplCommand : BaseCommand(name = "repl", help = "Start a REPL session", helpLink = helpLink) {
|
||||
private val projectOptions by ProjectOptions()
|
||||
|
||||
override fun run() {
|
||||
|
||||
@@ -23,7 +23,7 @@ import org.pkl.core.Release
|
||||
|
||||
internal val helpLink = "${Release.current().documentation.homepage}pkl-cli/index.html#usage"
|
||||
|
||||
object RootCommand :
|
||||
class RootCommand :
|
||||
NoOpCliktCommand(
|
||||
name = "pkl",
|
||||
printHelpOnEmptyArgs = true,
|
||||
@@ -41,13 +41,13 @@ object RootCommand :
|
||||
}
|
||||
|
||||
subcommands(
|
||||
EvalCommand,
|
||||
ReplCommand,
|
||||
ServerCommand,
|
||||
TestCommand,
|
||||
ProjectCommand,
|
||||
DownloadPackageCommand,
|
||||
AnalyzeCommand,
|
||||
EvalCommand(),
|
||||
ReplCommand(),
|
||||
ServerCommand(),
|
||||
TestCommand(),
|
||||
ProjectCommand(),
|
||||
DownloadPackageCommand(),
|
||||
AnalyzeCommand(),
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -19,7 +19,7 @@ import com.github.ajalt.clikt.core.CliktCommand
|
||||
import org.pkl.cli.CliServer
|
||||
import org.pkl.commons.cli.CliBaseOptions
|
||||
|
||||
object ServerCommand :
|
||||
class ServerCommand :
|
||||
CliktCommand(
|
||||
name = "server",
|
||||
help = "Run as a server that communicates over standard input/output",
|
||||
|
||||
@@ -26,7 +26,7 @@ import org.pkl.commons.cli.commands.BaseOptions
|
||||
import org.pkl.commons.cli.commands.ProjectOptions
|
||||
import org.pkl.commons.cli.commands.TestOptions
|
||||
|
||||
object TestCommand :
|
||||
class TestCommand :
|
||||
BaseCommand(name = "test", help = "Run tests within the given module(s)", helpLink = helpLink) {
|
||||
val modules: List<URI> by
|
||||
argument(name = "<modules>", help = "Module paths or URIs to evaluate.")
|
||||
|
||||
Reference in New Issue
Block a user