mirror of
https://github.com/apple/pkl.git
synced 2026-03-27 03:21:13 +01:00
SPICE-0025: pkl run CLI framework (#1367)
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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) }
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user