mirror of
https://codeberg.org/scip/esctl.git
synced 2026-08-24 05:04:18 +02:00
Refactor output code, add JSON, TSV and YAML output modes, add -o (#19), add version subcommand
This commit is contained in:
@@ -22,10 +22,11 @@ import (
|
||||
"log/slog"
|
||||
|
||||
"codeberg.org/scip/esctl/pkg/cfg"
|
||||
"codeberg.org/scip/esctl/pkg/printer"
|
||||
"github.com/elastic/go-elasticsearch/v9/typedapi/cat/shards"
|
||||
)
|
||||
|
||||
func colorzizeShard(state, name string) string {
|
||||
func colorzizeShard(conf *cfg.Config, state, name string) string {
|
||||
color := "red" // in case of RELOCATING and UNASSIGNED
|
||||
|
||||
switch state {
|
||||
@@ -35,7 +36,7 @@ func colorzizeShard(state, name string) string {
|
||||
color = "yellow"
|
||||
}
|
||||
|
||||
return Colorize(color, name)
|
||||
return printer.Colorize(conf, color, name)
|
||||
}
|
||||
|
||||
func resolvePrirep(state string) string {
|
||||
@@ -102,13 +103,13 @@ func printShards(conf *cfg.Config, shardlist shards.Response) error {
|
||||
headers = append(headers, "node", "ip")
|
||||
}
|
||||
|
||||
table := NewTable(len(headers), len(shardlist))
|
||||
table := printer.NewTable(conf, len(headers), len(shardlist))
|
||||
table.Addheaders(headers...)
|
||||
|
||||
for idx, shard := range shardlist {
|
||||
name := colorzizeShard(*shard.State, *shard.Index)
|
||||
name := colorzizeShard(conf, *shard.State, *shard.Index)
|
||||
|
||||
table.entries[idx] = []string{
|
||||
table.Entries[idx] = []string{
|
||||
name,
|
||||
*shard.Shard,
|
||||
resolvePrirep(*shard.Prirep),
|
||||
@@ -118,7 +119,7 @@ func printShards(conf *cfg.Config, shardlist shards.Response) error {
|
||||
}
|
||||
|
||||
if conf.Verbose {
|
||||
table.entries[idx] = append(table.entries[idx],
|
||||
table.Entries[idx] = append(table.Entries[idx],
|
||||
*shard.Node,
|
||||
*shard.Ip,
|
||||
)
|
||||
@@ -126,7 +127,7 @@ func printShards(conf *cfg.Config, shardlist shards.Response) error {
|
||||
}
|
||||
|
||||
table.Sort()
|
||||
if err := table.PrintMarkdown(); err != nil {
|
||||
if err := table.Print(); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user