mirror of
https://github.com/go-task/task.git
synced 2026-09-01 19:50:16 +02:00
The engine shipped opt-in behind --new-completion, with the old scripts still on --completion. That split was never released, so flip it now rather than carry a third flag through a deprecation later. --completion serves the engine wrappers; the hand-written scripts move to completion/legacy/ and stay reachable via --legacy-completion for a release or two. .goreleaser.yml needed to follow: it packages the static files from completion/ into the deb/rpm/apk contents and the Homebrew cask, so leaving it untouched would have shipped the engine to anyone running `eval "$(task --completion zsh)"` and the old scripts to everyone installing from a package. The paths it references are unchanged and now resolve to the wrappers. Its archive glob is narrowed at the same time, so the test harness under completion/tests/ stops being shipped in the release archives.
77 lines
1.9 KiB
Go
77 lines
1.9 KiB
Go
package task
|
|
|
|
import (
|
|
_ "embed"
|
|
"fmt"
|
|
)
|
|
|
|
// Thin wrappers around the `task __complete` engine, served by `--completion`.
|
|
|
|
//go:embed completion/bash/task.bash
|
|
var completionBash string
|
|
|
|
//go:embed completion/fish/task.fish
|
|
var completionFish string
|
|
|
|
//go:embed completion/nu/task-completions.nu
|
|
var completionNu string
|
|
|
|
//go:embed completion/ps/task.ps1
|
|
var completionPowershell string
|
|
|
|
//go:embed completion/zsh/_task
|
|
var completionZsh string
|
|
|
|
// The self-contained scripts that predate the engine, kept behind
|
|
// `--legacy-completion` as an escape hatch for a couple of releases.
|
|
|
|
//go:embed completion/legacy/bash/task.bash
|
|
var completionBashLegacy string
|
|
|
|
//go:embed completion/legacy/fish/task.fish
|
|
var completionFishLegacy string
|
|
|
|
//go:embed completion/legacy/nu/task-completions.nu
|
|
var completionNuLegacy string
|
|
|
|
//go:embed completion/legacy/ps/task.ps1
|
|
var completionPowershellLegacy string
|
|
|
|
//go:embed completion/legacy/zsh/_task
|
|
var completionZshLegacy string
|
|
|
|
// The maps accept `nushell` as an alias of `nu`.
|
|
var completionScripts = map[string]string{
|
|
"bash": completionBash,
|
|
"fish": completionFish,
|
|
"nu": completionNu,
|
|
"nushell": completionNu,
|
|
"powershell": completionPowershell,
|
|
"zsh": completionZsh,
|
|
}
|
|
|
|
var completionScriptsLegacy = map[string]string{
|
|
"bash": completionBashLegacy,
|
|
"fish": completionFishLegacy,
|
|
"nu": completionNuLegacy,
|
|
"nushell": completionNuLegacy,
|
|
"powershell": completionPowershellLegacy,
|
|
"zsh": completionZshLegacy,
|
|
}
|
|
|
|
func Completion(shell string) (string, error) {
|
|
return completionScript(completionScripts, shell)
|
|
}
|
|
|
|
func LegacyCompletion(shell string) (string, error) {
|
|
return completionScript(completionScriptsLegacy, shell)
|
|
}
|
|
|
|
func completionScript(scripts map[string]string, shell string) (string, error) {
|
|
script, ok := scripts[shell]
|
|
if !ok {
|
|
return "", fmt.Errorf("unknown shell: %s", shell)
|
|
}
|
|
return script, nil
|
|
}
|