fix-index-show-completion, add more completions (#29)

This commit is contained in:
T. von Dein
2026-06-03 13:07:11 +02:00
parent 5ecba5abe6
commit 01e0fd024b
10 changed files with 236 additions and 49 deletions

View File

@@ -118,8 +118,8 @@ func IndexList(conf *cfg.Config) error {
return nil
}
func IndexShow(conf *cfg.Config, index string) error {
res, err := conf.DefaultCluster.ES.Indices.Get(index).
func IndexShow(conf *cfg.Config, indexpattern string) error {
res, err := conf.DefaultCluster.ES.Indices.Get(indexpattern).
// we need to add custom request headers, required for older ES instances
Header("content-type", "application/json").
Header("accept", "application/json").
@@ -128,36 +128,38 @@ func IndexShow(conf *cfg.Config, index string) error {
return fmt.Errorf("failed to get index: %s", esErrorString(err))
}
slog.Debug("ES result", "index", res)
for name, index := range res {
fields := make([]string, len(index.Mappings.Properties))
idx := 0
for field := range index.Mappings.Properties {
fields[idx] = field
idx++
}
fields := make([]string, len(res[index].Mappings.Properties))
idx := 0
for field := range res[index].Mappings.Properties {
fields[idx] = field
idx++
}
table := printer.NewTable(conf, 2, 5)
table.Addheaders("index property", "value")
table := printer.NewTable(conf, 2, 5)
table.Addheaders("index property", "value")
ts, err := strconv.ParseInt(index.Settings.Index.CreationDate.(string), 10, 64)
if err != nil {
ts = 0
}
ts, err := strconv.ParseInt(res[index].Settings.Index.CreationDate.(string), 10, 64)
if err != nil {
ts = 0
}
created := time.Unix(ts/1000, 0)
created := time.Unix(ts/1000, 0)
table.Entries = [][]string{
{"name", name},
{"replicas", *index.Settings.Index.NumberOfReplicas},
{"shards", *index.Settings.Index.NumberOfShards},
{"created", created.Format("2006-01-02 15:04:05")},
{"uuid", *index.Settings.Index.Uuid},
{"fields", strings.Join(fields, ",")},
}
table.Entries = [][]string{
{"name", index},
{"replicas", *res[index].Settings.Index.NumberOfReplicas},
{"shards", *res[index].Settings.Index.NumberOfShards},
{"created", created.Format("2006-01-02 15:04:05")},
{"uuid", *res[index].Settings.Index.Uuid},
{"fields", strings.Join(fields, ",")},
}
if err := table.Print(); err != nil {
return err
}
if err := table.Print(); err != nil {
return err
fmt.Println()
}
return nil