Introduce a JSON output table mechanic

- Create JSONTable as a proxy/extension to tablewriter which can also output JSON.
- Implement machine readable output for `server list` and `recipe list`
This commit is contained in:
2023-01-10 18:51:38 -08:00
committed by Gitea
parent 89fcb5b216
commit cae0d9ef79
5 changed files with 223 additions and 10 deletions

View File

@ -6,7 +6,8 @@ import (
"time"
"github.com/docker/go-units"
"github.com/olekukonko/tablewriter"
// "github.com/olekukonko/tablewriter"
"coopcloud.tech/abra/pkg/jsontable"
"github.com/schollz/progressbar/v3"
"github.com/sirupsen/logrus"
)
@ -32,8 +33,8 @@ func HumanDuration(timestamp int64) string {
}
// CreateTable prepares a table layout for output.
func CreateTable(columns []string) *tablewriter.Table {
table := tablewriter.NewWriter(os.Stdout)
func CreateTable(columns []string) *jsontable.JSONTable {
table := jsontable.NewJSONTable(os.Stdout)
table.SetAutoWrapText(false)
table.SetHeader(columns)
return table