/* 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" ) func CcrFollower(conf *cfg.Config) *cli.Command { return &cli.Command{ Name: "follower", Aliases: []string{"f"}, Usage: "manage ccr follower indices", Commands: []*cli.Command{ CcrFollowerShow(conf), CcrFollowerAdd(conf), CcrFollowerDelete(conf), CcrFollowerUnfollow(conf), CcrFollowerPause(conf), CcrFollowerResume(conf), CcrFollowerRenew(conf), }, } } func CcrFollowerRenew(conf *cfg.Config) *cli.Command { return &cli.Command{ Name: "renew", Usage: "renew ccr follower index", UsageText: "renew [options] ", Flags: []cli.Flag{ &cli.BoolFlag{ Name: "force", Usage: "force even if unfollow fails (e.g. because following is red anyway)", Destination: &conf.Force, Aliases: []string{"f"}, }, }, Action: func(ctx context.Context, cmd *cli.Command) error { args := cmd.Args() if args.Len() != 1 { return errors.New("missing arguments: ") } return es.CcrFollowerRenew(conf, cmd.Args().Get(0)) }, } } func CcrFollowerResume(conf *cfg.Config) *cli.Command { return &cli.Command{ Name: "resume", Usage: "resume ccr index to follow", UsageText: "resume [options] ", Action: func(ctx context.Context, cmd *cli.Command) error { args := cmd.Args() if args.Len() != 1 { return errors.New("missing arguments: ") } return es.CcrFollowerResume(conf, cmd.Args().Get(0)) }, } } func CcrFollowerPause(conf *cfg.Config) *cli.Command { return &cli.Command{ Name: "pause", Usage: "pause ccr index to follow", UsageText: "pause [options] ", Action: func(ctx context.Context, cmd *cli.Command) error { args := cmd.Args() if args.Len() != 1 { return errors.New("missing arguments: ") } return es.CcrFollowerPause(conf, cmd.Args().Get(0)) }, } } func CcrFollowerUnfollow(conf *cfg.Config) *cli.Command { return &cli.Command{ Name: "unfollow", Usage: "unfollow ccr follower index", UsageText: "unfollow [options] ", Action: func(ctx context.Context, cmd *cli.Command) error { args := cmd.Args() if args.Len() != 1 { return errors.New("missing arguments: ") } return es.CcrFollowerUnfollow(conf, cmd.Args().Get(0)) }, } } func CcrFollowerAdd(conf *cfg.Config) *cli.Command { return &cli.Command{ Name: "add", Aliases: []string{"+"}, Usage: "add ccr follower index", UsageText: "add [options] ", Flags: []cli.Flag{ &cli.BoolFlag{ Name: "wait", Usage: "wait for active shards", Destination: &conf.Wait, Aliases: []string{"w"}, }, }, Action: func(ctx context.Context, cmd *cli.Command) error { args := cmd.Args() if args.Len() != 1 { return errors.New("missing arguments: ") } return es.CcrFollowerAdd(conf, cmd.Args().Get(0)) }, } } func CcrFollowerDelete(conf *cfg.Config) *cli.Command { return &cli.Command{ Name: "delete", Aliases: []string{"rm"}, Usage: "delete ccr follower index", UsageText: "delete ", Action: func(ctx context.Context, cmd *cli.Command) error { args := cmd.Args() if args.Len() != 1 { return errors.New("missing arguments: ") } // just an alias to index delete return es.IndexDelete(conf, cmd.Args().Get(0)) }, } } func CcrFollowerShow(conf *cfg.Config) *cli.Command { return &cli.Command{ Name: "show", Aliases: []string{"sh"}, Usage: "show ccr follower index details", UsageText: "show ", Action: func(ctx context.Context, cmd *cli.Command) error { args := cmd.Args() if args.Len() != 1 { return errors.New("missing arguments: ") } return es.CcrFollowerShow(conf, cmd.Args().Get(0)) }, } }