mirror of
https://codeberg.org/scip/esctl.git
synced 2026-08-24 13:54:17 +02:00
Compare commits
5 Commits
522898f187
...
0.0.27
| Author | SHA1 | Date | |
|---|---|---|---|
| 59331fc721 | |||
| aba5985a2b | |||
| 281499166b | |||
| 744cdcb733 | |||
| 6f3ca3243a |
1
TODO.md
1
TODO.md
@@ -5,4 +5,3 @@
|
|||||||
|
|
||||||
- add datastream support:
|
- add datastream support:
|
||||||
https://www.elastic.co/docs/api/doc/elasticsearch/operation/operation-indices-get-data-stream
|
https://www.elastic.co/docs/api/doc/elasticsearch/operation/operation-indices-get-data-stream
|
||||||
|
|
||||||
|
|||||||
3
go.mod
3
go.mod
@@ -17,6 +17,7 @@ module codeberg.org/scip/esctl
|
|||||||
go 1.26
|
go 1.26
|
||||||
|
|
||||||
require (
|
require (
|
||||||
|
codeberg.org/scip/mapmap v0.0.2
|
||||||
github.com/MichaelMure/go-term-markdown v0.1.4
|
github.com/MichaelMure/go-term-markdown v0.1.4
|
||||||
github.com/alecthomas/repr v0.5.3
|
github.com/alecthomas/repr v0.5.3
|
||||||
github.com/charmbracelet/bubbles v1.0.0
|
github.com/charmbracelet/bubbles v1.0.0
|
||||||
@@ -31,7 +32,6 @@ require (
|
|||||||
github.com/go-openapi/spec v0.22.5
|
github.com/go-openapi/spec v0.22.5
|
||||||
github.com/go-openapi/swag/loading v0.26.1
|
github.com/go-openapi/swag/loading v0.26.1
|
||||||
github.com/mattn/go-isatty v0.0.22
|
github.com/mattn/go-isatty v0.0.22
|
||||||
github.com/seeruk/go-wordwrap v0.0.0-20191208221741-14ec4aac9550
|
|
||||||
github.com/tidwall/gjson v1.19.0
|
github.com/tidwall/gjson v1.19.0
|
||||||
github.com/tlinden/yadu v0.1.3
|
github.com/tlinden/yadu v0.1.3
|
||||||
github.com/urfave/cli/v3 v3.10.1-0.20260623012112-f980ca84bf65
|
github.com/urfave/cli/v3 v3.10.1-0.20260623012112-f980ca84bf65
|
||||||
@@ -40,7 +40,6 @@ require (
|
|||||||
)
|
)
|
||||||
|
|
||||||
require (
|
require (
|
||||||
codeberg.org/scip/mapmap v0.0.2 // indirect
|
|
||||||
github.com/MichaelMure/go-term-text v0.3.1 // indirect
|
github.com/MichaelMure/go-term-text v0.3.1 // indirect
|
||||||
github.com/alecthomas/chroma v0.7.1 // indirect
|
github.com/alecthomas/chroma v0.7.1 // indirect
|
||||||
github.com/aymanbagabas/go-osc52/v2 v2.0.1 // indirect
|
github.com/aymanbagabas/go-osc52/v2 v2.0.1 // indirect
|
||||||
|
|||||||
4
go.sum
4
go.sum
@@ -1,5 +1,3 @@
|
|||||||
codeberg.org/scip/mapmap v0.0.1 h1:L1jMBo/UNp19MXUF/ONjc1XKVGeuF1x05z0pEhjgkzA=
|
|
||||||
codeberg.org/scip/mapmap v0.0.1/go.mod h1:/ojYo2P7dMA2FWEu+jHKmsKPeq5yDcCvXeHevqZd5OI=
|
|
||||||
codeberg.org/scip/mapmap v0.0.2 h1:0i61jOUwFmGVwPukrMzrx0Fi4T9Qru2nlmibuaJimBo=
|
codeberg.org/scip/mapmap v0.0.2 h1:0i61jOUwFmGVwPukrMzrx0Fi4T9Qru2nlmibuaJimBo=
|
||||||
codeberg.org/scip/mapmap v0.0.2/go.mod h1:/ojYo2P7dMA2FWEu+jHKmsKPeq5yDcCvXeHevqZd5OI=
|
codeberg.org/scip/mapmap v0.0.2/go.mod h1:/ojYo2P7dMA2FWEu+jHKmsKPeq5yDcCvXeHevqZd5OI=
|
||||||
github.com/MichaelMure/go-term-markdown v0.1.4 h1:Ir3kBXDUtOX7dEv0EaQV8CNPpH+T7AfTh0eniMOtNcs=
|
github.com/MichaelMure/go-term-markdown v0.1.4 h1:Ir3kBXDUtOX7dEv0EaQV8CNPpH+T7AfTh0eniMOtNcs=
|
||||||
@@ -155,8 +153,6 @@ github.com/rivo/uniseg v0.4.7 h1:WUdvkW8uEhrYfLC4ZzdpI2ztxP1I582+49Oc5Mq64VQ=
|
|||||||
github.com/rivo/uniseg v0.4.7/go.mod h1:FN3SvrM+Zdj16jyLfmOkMNblXMcoc8DfTHruCPUcx88=
|
github.com/rivo/uniseg v0.4.7/go.mod h1:FN3SvrM+Zdj16jyLfmOkMNblXMcoc8DfTHruCPUcx88=
|
||||||
github.com/rogpeppe/go-internal v1.13.1 h1:KvO1DLK/DRN07sQ1LQKScxyZJuNnedQ5/wKSR38lUII=
|
github.com/rogpeppe/go-internal v1.13.1 h1:KvO1DLK/DRN07sQ1LQKScxyZJuNnedQ5/wKSR38lUII=
|
||||||
github.com/rogpeppe/go-internal v1.13.1/go.mod h1:uMEvuHeurkdAXX61udpOXGD/AzZDWNMNyH2VO9fmH0o=
|
github.com/rogpeppe/go-internal v1.13.1/go.mod h1:uMEvuHeurkdAXX61udpOXGD/AzZDWNMNyH2VO9fmH0o=
|
||||||
github.com/seeruk/go-wordwrap v0.0.0-20191208221741-14ec4aac9550 h1:C3CfUXH/qmWuQFRqnPm3Sx8PFxa+pqACjhV5CaNO8pw=
|
|
||||||
github.com/seeruk/go-wordwrap v0.0.0-20191208221741-14ec4aac9550/go.mod h1:Sl541M2Em6rRG3V9WObycR7MYFZiERVkd/TJg0Gt0U4=
|
|
||||||
github.com/sergi/go-diff v1.0.0 h1:Kpca3qRNrduNnOQeazBd0ysaKrUJiIuISHxogkT9RPQ=
|
github.com/sergi/go-diff v1.0.0 h1:Kpca3qRNrduNnOQeazBd0ysaKrUJiIuISHxogkT9RPQ=
|
||||||
github.com/sergi/go-diff v1.0.0/go.mod h1:0CfEIISq7TuYL3j771MWULgwwjU+GofnZX9QAmXWZgo=
|
github.com/sergi/go-diff v1.0.0/go.mod h1:0CfEIISq7TuYL3j771MWULgwwjU+GofnZX9QAmXWZgo=
|
||||||
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
|
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
|
||||||
|
|||||||
@@ -285,9 +285,11 @@ func IlmExplain(conf *cfg.Config, index string) error {
|
|||||||
|
|
||||||
info := ""
|
info := ""
|
||||||
|
|
||||||
err = json.Unmarshal(ilm.StepInfo["reason"], &info)
|
if len(ilm.StepInfo["reason"]) > 0 {
|
||||||
if err != nil {
|
err = json.Unmarshal(ilm.StepInfo["reason"], &info)
|
||||||
return fmt.Errorf("failed to unmarshal step info: %w", err)
|
if err != nil {
|
||||||
|
return fmt.Errorf("failed to unmarshal step info: %w", err)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
table.Entries = [][]any{
|
table.Entries = [][]any{
|
||||||
@@ -299,8 +301,11 @@ func IlmExplain(conf *cfg.Config, index string) error {
|
|||||||
{"phase", *ilm.Phase},
|
{"phase", *ilm.Phase},
|
||||||
{"phase execution", ilmPhaseString(ilm.PhaseExecution.PhaseDefinition, false)},
|
{"phase execution", ilmPhaseString(ilm.PhaseExecution.PhaseDefinition, false)},
|
||||||
{"step", *ilm.Step},
|
{"step", *ilm.Step},
|
||||||
{"failed step", *ilm.FailedStep},
|
}
|
||||||
{"failed step retry count", ilm.FailedStepRetryCount},
|
|
||||||
|
if ilm.FailedStep != nil {
|
||||||
|
table.AddRow("failed step", *ilm.FailedStep)
|
||||||
|
table.AddRow("failed step retry count", ilm.FailedStepRetryCount)
|
||||||
}
|
}
|
||||||
|
|
||||||
if err := table.Print(); err != nil {
|
if err := table.Print(); err != nil {
|
||||||
|
|||||||
@@ -36,7 +36,7 @@ func TaskList(conf *cfg.Config) error {
|
|||||||
|
|
||||||
slog.Debug("res", "tasks", res)
|
slog.Debug("res", "tasks", res)
|
||||||
|
|
||||||
table := printer.NewTable(conf, 8, len(res))
|
table := printer.NewTable(conf, 6, len(res))
|
||||||
table.Addheaders("task id", "action", "start time", "run time", "node", "type")
|
table.Addheaders("task id", "action", "start time", "run time", "node", "type")
|
||||||
|
|
||||||
for idx, task := range res {
|
for idx, task := range res {
|
||||||
|
|||||||
@@ -18,8 +18,11 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|||||||
package printer
|
package printer
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"os"
|
||||||
|
|
||||||
"codeberg.org/scip/esctl/pkg/cfg"
|
"codeberg.org/scip/esctl/pkg/cfg"
|
||||||
"github.com/fatih/color"
|
"github.com/fatih/color"
|
||||||
|
"github.com/mattn/go-isatty"
|
||||||
)
|
)
|
||||||
|
|
||||||
var (
|
var (
|
||||||
@@ -31,6 +34,10 @@ var (
|
|||||||
)
|
)
|
||||||
|
|
||||||
func Colorize(conf *cfg.Config, col, what string) string {
|
func Colorize(conf *cfg.Config, col, what string) string {
|
||||||
|
if !isatty.IsTerminal(os.Stdout.Fd()) {
|
||||||
|
return what
|
||||||
|
}
|
||||||
|
|
||||||
switch conf.Output {
|
switch conf.Output {
|
||||||
case "json", "yaml":
|
case "json", "yaml":
|
||||||
return what
|
return what
|
||||||
@@ -49,3 +56,11 @@ func Colorize(conf *cfg.Config, col, what string) string {
|
|||||||
|
|
||||||
return what
|
return what
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func Bold(what string) string {
|
||||||
|
if !isatty.IsTerminal(os.Stdout.Fd()) {
|
||||||
|
return what
|
||||||
|
}
|
||||||
|
|
||||||
|
return bold(what)
|
||||||
|
}
|
||||||
|
|||||||
@@ -25,7 +25,6 @@ import (
|
|||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
"codeberg.org/scip/esctl/pkg/cfg"
|
"codeberg.org/scip/esctl/pkg/cfg"
|
||||||
"github.com/seeruk/go-wordwrap"
|
|
||||||
"gopkg.in/yaml.v3"
|
"gopkg.in/yaml.v3"
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -156,25 +155,17 @@ func (table *Table) PrintTSV() error {
|
|||||||
|
|
||||||
for _, entries := range table.rows {
|
for _, entries := range table.rows {
|
||||||
currentWidth := 0
|
currentWidth := 0
|
||||||
|
columns := len(entries)
|
||||||
|
|
||||||
for idx, entry := range entries {
|
for idx, entry := range entries {
|
||||||
length := visibleLen(entry)
|
length := visibleLen(entry)
|
||||||
|
|
||||||
if length+currentWidth > table.maxwidth && table.maxwidth-currentWidth > 1 {
|
if length+currentWidth > table.maxwidth &&
|
||||||
// text is too wide to be put into one line, wrap it
|
table.maxwidth-currentWidth > 1 &&
|
||||||
wrapper := wordwrap.Wrapper(table.maxwidth-currentWidth, false)
|
idx == columns-1 {
|
||||||
wrapped := wrapper(entry)
|
// text is too wide to be put into one line, and
|
||||||
|
// it's the last cell, so wrap it
|
||||||
// and indent it
|
entry = wrap(table.maxwidth-currentWidth, currentWidth+2, entry)
|
||||||
first := true
|
|
||||||
for line := range strings.Lines(wrapped) {
|
|
||||||
if first {
|
|
||||||
entry = line
|
|
||||||
first = false
|
|
||||||
} else {
|
|
||||||
entry += "\n " + strings.Repeat(" ", currentWidth) + line
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
currentWidth += table.lenHeaders[idx]
|
currentWidth += table.lenHeaders[idx]
|
||||||
@@ -202,6 +193,48 @@ func (table *Table) PrintTSV() error {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Wrap a text into multiple lines, first line is not indented, all
|
||||||
|
// further lines will be indented. Used within Print() to print large
|
||||||
|
// cell text.
|
||||||
|
func wrap(width, indent int, text string) string {
|
||||||
|
if len(text) <= width {
|
||||||
|
return text
|
||||||
|
}
|
||||||
|
|
||||||
|
wrapped := ""
|
||||||
|
line := ""
|
||||||
|
|
||||||
|
for word := range strings.FieldsSeq(text) {
|
||||||
|
if len(line)+len(word)+1 <= width {
|
||||||
|
// appending word to current line doesn't exceed width
|
||||||
|
if line != "" {
|
||||||
|
line += " "
|
||||||
|
}
|
||||||
|
|
||||||
|
line += word
|
||||||
|
} else {
|
||||||
|
// it exceeds it, so we need to wrap
|
||||||
|
if wrapped == "" {
|
||||||
|
// beginning of output, no indenting here
|
||||||
|
wrapped = line + "\n"
|
||||||
|
} else {
|
||||||
|
// we're in the middle of the text, so add the indent
|
||||||
|
wrapped += strings.Repeat(" ", indent) + line + "\n"
|
||||||
|
}
|
||||||
|
|
||||||
|
// remember the current word for the next round
|
||||||
|
line = word
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if line != "" {
|
||||||
|
// last line, no newline needed here
|
||||||
|
wrapped += strings.Repeat(" ", indent) + line
|
||||||
|
}
|
||||||
|
|
||||||
|
return wrapped
|
||||||
|
}
|
||||||
|
|
||||||
func (table *Table) PrintCSV() error {
|
func (table *Table) PrintCSV() error {
|
||||||
table.preprocessRows()
|
table.preprocessRows()
|
||||||
|
|
||||||
@@ -243,7 +276,7 @@ func (table *Table) Addheaders(headers ...string) {
|
|||||||
case "json", "yaml":
|
case "json", "yaml":
|
||||||
table.Headers[idx] = strings.ReplaceAll(strings.ToLower(header), " ", "_")
|
table.Headers[idx] = strings.ReplaceAll(strings.ToLower(header), " ", "_")
|
||||||
default:
|
default:
|
||||||
table.Headers[idx] = bold(strings.ReplaceAll(strings.ToUpper(header), " ", "-"))
|
table.Headers[idx] = Bold(strings.ReplaceAll(strings.ToUpper(header), " ", "-"))
|
||||||
}
|
}
|
||||||
|
|
||||||
table.RawHeaders[idx] = header
|
table.RawHeaders[idx] = header
|
||||||
|
|||||||
Reference in New Issue
Block a user