add snapshot commands

This commit is contained in:
2026-04-22 13:38:02 +02:00
parent a7d979ca38
commit 66221ea219
8 changed files with 298 additions and 10 deletions

View File

@@ -18,16 +18,23 @@ package es
import (
"context"
"log"
"fmt"
"log/slog"
"codeberg.org/scip/esctl/pkg/cfg"
"github.com/elastic/go-elasticsearch/v9/typedapi/types/enums/healthstatus"
)
func IndexList(conf *cfg.Config) error {
res, err := conf.ES.Cat.Indices().Do(context.Background())
cat := conf.ES.Cat.Indices()
if conf.Failed {
cat = cat.Health(healthstatus.Red)
}
res, err := cat.Do(context.Background())
if err != nil {
log.Fatalf("Error getting indicies: %s", err)
return fmt.Errorf("Error getting indicies: %s", err)
}
slog.Debug("ES result", "indicies", res)
@@ -40,9 +47,8 @@ func IndexList(conf *cfg.Config) error {
}
}
table := NewTable(size)
table.headers = []string{bold("NAME"), bold("SIZE"), bold("DOCSCOUNT")}
table := NewTable(3, size)
table.Addheaders("name", "size", "docscount")
for idx, index := range res {
name := Colorize(*index.Health, *index.Index)
@@ -59,3 +65,16 @@ func IndexList(conf *cfg.Config) error {
return nil
}
func IndexShow(conf *cfg.Config, index string) error {
res, err := conf.ES.Indices.Get(index).Do(context.Background())
if err != nil {
return fmt.Errorf("failed to get index: %s", err)
}
slog.Debug("ES result", "index", res)
// FIXME: add table printer like SnapshotShow
return nil
}