mirror of
https://codeberg.org/scip/esctl.git
synced 2026-08-24 06:24:18 +02:00
fix panic if using 'cluser ls -d' (#45)
This commit is contained in:
@@ -26,6 +26,7 @@ import (
|
||||
"log/slog"
|
||||
"net/http"
|
||||
"os"
|
||||
"reflect"
|
||||
|
||||
"github.com/alecthomas/repr"
|
||||
"github.com/elastic/elastic-transport-go/v8/elastictransport"
|
||||
@@ -162,6 +163,7 @@ func (conf *Config) Init() error {
|
||||
if err == nil {
|
||||
conf.DefaultCluster = cluster
|
||||
conf.CurrentCluster = name
|
||||
break
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -174,17 +176,33 @@ func (conf *Config) Init() error {
|
||||
return nil
|
||||
}
|
||||
|
||||
// we are using reflect to clone a config obj w/o the ES stuff for
|
||||
// shorter repr.Println() output (the ES structure is just too large)
|
||||
func (conf *Config) Clone() Config {
|
||||
clone := Config{}
|
||||
|
||||
ref := reflect.ValueOf(*conf)
|
||||
typeOfS := ref.Type()
|
||||
|
||||
for i := 0; i < ref.NumField(); i++ {
|
||||
field := typeOfS.Field(i).Name
|
||||
|
||||
if field == "Clusters" || field == "DefaultCluster" || !ref.Field(i).CanInterface() {
|
||||
continue
|
||||
}
|
||||
|
||||
reflect.ValueOf(&clone).Elem().FieldByName(field).Set(reflect.ValueOf(ref.Field(i).Interface()))
|
||||
}
|
||||
|
||||
return clone
|
||||
}
|
||||
|
||||
func (conf *Config) PrintDebug() {
|
||||
if !conf.Debug {
|
||||
return
|
||||
}
|
||||
|
||||
clone := *conf
|
||||
|
||||
for name := range clone.Clusters {
|
||||
clone.Clusters[name] = nil
|
||||
}
|
||||
clone.DefaultCluster = nil
|
||||
clone := conf.Clone()
|
||||
|
||||
fmt.Println("config:")
|
||||
repr.Println(clone)
|
||||
|
||||
Reference in New Issue
Block a user