Refactor output code, add JSON, TSV and YAML output modes, add -o (#19), add version subcommand

This commit is contained in:
T. von Dein
2026-05-20 13:06:39 +02:00
parent 32de4863af
commit 0870ceb3df
16 changed files with 439 additions and 190 deletions

View File

@@ -25,6 +25,7 @@ import (
"strings"
"codeberg.org/scip/esctl/pkg/cfg"
"codeberg.org/scip/esctl/pkg/printer"
)
var (
@@ -83,11 +84,11 @@ func SnapshotList(conf *cfg.Config) error {
}
}
table := NewTable(5, len(snapshots))
table := printer.NewTable(conf, 5, len(snapshots))
table.Addheaders("name", "index", "start", "orphaned", "status")
for idx, snap := range snapshots {
table.entries[idx] = []string{
table.Entries[idx] = []string{
snap.Name,
snap.Forindex,
snap.Start,
@@ -97,7 +98,7 @@ func SnapshotList(conf *cfg.Config) error {
}
table.Sort()
if err := table.PrintMarkdown(); err != nil {
if err := table.Print(); err != nil {
return err
}
@@ -116,12 +117,12 @@ func SnapshotShow(conf *cfg.Config, snapshot string) error {
return errors.New("no snapshot retrieved")
}
table := NewTable(2, 17)
table := printer.NewTable(conf, 2, 17)
table.Addheaders("snapshot property", "value")
snap := res.Snapshots[0]
table.entries = [][]string{
table.Entries = [][]string{
{"snapshot", snapshot},
{"uuid", snap.Uuid},
{"repository", *snap.Repository},
@@ -137,7 +138,7 @@ func SnapshotShow(conf *cfg.Config, snapshot string) error {
{"shards-successful", fmt.Sprintf("%d", snap.Shards.Successful)},
}
if err := table.PrintMarkdown(); err != nil {
if err := table.Print(); err != nil {
return err
}