feat: add stats to app list

This commit is contained in:
decentral1se 2021-10-14 12:02:12 +02:00
parent d4d4da19b7
commit 113bdf9e86
No known key found for this signature in database
GPG Key ID: 5E2EF5A63E3718CC
1 changed files with 22 additions and 0 deletions

View File

@ -1,6 +1,7 @@
package app package app
import ( import (
"fmt"
"sort" "sort"
"strings" "strings"
@ -81,6 +82,13 @@ can take some time.
table := abraFormatter.CreateTable(tableCol) table := abraFormatter.CreateTable(tableCol)
table.SetAutoMergeCellsByColumnIndex([]int{0}) table.SetAutoMergeCellsByColumnIndex([]int{0})
var (
versionedAppsCount int
unversionedAppsCount int
onLatestCount int
canUpgradeCount int
)
for _, app := range apps { for _, app := range apps {
var tableRow []string var tableRow []string
if app.Type == appType || appType == "" { if app.Type == appType || appType == "" {
@ -98,8 +106,10 @@ can take some time.
status = statusMeta["status"] status = statusMeta["status"]
} }
tableRow = append(tableRow, status, version) tableRow = append(tableRow, status, version)
versionedAppsCount++
} else { } else {
tableRow = append(tableRow, status, version) tableRow = append(tableRow, status, version)
unversionedAppsCount++
} }
var newUpdates []string var newUpdates []string
@ -131,6 +141,7 @@ can take some time.
tableRow = append(tableRow, "unknown") tableRow = append(tableRow, "unknown")
} else { } else {
tableRow = append(tableRow, "on latest") tableRow = append(tableRow, "on latest")
onLatestCount++
} }
} else { } else {
// FIXME: jeezus golang why do you not have a list reverse function // FIXME: jeezus golang why do you not have a list reverse function
@ -138,12 +149,23 @@ can take some time.
newUpdates[i], newUpdates[j] = newUpdates[j], newUpdates[i] newUpdates[i], newUpdates[j] = newUpdates[j], newUpdates[i]
} }
tableRow = append(tableRow, strings.Join(newUpdates, "\n")) tableRow = append(tableRow, strings.Join(newUpdates, "\n"))
canUpgradeCount++
} }
} }
} }
table.Append(tableRow) table.Append(tableRow)
} }
stats := fmt.Sprintf(
"Total apps: %v | Versioned: %v | Unversioned: %v | On latest: %v | Can upgrade: %v",
len(apps),
versionedAppsCount,
unversionedAppsCount,
onLatestCount,
canUpgradeCount,
)
table.SetCaption(true, stats)
table.Render() table.Render()
return nil return nil