/* Copyright © 2026 Thomas von Dein This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program. If not, see . */ package cmd import ( "context" "errors" "codeberg.org/scip/esctl/pkg/cfg" "codeberg.org/scip/esctl/pkg/es" "github.com/urfave/cli/v3" ) const ( SETTINGS = `` ) func ClusterSettings(conf *cfg.Config) *cli.Command { return &cli.Command{ Name: "settings", Usage: "cluster settings management", Aliases: []string{"config"}, Commands: []*cli.Command{ ClusterSettingsList(conf), ClusterSettingsSet(conf), }, } } func ClusterSettingsList(conf *cfg.Config) *cli.Command { return &cli.Command{ Name: "list", 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 } return nil }, } } func ClusterSettingsSet(conf *cfg.Config) *cli.Command { return &cli.Command{ Name: "set", Usage: "set|update cluster settings", Aliases: []string{"set", "update"}, UsageText: "set [options] setting:value [setting:value ...]", CustomHelpTemplate: addReference( "https://www.elastic.co/docs/reference/elasticsearch/configuration-reference"), Flags: []cli.Flag{ &cli.BoolFlag{ Name: "persistent", Usage: "add persistent setting[s] (default)", Destination: &conf.Persistent, Aliases: []string{"p"}, }, &cli.BoolFlag{ Name: "transient", Usage: "add transient setting[s]", Destination: &conf.Transient, Aliases: []string{"t"}, }, }, Action: func(ctx context.Context, cmd *cli.Command) error { args := cmd.Args() if args.Len() == 0 { return errors.New("at least one setting must be specified (format: setting:value)") } if err := es.ClusterSettingsSet(conf, cmd.Args()); err != nil { return err } return nil }, } }