forked from toolshed/abra
refactor: tablewriter -> lipgloss
Also the jsontable impl. is dropped also. Output is unchanged.
This commit is contained in:
@ -32,11 +32,25 @@ var recipeLintCommand = cli.Command{
|
||||
log.Fatal(err)
|
||||
}
|
||||
|
||||
tableCol := []string{"ref", "rule", "severity", "satisfied", "skipped", "resolve"}
|
||||
table := formatter.CreateTable(tableCol)
|
||||
headers := []string{
|
||||
"ref",
|
||||
"rule",
|
||||
"severity",
|
||||
"satisfied",
|
||||
"skipped",
|
||||
"resolve",
|
||||
}
|
||||
|
||||
table, err := formatter.CreateTable2()
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
|
||||
table.Headers(headers...)
|
||||
|
||||
hasError := false
|
||||
bar := formatter.CreateProgressbar(-1, "running recipe lint rules...")
|
||||
var rows [][]string
|
||||
var warnMessages []string
|
||||
for level := range lint.LintRules {
|
||||
for _, rule := range lint.LintRules[level] {
|
||||
if internal.OnlyErrors && rule.Level != "error" {
|
||||
@ -58,7 +72,7 @@ var recipeLintCommand = cli.Command{
|
||||
if !skipped {
|
||||
ok, err := rule.Function(recipe)
|
||||
if err != nil {
|
||||
log.Warn(err)
|
||||
warnMessages = append(warnMessages, err.Error())
|
||||
}
|
||||
|
||||
if !ok && rule.Level == "error" {
|
||||
@ -78,26 +92,30 @@ var recipeLintCommand = cli.Command{
|
||||
}
|
||||
}
|
||||
|
||||
table.Append([]string{
|
||||
row := []string{
|
||||
rule.Ref,
|
||||
rule.Description,
|
||||
rule.Level,
|
||||
satisfiedOutput,
|
||||
skippedOutput,
|
||||
rule.HowToResolve,
|
||||
})
|
||||
}
|
||||
|
||||
bar.Add(1)
|
||||
rows = append(rows, row)
|
||||
table.Row(row...)
|
||||
}
|
||||
}
|
||||
|
||||
if table.NumLines() > 0 {
|
||||
fmt.Println()
|
||||
table.Render()
|
||||
}
|
||||
if len(rows) > 0 {
|
||||
fmt.Println(table)
|
||||
|
||||
if hasError {
|
||||
log.Warn("watch out, some critical errors are present in your recipe config")
|
||||
for _, warnMsg := range warnMessages {
|
||||
log.Warn(warnMsg)
|
||||
}
|
||||
|
||||
if hasError {
|
||||
log.Warnf("critical errors present in %s config", recipe.Name)
|
||||
}
|
||||
}
|
||||
|
||||
return nil
|
||||
|
@ -41,12 +41,27 @@ var recipeListCommand = cli.Command{
|
||||
recipes := catl.Flatten()
|
||||
sort.Sort(recipe.ByRecipeName(recipes))
|
||||
|
||||
tableCol := []string{"name", "category", "status", "healthcheck", "backups", "email", "tests", "SSO"}
|
||||
table := formatter.CreateTable(tableCol)
|
||||
table, err := formatter.CreateTable2()
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
|
||||
len := 0
|
||||
headers := []string{
|
||||
"name",
|
||||
"category",
|
||||
"status",
|
||||
"healthcheck",
|
||||
"backups",
|
||||
"email",
|
||||
"tests",
|
||||
"SSO",
|
||||
}
|
||||
|
||||
table.Headers(headers...)
|
||||
|
||||
var rows [][]string
|
||||
for _, recipe := range recipes {
|
||||
tableRow := []string{
|
||||
row := []string{
|
||||
recipe.Name,
|
||||
recipe.Category,
|
||||
strconv.Itoa(recipe.Features.Status),
|
||||
@ -59,23 +74,27 @@ var recipeListCommand = cli.Command{
|
||||
|
||||
if pattern != "" {
|
||||
if strings.Contains(recipe.Name, pattern) {
|
||||
table.Append(tableRow)
|
||||
len++
|
||||
table.Row(row...)
|
||||
rows = append(rows, row)
|
||||
}
|
||||
} else {
|
||||
table.Append(tableRow)
|
||||
len++
|
||||
table.Row(row...)
|
||||
rows = append(rows, row)
|
||||
}
|
||||
}
|
||||
|
||||
if table.NumLines() > 0 {
|
||||
if len(rows) > 0 {
|
||||
if internal.MachineReadable {
|
||||
table.SetCaption(false, "")
|
||||
table.JSONRender()
|
||||
} else {
|
||||
table.SetCaption(true, fmt.Sprintf("total recipes: %v", len))
|
||||
table.Render()
|
||||
out, err := formatter.ToJSON(headers, rows)
|
||||
if err != nil {
|
||||
log.Fatal("unable to render to JSON: %s", err)
|
||||
}
|
||||
fmt.Println(out)
|
||||
return nil
|
||||
}
|
||||
|
||||
fmt.Println(table)
|
||||
log.Infof("total recipes: %v", len(rows))
|
||||
}
|
||||
|
||||
return nil
|
||||
|
@ -9,7 +9,6 @@ import (
|
||||
"coopcloud.tech/abra/pkg/formatter"
|
||||
"coopcloud.tech/abra/pkg/log"
|
||||
recipePkg "coopcloud.tech/abra/pkg/recipe"
|
||||
"github.com/olekukonko/tablewriter"
|
||||
"github.com/urfave/cli"
|
||||
)
|
||||
|
||||
@ -37,6 +36,8 @@ var recipeVersionCommand = cli.Command{
|
||||
Before: internal.SubCommandBefore,
|
||||
BashComplete: autocomplete.RecipeNameComplete,
|
||||
Action: func(c *cli.Context) error {
|
||||
var warnMessages []string
|
||||
|
||||
recipe := internal.ValidateRecipe(c)
|
||||
|
||||
catl, err := recipePkg.ReadRecipeCatalogue(internal.Offline)
|
||||
@ -46,47 +47,63 @@ var recipeVersionCommand = cli.Command{
|
||||
|
||||
recipeMeta, ok := catl[recipe.Name]
|
||||
if !ok {
|
||||
log.Warn("no published versions in catalogue, trying local recipe repository")
|
||||
warnMessages = append(warnMessages, "retrieved versions from local recipe repository")
|
||||
|
||||
recipeVersions, err := recipe.GetRecipeVersions()
|
||||
if err != nil {
|
||||
log.Warn(err)
|
||||
warnMessages = append(warnMessages, err.Error())
|
||||
}
|
||||
|
||||
recipeMeta = recipePkg.RecipeMeta{Versions: recipeVersions}
|
||||
}
|
||||
|
||||
if len(recipeMeta.Versions) == 0 {
|
||||
log.Fatalf("%s has no catalogue published versions?", recipe.Name)
|
||||
log.Fatalf("%s has no published versions?", recipe.Name)
|
||||
}
|
||||
|
||||
tableCols := []string{"version", "service", "image", "tag"}
|
||||
aggregated_table := formatter.CreateTable(tableCols)
|
||||
var allRows [][]string
|
||||
for i := len(recipeMeta.Versions) - 1; i >= 0; i-- {
|
||||
table := formatter.CreateTable(tableCols)
|
||||
table, err := formatter.CreateTable2()
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
|
||||
table.Headers("SERVICE", "NAME", "TAG")
|
||||
|
||||
for version, meta := range recipeMeta.Versions[i] {
|
||||
var versions [][]string
|
||||
var rows [][]string
|
||||
|
||||
for service, serviceMeta := range meta {
|
||||
versions = append(versions, []string{version, service, serviceMeta.Image, serviceMeta.Tag})
|
||||
rows = append(rows, []string{service, serviceMeta.Image, serviceMeta.Tag})
|
||||
allRows = append(allRows, []string{version, service, serviceMeta.Image, serviceMeta.Tag})
|
||||
}
|
||||
|
||||
sort.Slice(versions, sortServiceByName(versions))
|
||||
sort.Slice(rows, sortServiceByName(rows))
|
||||
|
||||
for _, version := range versions {
|
||||
table.Append(version)
|
||||
aggregated_table.Append(version)
|
||||
}
|
||||
table.Rows(rows...)
|
||||
|
||||
if !internal.MachineReadable {
|
||||
table.SetAutoMergeCellsByColumnIndex([]int{0})
|
||||
table.SetAlignment(tablewriter.ALIGN_LEFT)
|
||||
table.Render()
|
||||
fmt.Println()
|
||||
fmt.Println(table)
|
||||
log.Infof("VERSION: %s", version)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if !internal.MachineReadable {
|
||||
for _, warnMsg := range warnMessages {
|
||||
log.Warn(warnMsg)
|
||||
}
|
||||
}
|
||||
|
||||
if internal.MachineReadable {
|
||||
aggregated_table.JSONRender()
|
||||
sort.Slice(allRows, sortServiceByName(allRows))
|
||||
headers := []string{"VERSION", "SERVICE", "NAME", "TAG"}
|
||||
out, err := formatter.ToJSON(headers, allRows)
|
||||
if err != nil {
|
||||
log.Fatal("unable to render to JSON: %s", err)
|
||||
}
|
||||
fmt.Println(out)
|
||||
return nil
|
||||
}
|
||||
|
||||
return nil
|
||||
|
Reference in New Issue
Block a user