Fix shell completion for paths (#1161)

This commit is contained in:
Artem Yarmoliuk
2025-08-26 18:46:54 +01:00
committed by Dan Chao
parent 9f7997bbc4
commit f0896ba16f
5 changed files with 26 additions and 5 deletions

View File

@@ -15,6 +15,7 @@
*/
package org.pkl.cli.commands
import com.github.ajalt.clikt.completion.CompletionCandidates
import com.github.ajalt.clikt.parameters.options.default
import com.github.ajalt.clikt.parameters.options.flag
import com.github.ajalt.clikt.parameters.options.option
@@ -33,6 +34,7 @@ class EvalCommand : ModulesCommand(name = "eval", helpLink = helpLink) {
names = arrayOf("-o", "--output-path"),
metavar = "path",
help = "File path where the output file is placed.",
completionCandidates = CompletionCandidates.Path,
)
.single()
@@ -59,6 +61,7 @@ class EvalCommand : ModulesCommand(name = "eval", helpLink = helpLink) {
names = arrayOf("-m", "--multiple-file-output-path"),
metavar = "path",
help = "Directory where a module's multiple file output is placed.",
completionCandidates = CompletionCandidates.Path,
)
.single()
.validate {

View File

@@ -15,6 +15,7 @@
*/
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
@@ -116,6 +117,7 @@ class PackageCommand : BaseCommand(name = "package", helpLink = helpLink) {
names = arrayOf("--output-path"),
help = "The directory to write artifacts to",
metavar = "path",
completionCandidates = CompletionCandidates.Path,
)
.single()
.default(".out/%{name}@%{version}")

View File

@@ -15,6 +15,7 @@
*/
package org.pkl.cli.commands
import com.github.ajalt.clikt.completion.CompletionCandidates
import com.github.ajalt.clikt.parameters.arguments.argument
import com.github.ajalt.clikt.parameters.arguments.convert
import com.github.ajalt.clikt.parameters.arguments.multiple
@@ -30,7 +31,11 @@ class TestCommand : BaseCommand(name = "test", helpLink = helpLink) {
override val helpString = "Run tests within the given module(s)"
val modules: List<URI> by
argument(name = "modules", help = "Module paths or URIs to evaluate.")
argument(
name = "modules",
help = "Module paths or URIs to evaluate.",
completionCandidates = CompletionCandidates.Path,
)
.convert { BaseOptions.parseModuleName(it) }
.multiple()

View File

@@ -15,6 +15,7 @@
*/
package org.pkl.commons.cli.commands
import com.github.ajalt.clikt.completion.CompletionCandidates
import com.github.ajalt.clikt.parameters.groups.OptionGroup
import com.github.ajalt.clikt.parameters.options.*
import com.github.ajalt.clikt.parameters.types.enum
@@ -165,6 +166,7 @@ class BaseOptions : OptionGroup() {
option(
names = arrayOf("-f", "--format"),
help = "Output format to generate. <${output.joinToString()}>",
completionCandidates = CompletionCandidates.Fixed(output.toSet()),
)
.single()
@@ -187,9 +189,13 @@ class BaseOptions : OptionGroup() {
.splitAll(File.pathSeparator)
val settings: URI? by
option(names = arrayOf("--settings"), help = "Pkl settings module to use.").single().convert {
parseModuleName(it)
}
option(
names = arrayOf("--settings"),
help = "Pkl settings module to use.",
completionCandidates = CompletionCandidates.Path,
)
.single()
.convert { parseModuleName(it) }
val timeout: Duration? by
option(

View File

@@ -15,6 +15,7 @@
*/
package org.pkl.commons.cli.commands
import com.github.ajalt.clikt.completion.CompletionCandidates
import com.github.ajalt.clikt.parameters.arguments.argument
import com.github.ajalt.clikt.parameters.arguments.convert
import com.github.ajalt.clikt.parameters.arguments.multiple
@@ -24,7 +25,11 @@ import java.net.URI
abstract class ModulesCommand(name: String, helpLink: String) :
BaseCommand(name = name, helpLink = helpLink) {
open val modules: List<URI> by
argument(name = "modules", help = "Module paths or URIs to evaluate.")
argument(
name = "modules",
help = "Module paths or URIs to evaluate.",
completionCandidates = CompletionCandidates.Path,
)
.convert { BaseOptions.parseModuleName(it) }
.multiple(required = true)