add datastream support, refactor custom completion (#32)

This commit is contained in:
T. von Dein
2026-06-10 15:43:14 +02:00
parent 925b21823a
commit ec1ce56b2d
11 changed files with 445 additions and 63 deletions

View File

@@ -25,7 +25,14 @@ import (
"github.com/urfave/cli/v3"
)
func completeIndex(cmd *cli.Command) {
const (
Cindex = iota
Cdatastream
Crole
Ccluster
)
func complete(cmd *cli.Command, what int) {
if cmd.NArg() > 0 {
return
}
@@ -37,53 +44,27 @@ func completeIndex(cmd *cli.Command) {
return
}
indices, err := es.IndexNames(conf)
var list []string
var err error
switch what {
case Cindex:
list, err = es.IndexNames(conf)
case Crole:
list, err = es.RoleNames(conf)
case Ccluster:
for cluster := range conf.Clusters {
list = append(list, cluster)
}
case Cdatastream:
list, err = es.DatastreamNames(conf)
}
if err != nil {
return
}
for _, index := range indices {
fmt.Println(index)
}
}
func completeRole(cmd *cli.Command) {
if cmd.NArg() > 0 {
return
}
// FIXME: config should load from root.Before(), see https://github.com/urfave/cli/issues/2348
// workaround: load it directly here
conf := cfg.NewConfig()
if err := conf.Init(); err != nil {
return
}
roles, err := es.RoleNames(conf)
if err != nil {
return
}
for _, role := range roles {
fmt.Println(role)
}
}
func completeCluster(cmd *cli.Command) {
if cmd.NArg() > 0 {
return
}
// FIXME: config should load from root.Before(), see https://github.com/urfave/cli/issues/2348
// workaround: load it directly here
conf := cfg.NewConfig()
if err := conf.Init(); err != nil {
return
}
for cluster := range conf.Clusters {
fmt.Println(cluster)
for _, item := range list {
fmt.Println(item)
}
}