mirror of
https://codeberg.org/scip/esctl.git
synced 2026-08-24 11:34:17 +02:00
fix panic if using 'cluser ls -d' (#45)
This commit is contained in:
@@ -26,6 +26,7 @@ import (
|
|||||||
"log/slog"
|
"log/slog"
|
||||||
"net/http"
|
"net/http"
|
||||||
"os"
|
"os"
|
||||||
|
"reflect"
|
||||||
|
|
||||||
"github.com/alecthomas/repr"
|
"github.com/alecthomas/repr"
|
||||||
"github.com/elastic/elastic-transport-go/v8/elastictransport"
|
"github.com/elastic/elastic-transport-go/v8/elastictransport"
|
||||||
@@ -162,6 +163,7 @@ func (conf *Config) Init() error {
|
|||||||
if err == nil {
|
if err == nil {
|
||||||
conf.DefaultCluster = cluster
|
conf.DefaultCluster = cluster
|
||||||
conf.CurrentCluster = name
|
conf.CurrentCluster = name
|
||||||
|
break
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -174,17 +176,33 @@ func (conf *Config) Init() error {
|
|||||||
return nil
|
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() {
|
func (conf *Config) PrintDebug() {
|
||||||
if !conf.Debug {
|
if !conf.Debug {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
clone := *conf
|
clone := conf.Clone()
|
||||||
|
|
||||||
for name := range clone.Clusters {
|
|
||||||
clone.Clusters[name] = nil
|
|
||||||
}
|
|
||||||
clone.DefaultCluster = nil
|
|
||||||
|
|
||||||
fmt.Println("config:")
|
fmt.Println("config:")
|
||||||
repr.Println(clone)
|
repr.Println(clone)
|
||||||
|
|||||||
Reference in New Issue
Block a user