mirror of
https://codeberg.org/scip/esctl.git
synced 2026-08-24 06:34:18 +02:00
add datastream support, refactor custom completion (#32)
This commit is contained in:
@@ -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)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user