mirror of
https://codeberg.org/scip/esctl.git
synced 2026-08-24 12:24:17 +02:00
122 lines
2.7 KiB
Go
122 lines
2.7 KiB
Go
/*
|
|
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 <http://www.gnu.org/licenses/>.
|
|
*/
|
|
package cmd
|
|
|
|
import (
|
|
"context"
|
|
"errors"
|
|
|
|
"codeberg.org/scip/esctl/pkg/cfg"
|
|
"codeberg.org/scip/esctl/pkg/es"
|
|
|
|
"github.com/urfave/cli/v3"
|
|
)
|
|
|
|
func Cluster(conf *cfg.Config) *cli.Command {
|
|
return &cli.Command{
|
|
Name: "cluster",
|
|
Aliases: []string{"c"},
|
|
Usage: "manage cluster[s]",
|
|
|
|
Commands: []*cli.Command{
|
|
Compare(conf),
|
|
Status(conf),
|
|
List(conf),
|
|
},
|
|
}
|
|
}
|
|
|
|
func List(conf *cfg.Config) *cli.Command {
|
|
return &cli.Command{
|
|
Name: "list",
|
|
Usage: "list configured clusters",
|
|
Aliases: []string{"ls"},
|
|
|
|
Action: func(ctx context.Context, cmd *cli.Command) error {
|
|
if err := es.List(conf); err != nil {
|
|
return err
|
|
}
|
|
|
|
return nil
|
|
},
|
|
}
|
|
}
|
|
|
|
func Status(conf *cfg.Config) *cli.Command {
|
|
return &cli.Command{
|
|
Name: "status",
|
|
Usage: "show cluster status",
|
|
Aliases: []string{"s"},
|
|
|
|
Flags: []cli.Flag{
|
|
&cli.BoolFlag{
|
|
Name: "all",
|
|
Usage: "show status of all clusters",
|
|
Destination: &conf.All,
|
|
Aliases: []string{"a"},
|
|
},
|
|
},
|
|
|
|
Action: func(ctx context.Context, cmd *cli.Command) error {
|
|
if err := es.Status(conf); err != nil {
|
|
return err
|
|
}
|
|
|
|
return nil
|
|
},
|
|
}
|
|
}
|
|
|
|
func Compare(conf *cfg.Config) *cli.Command {
|
|
return &cli.Command{
|
|
Name: "compare",
|
|
Aliases: []string{"c"},
|
|
Usage: "compare cluster[s] (yaml config with 2 clusters required)",
|
|
|
|
Flags: []cli.Flag{
|
|
&cli.StringFlag{
|
|
Name: "exclude",
|
|
Usage: "regexp of indicies to exclude",
|
|
Destination: &conf.Exclude,
|
|
Aliases: []string{"e"},
|
|
},
|
|
},
|
|
|
|
Action: func(ctx context.Context, cmd *cli.Command) error {
|
|
leader := cmd.Args().Get(0)
|
|
follower := cmd.Args().Get(1)
|
|
|
|
if leader == "" || follower == "" {
|
|
return errors.New("no leader and follower aliases specified")
|
|
}
|
|
|
|
_, hasLeader := conf.Clusters[leader]
|
|
_, hasFollower := conf.Clusters[follower]
|
|
|
|
if !hasLeader || !hasFollower {
|
|
return errors.New("either leader or follower alias not configured")
|
|
}
|
|
|
|
if err := es.ClusterCompare(conf, leader, follower); err != nil {
|
|
return err
|
|
}
|
|
|
|
return nil
|
|
},
|
|
}
|
|
}
|