show message when no packages are discovered (#115)

This commit is contained in:
Alex Goodman 2020-07-31 08:30:35 -04:00 committed by GitHub
parent c67e17a2cf
commit 5320280216
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 17 additions and 4 deletions

View File

@ -1,6 +1,7 @@
package table package table
import ( import (
"fmt"
"io" "io"
"sort" "sort"
@ -35,6 +36,11 @@ func (pres *Presenter) Present(output io.Writer) error {
rows = append(rows, row) rows = append(rows, row)
} }
if len(rows) == 0 {
fmt.Fprintln(output, "No packages discovered")
return nil
}
// sort by name, version, then type // sort by name, version, then type
sort.SliceStable(rows, func(i, j int) bool { sort.SliceStable(rows, func(i, j int) bool {
for col := 0; col < len(columns); col++ { for col := 0; col < len(columns); col++ {
@ -57,7 +63,7 @@ func (pres *Presenter) Present(output io.Writer) error {
table.SetCenterSeparator("") table.SetCenterSeparator("")
table.SetColumnSeparator("") table.SetColumnSeparator("")
table.SetRowSeparator("") table.SetRowSeparator("")
table.SetTablePadding("\t") table.SetTablePadding(" ")
table.SetNoWhiteSpace(true) table.SetNoWhiteSpace(true)
table.AppendBulk(rows) table.AppendBulk(rows)

View File

@ -48,6 +48,7 @@ func (pres *Presenter) Present(output io.Writer) error {
} }
// populate artifacts... // populate artifacts...
rows := 0
for _, p := range pres.catalog.Sorted() { for _, p := range pres.catalog.Sorted() {
fmt.Fprintln(w, fmt.Sprintf("[%s]", p.Name)) fmt.Fprintln(w, fmt.Sprintf("[%s]", p.Name))
fmt.Fprintln(w, " Version:\t", p.Version) fmt.Fprintln(w, " Version:\t", p.Version)
@ -55,6 +56,12 @@ func (pres *Presenter) Present(output io.Writer) error {
fmt.Fprintln(w, " Found by:\t", p.FoundBy) fmt.Fprintln(w, " Found by:\t", p.FoundBy)
fmt.Fprintln(w) fmt.Fprintln(w)
w.Flush() w.Flush()
rows++
}
if rows == 0 {
fmt.Fprintln(output, "No packages discovered")
return nil
} }
return nil return nil