mirror of
https://github.com/apple/pkl.git
synced 2026-03-18 07:13:54 +01:00
Allow referring to remote project dependencies on the CLI with @-notation (#1434)
This commit is contained in:
@@ -52,8 +52,6 @@ constructor(
|
||||
private val errStream: OutputStream = System.err,
|
||||
) : CliCommand(options) {
|
||||
|
||||
private val normalizedSourceModule = options.normalizedSourceModules.first()
|
||||
|
||||
override fun doRun() {
|
||||
val builder = evaluatorBuilder()
|
||||
try {
|
||||
@@ -68,7 +66,7 @@ constructor(
|
||||
val evaluator = builder.build()
|
||||
evaluator.use {
|
||||
evaluator.evaluateCommand(
|
||||
uri(normalizedSourceModule),
|
||||
uri(resolvedSourceModules.first()),
|
||||
reservedFlagNames,
|
||||
reservedFlagShortNames,
|
||||
) { spec ->
|
||||
|
||||
@@ -111,12 +111,11 @@ constructor(
|
||||
}
|
||||
|
||||
private fun resolveOutputPaths(pathStr: String): Map<URI, Path> {
|
||||
val moduleUris = options.base.normalizedSourceModules
|
||||
val workingDir = options.base.normalizedWorkingDir
|
||||
// used just to resolve the `%{moduleName}` placeholder
|
||||
val moduleResolver = ModuleResolver(moduleKeyFactories(ModulePathResolver.empty()))
|
||||
|
||||
return moduleUris.associateWith { uri ->
|
||||
return resolvedSourceModules.associateWith { uri ->
|
||||
val moduleDir: String? =
|
||||
IoUtils.toPath(uri)?.let {
|
||||
IoUtils.relativize(it.parent, workingDir).toString().ifEmpty { "." }
|
||||
@@ -192,7 +191,7 @@ constructor(
|
||||
}
|
||||
} else {
|
||||
var outputWritten = false
|
||||
for (moduleUri in options.base.normalizedSourceModules) {
|
||||
for (moduleUri in resolvedSourceModules) {
|
||||
val moduleSource = toModuleSource(moduleUri, inputStream)
|
||||
if (options.expression != null) {
|
||||
val output = evaluator.evaluateExpressionString(moduleSource, options.expression)
|
||||
|
||||
@@ -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.
|
||||
@@ -66,7 +66,7 @@ constructor(
|
||||
try {
|
||||
return builder
|
||||
.apply {
|
||||
for ((idx, sourceModule) in options.base.normalizedSourceModules.withIndex()) {
|
||||
for ((idx, sourceModule) in resolvedSourceModules.withIndex()) {
|
||||
addExternalProperty("pkl.analyzeImports.$idx", sourceModule.toString())
|
||||
}
|
||||
}
|
||||
|
||||
@@ -47,7 +47,7 @@ constructor(
|
||||
|
||||
private fun evalTest(builder: EvaluatorBuilder) {
|
||||
val sources =
|
||||
options.normalizedSourceModules.ifEmpty { project?.tests?.map { it.toUri() } }
|
||||
resolvedSourceModules.ifEmpty { project?.tests?.map { it.toUri() } }
|
||||
?:
|
||||
// keep in sync with error message thrown by clikt
|
||||
throw CliException(
|
||||
|
||||
@@ -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.
|
||||
@@ -16,7 +16,6 @@
|
||||
package org.pkl.cli.commands
|
||||
|
||||
import com.github.ajalt.clikt.core.Context
|
||||
import com.github.ajalt.clikt.core.NoOpCliktCommand
|
||||
import com.github.ajalt.clikt.core.subcommands
|
||||
import com.github.ajalt.clikt.parameters.options.option
|
||||
import com.github.ajalt.clikt.parameters.types.path
|
||||
@@ -24,9 +23,10 @@ import java.nio.file.Path
|
||||
import org.pkl.cli.CliImportAnalyzer
|
||||
import org.pkl.cli.CliImportAnalyzerOptions
|
||||
import org.pkl.commons.cli.commands.ModulesCommand
|
||||
import org.pkl.commons.cli.commands.NoOpCommand
|
||||
import org.pkl.commons.cli.commands.single
|
||||
|
||||
class AnalyzeCommand : NoOpCliktCommand(name = "analyze") {
|
||||
class AnalyzeCommand : NoOpCommand(name = "analyze") {
|
||||
override fun help(context: Context) = "Commands related to static analysis"
|
||||
|
||||
override fun helpEpilog(context: Context) = "For more information, visit $helpLink"
|
||||
|
||||
@@ -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.
|
||||
@@ -17,7 +17,6 @@ package org.pkl.cli.commands
|
||||
|
||||
import com.github.ajalt.clikt.completion.CompletionCandidates
|
||||
import com.github.ajalt.clikt.core.Context
|
||||
import com.github.ajalt.clikt.core.NoOpCliktCommand
|
||||
import com.github.ajalt.clikt.core.subcommands
|
||||
import com.github.ajalt.clikt.parameters.arguments.argument
|
||||
import com.github.ajalt.clikt.parameters.arguments.multiple
|
||||
@@ -30,10 +29,11 @@ import java.nio.file.Path
|
||||
import org.pkl.cli.CliProjectPackager
|
||||
import org.pkl.cli.CliProjectResolver
|
||||
import org.pkl.commons.cli.commands.BaseCommand
|
||||
import org.pkl.commons.cli.commands.NoOpCommand
|
||||
import org.pkl.commons.cli.commands.TestOptions
|
||||
import org.pkl.commons.cli.commands.single
|
||||
|
||||
class ProjectCommand : NoOpCliktCommand(name = "project") {
|
||||
class ProjectCommand : NoOpCommand(name = "project") {
|
||||
override fun help(context: Context) = "Run commands related to projects"
|
||||
|
||||
override fun helpEpilog(context: Context) = "For more information, visit $helpLink"
|
||||
|
||||
@@ -17,21 +17,22 @@ package org.pkl.cli.commands
|
||||
|
||||
import com.github.ajalt.clikt.completion.CompletionCommand
|
||||
import com.github.ajalt.clikt.core.Context
|
||||
import com.github.ajalt.clikt.core.NoOpCliktCommand
|
||||
import com.github.ajalt.clikt.core.context
|
||||
import com.github.ajalt.clikt.core.subcommands
|
||||
import org.pkl.commons.cli.commands.NoOpCommand
|
||||
import org.pkl.commons.cli.commands.installCommonOptions
|
||||
import org.pkl.core.Release
|
||||
|
||||
internal val helpLink = "${Release.current().documentation.homepage}pkl-cli/index.html#usage"
|
||||
|
||||
class RootCommand : NoOpCliktCommand(name = "pkl") {
|
||||
class RootCommand : NoOpCommand(name = "pkl") {
|
||||
override val printHelpOnEmptyArgs = true
|
||||
|
||||
override fun helpEpilog(context: Context) = "For more information, visit $helpLink"
|
||||
|
||||
init {
|
||||
context {
|
||||
readArgumentFile = null
|
||||
suggestTypoCorrection = { given, possible ->
|
||||
if (!given.startsWith("-")) {
|
||||
registeredSubcommands().map { it.commandName }
|
||||
|
||||
@@ -49,7 +49,11 @@ class RunCommand : BaseCommand(name = "run", helpLink = helpLink) {
|
||||
private val showHelp by option("-h", "--help", help = "Show this message and exit").flag()
|
||||
|
||||
val module: URI? by
|
||||
argument(name = "module", completionCandidates = CompletionCandidates.Path)
|
||||
argument(
|
||||
name = "module",
|
||||
help = "Root pkl:Command module to invoke.",
|
||||
completionCandidates = CompletionCandidates.Path,
|
||||
)
|
||||
.convert { BaseOptions.parseModuleName(it) }
|
||||
.optional()
|
||||
|
||||
|
||||
Reference in New Issue
Block a user