enhanced default cluster selection, add 'cluster switch', overhaul json header setting (#47)

This commit is contained in:
T. von Dein
2026-06-24 09:25:50 +02:00
parent 3c6819151f
commit ffcb8adb70
26 changed files with 393 additions and 320 deletions

View File

@@ -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)
},
}
}

View File

@@ -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
}