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

View File

@ -48,6 +48,7 @@ func (pres *Presenter) Present(output io.Writer) error {
}
// populate artifacts...
rows := 0
for _, p := range pres.catalog.Sorted() {
fmt.Fprintln(w, fmt.Sprintf("[%s]", p.Name))
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)
w.Flush()
rows++
}
if rows == 0 {
fmt.Fprintln(output, "No packages discovered")
return nil
}
return nil