SPICE-0025: pkl run CLI framework (#1367)

This commit is contained in:
Jen Basch
2026-02-12 07:53:02 -08:00
committed by GitHub
parent 63a20dd453
commit 72a57af164
35 changed files with 4706 additions and 147 deletions

View File

@@ -29,7 +29,7 @@ import org.pkl.core.util.IoUtils
/** Base options shared between CLI commands. */
data class CliBaseOptions(
/** The source modules to evaluate. Relative URIs are resolved against [workingDir]. */
private val sourceModules: List<URI> = listOf(),
val sourceModules: List<URI> = listOf(),
/**
* The URI patterns that determine which modules can be loaded and evaluated. Patterns are matched

View File

@@ -15,6 +15,7 @@
*/
package org.pkl.commons.cli
import com.github.ajalt.clikt.core.CliktError
import java.net.URI
import java.nio.file.Files
import java.nio.file.Path
@@ -46,6 +47,7 @@ abstract class CliCommand(protected val cliOptions: CliBaseOptions) {
proxyAddress?.let(IoUtils::setSystemProxy)
doRun()
} catch (e: PklException) {
if (e.cause is CliktError) throw e.cause!!
throw CliException(e.message!!)
} catch (e: CliException) {
throw e

View File

@@ -1,5 +1,5 @@
/*
* Copyright © 2024-2025 Apple Inc. and the Pkl project authors. All rights reserved.
* Copyright © 2024-2026 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.
@@ -27,14 +27,16 @@ import org.pkl.core.Release
private val theme = Theme { styles["markdown.code.span"] = TextStyle(bold = true) }
fun <T : BaseCliktCommand<T>> T.installCommonOptions() {
fun <T : BaseCliktCommand<T>> T.installCommonOptions(includeVersion: Boolean = true) {
installMordantMarkdown()
versionOption(
Release.current().versionInfo,
names = setOf("-v", "--version"),
message = { if (commandName == "pkl") it else it.replaceFirst("Pkl", commandName) },
)
if (includeVersion) {
versionOption(
Release.current().versionInfo,
names = setOf("-v", "--version"),
message = { if (commandName == "pkl") it else it.replaceFirst("Pkl", commandName) },
)
}
context { terminal = Terminal(theme = theme) }
}