refactor: urfave v3

This commit is contained in:
2024-07-09 13:57:54 +02:00
parent 375e17a4a0
commit 1f8662cd95
336 changed files with 7332 additions and 25145 deletions
cli
go.modgo.sum
pkg/autocomplete
scripts/autocomplete
vendor
github.com
Azure
ProtonMail
beorn7
perks
quantile
cenkalti
containers
cpuguy83
davecgh
docker
emirpasic
gods
containers
lists
arraylist
utils
felixge
ghodss
go-git
gogo
google
hashicorp
go-cleanhttp
kballard
go-shellquote
kevinburke
ssh_config
lucasb-eyer
go-colorful
mattn
mgutz
ansi
miekg
pkcs11
opencontainers
pkg
pmezard
go-difflib
difflib
russross
sergi
go-diff
diffmatchpatch
sirupsen
spf13
theupdateframework
urfave
xeipuuv
xrash
go.opentelemetry.io
proto
otlp
metrics
trace
golang.org
x
sys
text
internal
language
language
google.golang.org
protobuf
internal
gopkg.in
gotest.tools
v3
internal
difflib
modules.txt

68
vendor/github.com/urfave/cli/v3/completion.go generated vendored Normal file

@ -0,0 +1,68 @@
package cli
import (
"context"
"embed"
"fmt"
"sort"
)
const (
completionCommandName = "generate-completion"
)
var (
//go:embed autocomplete
autoCompleteFS embed.FS
shellCompletions = map[string]renderCompletion{
"bash": getCompletion("autocomplete/bash_autocomplete"),
"ps": getCompletion("autocomplete/powershell_autocomplete.ps1"),
"zsh": getCompletion("autocomplete/zsh_autocomplete"),
"fish": func(c *Command) (string, error) {
return c.ToFishCompletion()
},
}
)
type renderCompletion func(*Command) (string, error)
func getCompletion(s string) renderCompletion {
return func(c *Command) (string, error) {
b, err := autoCompleteFS.ReadFile(s)
return string(b), err
}
}
func buildCompletionCommand() *Command {
return &Command{
Name: completionCommandName,
Hidden: true,
Action: completionCommandAction,
}
}
func completionCommandAction(ctx context.Context, cmd *Command) error {
var shells []string
for k := range shellCompletions {
shells = append(shells, k)
}
sort.Strings(shells)
if cmd.Args().Len() == 0 {
return Exit(fmt.Sprintf("no shell provided for completion command. available shells are %+v", shells), 1)
}
s := cmd.Args().First()
if rc, ok := shellCompletions[s]; !ok {
return Exit(fmt.Sprintf("unknown shell %s, available shells are %+v", s, shells), 1)
} else if c, err := rc(cmd); err != nil {
return Exit(err, 1)
} else {
if _, err = cmd.Writer.Write([]byte(c)); err != nil {
return Exit(err, 1)
}
}
return nil
}