Skip to content

Commit

Permalink
Show smaller output for updated plugins list (#477)
Browse files Browse the repository at this point in the history
  • Loading branch information
artmello authored and k8s-ci-robot committed Jan 27, 2020
1 parent da2c84b commit 7743d89
Showing 1 changed file with 7 additions and 15 deletions.
22 changes: 7 additions & 15 deletions cmd/krew/cmd/update.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ import (
"fmt"
"io"
"os"
"strings"

"github.com/pkg/errors"
"github.com/spf13/cobra"
Expand Down Expand Up @@ -49,20 +48,13 @@ Remarks:

func showFormattedPluginsInfo(out io.Writer, header string, plugins []string) {
var b bytes.Buffer
b.WriteString(fmt.Sprintf(" %s: ", header))

chunkSize := 5
var s []string
for i := 0; i < len(plugins); i += chunkSize {
end := i + chunkSize
if end > len(plugins) {
end = len(plugins)
}
s = append(s, strings.Join(plugins[i:end], ", "))
b.WriteString(fmt.Sprintf(" %s:\n", header))

for _, p := range plugins {
b.WriteString(fmt.Sprintf(" * %s\n", p))
}

b.WriteString(strings.Join(s, "\n\t"))
fmt.Fprintln(out, b.String())
fmt.Fprintf(out, "%s", b.String())
}

func showUpdatedPlugins(out io.Writer, preUpdate, posUpdate []index.Plugin, installedPlugins map[string]string) {
Expand Down Expand Up @@ -93,7 +85,7 @@ func showUpdatedPlugins(out io.Writer, preUpdate, posUpdate []index.Plugin, inst
if len(newPlugins) > 0 {
var s []string
for _, p := range newPlugins {
s = append(s, fmt.Sprintf("%s %s", p.Name, p.Spec.Version))
s = append(s, p.Name)
}

showFormattedPluginsInfo(out, "New plugins available", s)
Expand All @@ -106,7 +98,7 @@ func showUpdatedPlugins(out io.Writer, preUpdate, posUpdate []index.Plugin, inst
s = append(s, fmt.Sprintf("%s %s -> %s", p.Name, old.Spec.Version, p.Spec.Version))
}

showFormattedPluginsInfo(out, "Upgrades available", s)
showFormattedPluginsInfo(out, "Upgrades available for installed plugins", s)
}
}

Expand Down

0 comments on commit 7743d89

Please sign in to comment.