mirror of
https://codeberg.org/scip/esctl.git
synced 2026-08-24 06:34:18 +02:00
Refactor output code, add JSON, TSV and YAML output modes, add -o (#19), add version subcommand
This commit is contained in:
@@ -26,6 +26,7 @@ import (
|
||||
"time"
|
||||
|
||||
"codeberg.org/scip/esctl/pkg/cfg"
|
||||
"codeberg.org/scip/esctl/pkg/printer"
|
||||
"github.com/elastic/go-elasticsearch/v9/typedapi/cat/indices"
|
||||
"github.com/elastic/go-elasticsearch/v9/typedapi/esdsl"
|
||||
"github.com/elastic/go-elasticsearch/v9/typedapi/types/enums/healthstatus"
|
||||
@@ -95,13 +96,13 @@ func IndexList(conf *cfg.Config) error {
|
||||
}
|
||||
}
|
||||
|
||||
table := NewTable(3, size)
|
||||
table := printer.NewTable(conf, 3, size)
|
||||
table.Addheaders("name", "size", "docscount")
|
||||
|
||||
for idx, index := range list {
|
||||
name := Colorize(*index.Health, *index.Index)
|
||||
name := printer.Colorize(conf, *index.Health, *index.Index)
|
||||
|
||||
table.entries[idx] = []string{name, *index.DatasetSize, *index.DocsCount}
|
||||
table.Entries[idx] = []string{name, *index.DatasetSize, *index.DocsCount}
|
||||
|
||||
if idx == size-1 {
|
||||
break
|
||||
@@ -109,7 +110,7 @@ func IndexList(conf *cfg.Config) error {
|
||||
}
|
||||
|
||||
table.Sort()
|
||||
if err := table.PrintMarkdown(); err != nil {
|
||||
if err := table.Print(); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
@@ -128,7 +129,7 @@ func IndexShow(conf *cfg.Config, index string) error {
|
||||
|
||||
slog.Debug("ES result", "index", res)
|
||||
|
||||
table := NewTable(2, 5)
|
||||
table := printer.NewTable(conf, 2, 5)
|
||||
table.Addheaders("index property", "value")
|
||||
|
||||
ts, err := strconv.ParseInt(res[index].Settings.Index.CreationDate.(string), 10, 64)
|
||||
@@ -138,7 +139,7 @@ func IndexShow(conf *cfg.Config, index string) error {
|
||||
|
||||
created := time.Unix(ts/1000, 0)
|
||||
|
||||
table.entries = [][]string{
|
||||
table.Entries = [][]string{
|
||||
{"name", index},
|
||||
{"replicas", *res[index].Settings.Index.NumberOfReplicas},
|
||||
{"shards", *res[index].Settings.Index.NumberOfShards},
|
||||
@@ -146,7 +147,7 @@ func IndexShow(conf *cfg.Config, index string) error {
|
||||
{"uuid", *res[index].Settings.Index.Uuid},
|
||||
}
|
||||
|
||||
if err := table.PrintMarkdown(); err != nil {
|
||||
if err := table.Print(); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
@@ -247,7 +248,7 @@ func IndexAllocation(conf *cfg.Config, index string) error {
|
||||
|
||||
currentNode := res.CurrentNode
|
||||
|
||||
table := NewTable(2, 10)
|
||||
table := printer.NewTable(conf, 2, 10)
|
||||
table.Addheaders("index allocation setting", "value")
|
||||
|
||||
roles := make([]string, len(currentNode.Roles))
|
||||
@@ -255,7 +256,7 @@ func IndexAllocation(conf *cfg.Config, index string) error {
|
||||
roles[idx] = role.Name
|
||||
}
|
||||
|
||||
table.entries = [][]string{
|
||||
table.Entries = [][]string{
|
||||
{"Index", index},
|
||||
{"Current node", currentNode.Name},
|
||||
{"Current k8s node", currentNode.Attributes["k8s_node_name"]},
|
||||
@@ -268,7 +269,7 @@ func IndexAllocation(conf *cfg.Config, index string) error {
|
||||
{"Can remain on current node", res.CanRemainOnCurrentNode.Name},
|
||||
}
|
||||
|
||||
if err := table.PrintMarkdown(); err != nil {
|
||||
if err := table.Print(); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user