From c900cebc30f948968808bf2ec7e0be6a748b42d3 Mon Sep 17 00:00:00 2001 From: cellarspoon Date: Sun, 2 Jan 2022 16:21:22 +0100 Subject: [PATCH] fix: fix filtering by type for output --- cli/app/list.go | 40 +++++++++++++++++++++++++--------------- 1 file changed, 25 insertions(+), 15 deletions(-) diff --git a/cli/app/list.go b/cli/app/list.go index 91f17fcf..df9db820 100644 --- a/cli/app/list.go +++ b/cli/app/list.go @@ -124,10 +124,18 @@ can take some time. var ok bool if stats, ok = allStats[app.Server]; !ok { stats = serverStatus{} - totalServersCount++ + if appType == "" { + // count server, no filtering + totalServersCount++ + } } if app.Type == appType || appType == "" { + if appType != "" { + // only count server if matches filter + totalServersCount++ + } + appStats := appStatus{} stats.appCount++ totalAppsCount++ @@ -222,23 +230,25 @@ can take some time. table.Append(tableRow) } - table.Render() + if table.NumLines() > 0 { + table.Render() - if status { - fmt.Println(fmt.Sprintf( - "server: %s | total apps: %v | versioned: %v | unversioned: %v | latest: %v | upgrade: %v", - app.Server, - serverStat.appCount, - serverStat.versionCount, - serverStat.unversionedCount, - serverStat.latestCount, - serverStat.upgradeCount, - )) - } else { - fmt.Println(fmt.Sprintf("server: %s | total apps: %v", app.Server, serverStat.appCount)) + if status { + fmt.Println(fmt.Sprintf( + "server: %s | total apps: %v | versioned: %v | unversioned: %v | latest: %v | upgrade: %v", + app.Server, + serverStat.appCount, + serverStat.versionCount, + serverStat.unversionedCount, + serverStat.latestCount, + serverStat.upgradeCount, + )) + } else { + fmt.Println(fmt.Sprintf("server: %s | total apps: %v", app.Server, serverStat.appCount)) + } } - if len(allStats) > 1 { + if len(allStats) > 1 && table.NumLines() > 0 { fmt.Println() // newline separator for multiple servers }