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
@@ -15,6 +15,7 @@
*/ */
package org.pkl.cli.commands 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.default
import com.github.ajalt.clikt.parameters.options.flag import com.github.ajalt.clikt.parameters.options.flag
import com.github.ajalt.clikt.parameters.options.option import com.github.ajalt.clikt.parameters.options.option
@@ -33,6 +34,7 @@ class EvalCommand : ModulesCommand(name = "eval", helpLink = helpLink) {
names = arrayOf("-o", "--output-path"), names = arrayOf("-o", "--output-path"),
metavar = "path", metavar = "path",
help = "File path where the output file is placed.", help = "File path where the output file is placed.",
completionCandidates = CompletionCandidates.Path,
) )
.single() .single()
@@ -59,6 +61,7 @@ class EvalCommand : ModulesCommand(name = "eval", helpLink = helpLink) {
names = arrayOf("-m", "--multiple-file-output-path"), names = arrayOf("-m", "--multiple-file-output-path"),
metavar = "path", metavar = "path",
help = "Directory where a module's multiple file output is placed.", help = "Directory where a module's multiple file output is placed.",
completionCandidates = CompletionCandidates.Path,
) )
.single() .single()
.validate { .validate {
@@ -15,6 +15,7 @@
*/ */
package org.pkl.cli.commands 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.Context
import com.github.ajalt.clikt.core.NoOpCliktCommand import com.github.ajalt.clikt.core.NoOpCliktCommand
import com.github.ajalt.clikt.core.subcommands import com.github.ajalt.clikt.core.subcommands
@@ -116,6 +117,7 @@ class PackageCommand : BaseCommand(name = "package", helpLink = helpLink) {
names = arrayOf("--output-path"), names = arrayOf("--output-path"),
help = "The directory to write artifacts to", help = "The directory to write artifacts to",
metavar = "path", metavar = "path",
completionCandidates = CompletionCandidates.Path,
) )
.single() .single()
.default(".out/%{name}@%{version}") .default(".out/%{name}@%{version}")
@@ -15,6 +15,7 @@
*/ */
package org.pkl.cli.commands 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.argument
import com.github.ajalt.clikt.parameters.arguments.convert import com.github.ajalt.clikt.parameters.arguments.convert
import com.github.ajalt.clikt.parameters.arguments.multiple 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)" override val helpString = "Run tests within the given module(s)"
val modules: List<URI> by 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) } .convert { BaseOptions.parseModuleName(it) }
.multiple() .multiple()
@@ -15,6 +15,7 @@
*/ */
package org.pkl.commons.cli.commands 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.groups.OptionGroup
import com.github.ajalt.clikt.parameters.options.* import com.github.ajalt.clikt.parameters.options.*
import com.github.ajalt.clikt.parameters.types.enum import com.github.ajalt.clikt.parameters.types.enum
@@ -165,6 +166,7 @@ class BaseOptions : OptionGroup() {
option( option(
names = arrayOf("-f", "--format"), names = arrayOf("-f", "--format"),
help = "Output format to generate. <${output.joinToString()}>", help = "Output format to generate. <${output.joinToString()}>",
completionCandidates = CompletionCandidates.Fixed(output.toSet()),
) )
.single() .single()
@@ -187,9 +189,13 @@ class BaseOptions : OptionGroup() {
.splitAll(File.pathSeparator) .splitAll(File.pathSeparator)
val settings: URI? by val settings: URI? by
option(names = arrayOf("--settings"), help = "Pkl settings module to use.").single().convert { option(
parseModuleName(it) names = arrayOf("--settings"),
} help = "Pkl settings module to use.",
completionCandidates = CompletionCandidates.Path,
)
.single()
.convert { parseModuleName(it) }
val timeout: Duration? by val timeout: Duration? by
option( option(
@@ -15,6 +15,7 @@
*/ */
package org.pkl.commons.cli.commands 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.argument
import com.github.ajalt.clikt.parameters.arguments.convert import com.github.ajalt.clikt.parameters.arguments.convert
import com.github.ajalt.clikt.parameters.arguments.multiple import com.github.ajalt.clikt.parameters.arguments.multiple
@@ -24,7 +25,11 @@ import java.net.URI
abstract class ModulesCommand(name: String, helpLink: String) : abstract class ModulesCommand(name: String, helpLink: String) :
BaseCommand(name = name, helpLink = helpLink) { BaseCommand(name = name, helpLink = helpLink) {
open val modules: List<URI> by 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) } .convert { BaseOptions.parseModuleName(it) }
.multiple(required = true) .multiple(required = true)