mirror of
https://codeberg.org/scip/esctl.git
synced 2026-08-24 09:54:18 +02:00
Refactor output code, add JSON, TSV and YAML output modes, add -o (#19), add version subcommand
This commit is contained in:
@@ -25,6 +25,7 @@ import (
|
||||
"sync"
|
||||
|
||||
"codeberg.org/scip/esctl/pkg/cfg"
|
||||
"codeberg.org/scip/esctl/pkg/printer"
|
||||
"github.com/dustin/go-humanize"
|
||||
"github.com/elastic/go-elasticsearch/v9/typedapi/ccr/stats"
|
||||
"github.com/elastic/go-elasticsearch/v9/typedapi/cluster/health"
|
||||
@@ -52,7 +53,7 @@ type apiResponse struct {
|
||||
}
|
||||
|
||||
func ClusterList(conf *cfg.Config) error {
|
||||
table := NewTable(3, len(conf.Clusters))
|
||||
table := printer.NewTable(conf, 3, len(conf.Clusters))
|
||||
|
||||
table.Addheaders("cluster", "uri", "default")
|
||||
|
||||
@@ -76,13 +77,13 @@ func ClusterList(conf *cfg.Config) error {
|
||||
Do(context.Background())
|
||||
|
||||
if err == nil {
|
||||
name = Colorize("green", name)
|
||||
name = printer.Colorize(conf, "green", name)
|
||||
}
|
||||
|
||||
table.entries[idx] = []string{name, cluster.Uri, fmt.Sprintf("%t", current)}
|
||||
table.Entries[idx] = []string{name, cluster.Uri, fmt.Sprintf("%t", current)}
|
||||
}
|
||||
|
||||
if err := table.PrintMarkdown(); err != nil {
|
||||
if err := table.Print(); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
@@ -162,11 +163,11 @@ func ClusterStatus(conf *cfg.Config) error {
|
||||
)
|
||||
}
|
||||
|
||||
table := NewTable(2, 5)
|
||||
table := printer.NewTable(conf, 2, 5)
|
||||
table.Addheaders(cluster, "status")
|
||||
|
||||
table.entries = [][]string{
|
||||
{"Cluster Name", Colorize(clusterhealth.Status.Name, clusterhealth.ClusterName)},
|
||||
table.Entries = [][]string{
|
||||
{"Cluster Name", printer.Colorize(conf, clusterhealth.Status.Name, clusterhealth.ClusterName)},
|
||||
{"ES Version", info.Version.Int},
|
||||
{"Active Shards", fmt.Sprintf("%d", clusterhealth.ActiveShards)},
|
||||
{"Active Primary Shards", fmt.Sprintf("%d", clusterhealth.ActivePrimaryShards)},
|
||||
@@ -178,7 +179,7 @@ func ClusterStatus(conf *cfg.Config) error {
|
||||
table = gatherClusterStats(conf, clusterstats, table)
|
||||
}
|
||||
|
||||
if err := table.PrintMarkdown(); err != nil {
|
||||
if err := table.Print(); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
@@ -186,7 +187,7 @@ func ClusterStatus(conf *cfg.Config) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func gatherClusterStats(conf *cfg.Config, clusterstats *clusterstats.Response, table *Table) *Table {
|
||||
func gatherClusterStats(conf *cfg.Config, clusterstats *clusterstats.Response, table *printer.Table) *printer.Table {
|
||||
var querycount int64
|
||||
var vmversion string
|
||||
|
||||
@@ -202,7 +203,7 @@ func gatherClusterStats(conf *cfg.Config, clusterstats *clusterstats.Response, t
|
||||
|
||||
isleader := checkClusterIsLeader(conf, conf.CurrentCluster)
|
||||
|
||||
table.entries = append(table.entries, [][]string{
|
||||
table.Entries = append(table.Entries, [][]string{
|
||||
{"Indicies", fmt.Sprintf("%d", clusterstats.Indices.Count)},
|
||||
{"Is Leader", fmt.Sprintf("%t", isleader)},
|
||||
{"Docs", fmt.Sprintf("%d", clusterstats.Indices.Docs.Count)},
|
||||
|
||||
Reference in New Issue
Block a user