forked from toolshed/abra
refactor: urfave v3
This commit is contained in:
cli
app
app.gobackup.gocheck.gocmd.goconfig.gocp.godeploy.golist.gologs.gonew.gops.goremove.gorestart.gorestore.gorollback.gorun.gosecret.goservices.goundeploy.goupgrade.govolume.go
catalogue
cli.gointernal
recipe
server
updater
pkg/autocomplete
scripts/autocomplete
vendor
github.com
Azure
go-ansiterm
ProtonMail
go-crypto
openpgp
beorn7
perks
quantile
cenkalti
backoff
containers
image
docker
reference
pkg
types
cpuguy83
go-md2man
v2
davecgh
go-spew
docker
emirpasic
gods
felixge
ghodss
go-git
gcfg
go-billy
go-git
v5
plumbing
format
config
gitignore
idxfile
index
packfile
object
protocol
packp
utils
worktree_bsd.goworktree_js.goworktree_linux.goworktree_unix_other.goworktree_windows.gogogo
protobuf
google
go-cmp
shlex
uuid
hashicorp
go-cleanhttp
kballard
go-shellquote
kevinburke
ssh_config
lucasb-eyer
go-colorful
mattn
go-isatty
mgutz
ansi
miekg
pkcs11
opencontainers
pkg
pmezard
go-difflib
difflib
russross
blackfriday
sergi
sirupsen
logrus
spf13
theupdateframework
notary
urfave
cli
.flake8.gitignoreCODE_OF_CONDUCT.mdLICENSEREADME.mdapp.gocategory.gocli.gocommand.gocontext.godocs.goerrors.gofish.goflag.goflag_bool.goflag_bool_t.goflag_duration.goflag_float64.goflag_generic.goflag_int.goflag_int64.goflag_int64_slice.goflag_int_slice.goflag_string.goflag_string_slice.goflag_uint.goflag_uint64.gofuncs.gohelp.goparse.gotemplate.go
v2
.flake8README.mdapp.goargs.gocli.gocommand.gocontext.godocs.goflag-spec.yamlflag_bool.goflag_duration.goflag_float64.goflag_float64_slice.goflag_generic.goflag_int.goflag_int64.goflag_int64_slice.goflag_int_slice.goflag_path.goflag_string.goflag_string_slice.goflag_timestamp.goflag_uint.goflag_uint64.goflag_uint64_slice.goflag_uint_slice.gogodoc-current.txthelp.gomkdocs-reqs.txtsliceflag.gosort.gosuggestions.gozz_generated.flags.go
v3
.gitignore.golangci.yamlCODE_OF_CONDUCT.mdLICENSEMakefileREADME.mdargs.go
autocomplete
category.gocli.gocommand.gocompletion.goerrors.gofish.goflag.goflag_bool.goflag_bool_with_inverse.goflag_duration.goflag_ext.goflag_float.goflag_float_slice.goflag_impl.goflag_int.goflag_int_slice.goflag_map_impl.goflag_mutex.goflag_slice_base.goflag_string.goflag_string_map.goflag_string_slice.goflag_timestamp.goflag_uint.goflag_uint_slice.gofuncs.gogodoc-current.txthelp.gomkdocs-reqs.txtmkdocs.ymlparse.gosort.gostaticcheck.confsuggestions.gotemplate.govalue_source.goxeipuuv
gojsonschema
xrash
go.opentelemetry.io
proto
otlp
golang.org
x
google.golang.org
protobuf
internal
impl
gopkg.in
warnings.v0
yaml.v2
yaml.v3
gotest.tools
v3
internal
difflib
68
vendor/github.com/urfave/cli/v3/completion.go
generated
vendored
Normal file
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
|
||||
}
|
Reference in New Issue
Block a user