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

@ -27,6 +27,7 @@ var recipeListCommand = cli.Command{
Aliases: []string{"ls"},
Flags: []cli.Flag{
internal.DebugFlag,
internal.MachineReadableFlag,
patternFlag,
},
Before: internal.SubCommandBefore,
@ -66,10 +67,14 @@ var recipeListCommand = cli.Command{
}
}
table.SetCaption(true, fmt.Sprintf("total recipes: %v", len))
if table.NumLines() > 0 {
table.Render()
if internal.MachineReadable {
table.SetCaption(false, "")
table.JSONRender()
} else {
table.SetCaption(true, fmt.Sprintf("total recipes: %v", len))
table.Render()
}
}
return nil