diff --git a/cmd/cluster.go b/cmd/cluster.go index 7b086d4..7edd479 100644 --- a/cmd/cluster.go +++ b/cmd/cluster.go @@ -140,6 +140,27 @@ func ClusterSettingsList(conf *cfg.Config) *cli.Command { Usage: "show cluster settings", Aliases: []string{"ls", "get"}, + Flags: []cli.Flag{ + &cli.BoolFlag{ + Name: "persistent", + Usage: "only show persistent setting[s] (default)", + Destination: &conf.Persistent, + Aliases: []string{"p"}, + }, + &cli.BoolFlag{ + Name: "transient", + Usage: "only show transient setting[s]", + Destination: &conf.Transient, + Aliases: []string{"t"}, + }, + &cli.BoolFlag{ + Name: "default", + Usage: "only show default setting[s]", + Destination: &conf.Default, + Aliases: []string{"D"}, + }, + }, + Action: func(ctx context.Context, cmd *cli.Command) error { if err := es.ClusterSettingsList(conf); err != nil { return err diff --git a/pkg/cfg/config.go b/pkg/cfg/config.go index a6f0514..f3521a7 100644 --- a/pkg/cfg/config.go +++ b/pkg/cfg/config.go @@ -39,20 +39,20 @@ type Cluster struct { } type Config struct { - ConfigFile string // -c - CurrentCluster string // -C - Debug bool // -d - Clusters map[string]*Cluster - DefaultCluster *Cluster - Index string // index: -i - Failed, Partials bool // index: flags - Shards, Replicas int // index create: -s -r - Wait bool // index create: -w - From, To, MaxItems int // search: flags - Filter []string // search: -F - Exclude string // cluster compare: -e (regexp) - All bool // cluster status: -a - Persistent, Transient bool // -p -t cluster settings set + ConfigFile string // -c + CurrentCluster string // -C + Debug bool // -d + Clusters map[string]*Cluster + DefaultCluster *Cluster + Index string // index: -i + Failed, Partials bool // index: flags + Shards, Replicas int // index create: -s -r + Wait bool // index create: -w + From, To, MaxItems int // search: flags + Filter []string // search: -F + Exclude string // cluster compare: -e (regexp) + All bool // cluster status: -a + Persistent, Transient, Default bool // -p -t -D cluster settings set } func NewConfig() *Config { diff --git a/pkg/es/cluster.go b/pkg/es/cluster.go index 3860a56..c8a4af7 100644 --- a/pkg/es/cluster.go +++ b/pkg/es/cluster.go @@ -147,7 +147,16 @@ func ClusterSettingsList(conf *cfg.Config) error { table.Addheaders("setting", "value") entries := [][]string{} - for topic, val := range res.Persistent { + settingshash := res.Persistent // == map[string]json.RawMessage + + switch { + case conf.Transient: + settingshash = res.Transient + case conf.Default: + settingshash = res.Defaults + } + + for topic, val := range settingshash { data := map[string]map[string]any{} err := json.Unmarshal(val, &data)