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
3 changed files with 17 additions and 4 deletions
+7 -1
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)
@@ -1,3 +1,3 @@
NAME VERSION TYPE
package-1 1.0.1 deb
package-2 2.0.1 deb
NAME VERSION TYPE
package-1 1.0.1 deb
package-2 2.0.1 deb
+7
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