mirror of
https://codeberg.org/scip/esctl.git
synced 2026-08-24 06:24:18 +02:00
enhanced default cluster selection, add 'cluster switch', overhaul json header setting (#47)
This commit is contained in:
@@ -18,6 +18,7 @@ package cmd
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
|
||||
"codeberg.org/scip/esctl/pkg/cfg"
|
||||
"codeberg.org/scip/esctl/pkg/es"
|
||||
@@ -33,6 +34,7 @@ func Cluster(conf *cfg.Config) *cli.Command {
|
||||
|
||||
Commands: []*cli.Command{
|
||||
ClusterStatus(conf),
|
||||
ClusterSwitch(conf),
|
||||
ClusterList(conf),
|
||||
ClusterSettings(conf),
|
||||
},
|
||||
@@ -77,3 +79,25 @@ func ClusterStatus(conf *cfg.Config) *cli.Command {
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
func ClusterSwitch(conf *cfg.Config) *cli.Command {
|
||||
return &cli.Command{
|
||||
Name: "switch",
|
||||
Usage: "set current elasticsearch cluster",
|
||||
UsageText: "switch <cluster-name>",
|
||||
Aliases: []string{"ctx"},
|
||||
|
||||
ShellComplete: func(ctx context.Context, cmd *cli.Command) {
|
||||
complete(cmd, Ccluster)
|
||||
},
|
||||
|
||||
Action: func(ctx context.Context, cmd *cli.Command) error {
|
||||
name := cmd.Args().Get(0)
|
||||
if name == "" {
|
||||
return errors.New("no cluster name specified")
|
||||
}
|
||||
|
||||
return conf.SwitchCluster(name)
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
@@ -122,7 +122,10 @@ func Main() int {
|
||||
|
||||
Before: func(ctx context.Context, cmd *cli.Command) (context.Context, error) {
|
||||
if tree {
|
||||
Tree(cmd)
|
||||
if err := Tree(cmd); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
os.Exit(0)
|
||||
}
|
||||
|
||||
@@ -254,7 +257,7 @@ func Debug(conf *cfg.Config) *cli.Command {
|
||||
func Tree(cmd *cli.Command) error {
|
||||
max := 20
|
||||
|
||||
cmd.Walk(func(cmd *cli.Command) error {
|
||||
return cmd.Walk(func(cmd *cli.Command) error {
|
||||
path := cmd.Path()
|
||||
command := path[len(path)-1]
|
||||
|
||||
@@ -269,6 +272,4 @@ func Tree(cmd *cli.Command) error {
|
||||
|
||||
return nil
|
||||
})
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user