mirror of
https://codeberg.org/scip/esctl.git
synced 2026-08-24 10:44:17 +02:00
222 lines
5.1 KiB
Go
222 lines
5.1 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 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] <index>",
|
|
|
|
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"},
|
|
},
|
|
},
|
|
|
|
ShellComplete: func(ctx context.Context, cmd *cli.Command) {
|
|
completeIndex(cmd)
|
|
},
|
|
|
|
Action: func(ctx context.Context, cmd *cli.Command) error {
|
|
args := cmd.Args()
|
|
|
|
if args.Len() != 1 {
|
|
return errors.New("missing arguments: <index>")
|
|
}
|
|
|
|
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] <index>",
|
|
|
|
ShellComplete: func(ctx context.Context, cmd *cli.Command) {
|
|
completeIndex(cmd)
|
|
},
|
|
|
|
Action: func(ctx context.Context, cmd *cli.Command) error {
|
|
args := cmd.Args()
|
|
|
|
if args.Len() != 1 {
|
|
return errors.New("missing arguments: <index>")
|
|
}
|
|
|
|
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] <index>",
|
|
|
|
ShellComplete: func(ctx context.Context, cmd *cli.Command) {
|
|
completeIndex(cmd)
|
|
},
|
|
|
|
Action: func(ctx context.Context, cmd *cli.Command) error {
|
|
args := cmd.Args()
|
|
|
|
if args.Len() != 1 {
|
|
return errors.New("missing arguments: <index>")
|
|
}
|
|
|
|
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] <index>",
|
|
|
|
ShellComplete: func(ctx context.Context, cmd *cli.Command) {
|
|
completeIndex(cmd)
|
|
},
|
|
|
|
Action: func(ctx context.Context, cmd *cli.Command) error {
|
|
args := cmd.Args()
|
|
|
|
if args.Len() != 1 {
|
|
return errors.New("missing arguments: <index>")
|
|
}
|
|
|
|
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] <index>",
|
|
|
|
Flags: []cli.Flag{
|
|
&cli.BoolFlag{
|
|
Name: "wait",
|
|
Usage: "wait for active shards",
|
|
Destination: &conf.Wait,
|
|
Aliases: []string{"w"},
|
|
},
|
|
},
|
|
|
|
ShellComplete: func(ctx context.Context, cmd *cli.Command) {
|
|
completeIndex(cmd)
|
|
},
|
|
|
|
Action: func(ctx context.Context, cmd *cli.Command) error {
|
|
args := cmd.Args()
|
|
|
|
if args.Len() != 1 {
|
|
return errors.New("missing arguments: <index>")
|
|
}
|
|
|
|
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 <index>",
|
|
|
|
ShellComplete: func(ctx context.Context, cmd *cli.Command) {
|
|
completeIndex(cmd)
|
|
},
|
|
|
|
Action: func(ctx context.Context, cmd *cli.Command) error {
|
|
args := cmd.Args()
|
|
|
|
if args.Len() != 1 {
|
|
return errors.New("missing arguments: <index>")
|
|
}
|
|
|
|
// 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 <index>",
|
|
|
|
ShellComplete: func(ctx context.Context, cmd *cli.Command) {
|
|
completeIndex(cmd)
|
|
},
|
|
|
|
Action: func(ctx context.Context, cmd *cli.Command) error {
|
|
args := cmd.Args()
|
|
|
|
if args.Len() != 1 {
|
|
return errors.New("missing arguments: <index>")
|
|
}
|
|
|
|
return es.CcrFollowerShow(conf, cmd.Args().Get(0))
|
|
},
|
|
}
|
|
}
|