2026-05-19 13:58:08 +02:00
|
|
|
/*
|
|
|
|
|
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 IndexAlias(conf *cfg.Config) *cli.Command {
|
|
|
|
|
return &cli.Command{
|
|
|
|
|
Name: "alias",
|
|
|
|
|
Aliases: []string{"a"},
|
|
|
|
|
Usage: "manage index aliases",
|
|
|
|
|
|
|
|
|
|
Commands: []*cli.Command{
|
|
|
|
|
IndexAliasCreate(conf),
|
|
|
|
|
IndexAliasList(conf),
|
2026-05-21 14:00:35 +02:00
|
|
|
IndexAliasDelete(conf),
|
2026-05-19 13:58:08 +02:00
|
|
|
//IndexAliasShow(conf),
|
|
|
|
|
//IndexAliasAdd(conf), // see https://www.elastic.co/docs/api/doc/elasticsearch/operation/operation-indices-update-aliases
|
|
|
|
|
},
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func IndexAliasCreate(conf *cfg.Config) *cli.Command {
|
|
|
|
|
return &cli.Command{
|
|
|
|
|
Name: "create",
|
|
|
|
|
Aliases: []string{"+"},
|
|
|
|
|
Usage: "create an index alias",
|
|
|
|
|
UsageText: "create <index> <alias>",
|
|
|
|
|
|
|
|
|
|
Action: func(ctx context.Context, cmd *cli.Command) error {
|
|
|
|
|
index := cmd.Args().Get(0)
|
|
|
|
|
alias := cmd.Args().Get(1)
|
|
|
|
|
|
|
|
|
|
if index == "" || alias == "" {
|
|
|
|
|
return errors.New("no index or alias specified")
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return es.IndexAliasCreate(conf, index, alias)
|
|
|
|
|
},
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2026-05-21 14:00:35 +02:00
|
|
|
func IndexAliasDelete(conf *cfg.Config) *cli.Command {
|
|
|
|
|
return &cli.Command{
|
|
|
|
|
Name: "delete",
|
|
|
|
|
Aliases: []string{"rm"},
|
|
|
|
|
Usage: "delete an index alias",
|
|
|
|
|
UsageText: "delete <index> <alias>",
|
|
|
|
|
|
|
|
|
|
Action: func(ctx context.Context, cmd *cli.Command) error {
|
|
|
|
|
index := cmd.Args().Get(0)
|
|
|
|
|
alias := cmd.Args().Get(1)
|
|
|
|
|
|
|
|
|
|
if index == "" || alias == "" {
|
|
|
|
|
return errors.New("no index or alias specified")
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return es.IndexAliasDelete(conf, index, alias)
|
|
|
|
|
},
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2026-05-19 13:58:08 +02:00
|
|
|
func IndexAliasList(conf *cfg.Config) *cli.Command {
|
|
|
|
|
return &cli.Command{
|
|
|
|
|
Name: "list",
|
|
|
|
|
Aliases: []string{"ls"},
|
|
|
|
|
Usage: "list index aliases",
|
|
|
|
|
|
|
|
|
|
Flags: []cli.Flag{
|
|
|
|
|
&cli.StringSliceFlag{
|
|
|
|
|
Name: "filter",
|
|
|
|
|
Usage: "show only aliases for indicies matching the filter",
|
|
|
|
|
Destination: &conf.Filter,
|
|
|
|
|
Aliases: []string{"F"},
|
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
Action: func(ctx context.Context, cmd *cli.Command) error {
|
|
|
|
|
return es.IndexAliasList(conf)
|
|
|
|
|
},
|
|
|
|
|
}
|
|
|
|
|
}
|