fix: update repo_list.go (Closes 30606!)

Signed-off-by: zsz <2492127354@qq.com>
pull/30608/head
zsz 7 months ago
parent 726b2f6f03
commit bce6d0ec25

@ -21,7 +21,6 @@ import (
"io" "io"
"github.com/gosuri/uitable" "github.com/gosuri/uitable"
"github.com/pkg/errors"
"github.com/spf13/cobra" "github.com/spf13/cobra"
"helm.sh/helm/v4/pkg/cli/output" "helm.sh/helm/v4/pkg/cli/output"
@ -39,10 +38,6 @@ func newRepoListCmd(out io.Writer) *cobra.Command {
ValidArgsFunction: noMoreArgsCompFunc, ValidArgsFunction: noMoreArgsCompFunc,
RunE: func(_ *cobra.Command, _ []string) error { RunE: func(_ *cobra.Command, _ []string) error {
f, _ := repo.LoadFile(settings.RepositoryConfig) f, _ := repo.LoadFile(settings.RepositoryConfig)
if len(f.Repositories) == 0 && !(outfmt == output.JSON || outfmt == output.YAML) {
return errors.New("no repositories to show")
}
return outfmt.Write(out, &repoListWriter{f.Repositories}) return outfmt.Write(out, &repoListWriter{f.Repositories})
}, },
} }
@ -62,6 +57,10 @@ type repoListWriter struct {
} }
func (r *repoListWriter) WriteTable(out io.Writer) error { func (r *repoListWriter) WriteTable(out io.Writer) error {
if len(r.repos) == 0 {
_, _ = fmt.Fprintln(out, "no repositories to show")
return nil
}
table := uitable.New() table := uitable.New()
table.AddRow("NAME", "URL") table.AddRow("NAME", "URL")
for _, re := range r.repos { for _, re := range r.repos {

Loading…
Cancel
Save