feat(repo): add --no-headers option to 'helm repo list'

This adds a --no-headers flag to the 'helm repo list' command,
allowing users to suppress table headers in the output.
Useful for scripting and automation.

Signed-off-by: Paul Van Laer <paul.van.laer1@gmail.com>
pull/31448/head
Paul Van Laer 2 months ago
parent 9bed143103
commit 6ef79bb8d5

@ -30,6 +30,7 @@ import (
func newRepoListCmd(out io.Writer) *cobra.Command {
var outfmt output.Format
var noHeaders bool
cmd := &cobra.Command{
Use: "list",
Aliases: []string{"ls"},
@ -46,12 +47,17 @@ func newRepoListCmd(out io.Writer) *cobra.Command {
return nil
}
return outfmt.Write(out, &repoListWriter{f.Repositories})
w := &repoListWriter{
repos: f.Repositories,
noHeaders: noHeaders,
}
return outfmt.Write(out, w)
},
}
cmd.Flags().BoolVar(&noHeaders, "no-headers", false, "suppress headers in the output")
bindOutputFlag(cmd, &outfmt)
return cmd
}
@ -61,12 +67,15 @@ type repositoryElement struct {
}
type repoListWriter struct {
repos []*repo.Entry
repos []*repo.Entry
noHeaders bool
}
func (r *repoListWriter) WriteTable(out io.Writer) error {
table := uitable.New()
table.AddRow("NAME", "URL")
if !r.noHeaders {
table.AddRow("NAME", "URL")
}
for _, re := range r.repos {
table.AddRow(re.Name, re.URL)
}

@ -48,6 +48,12 @@ func TestRepoList(t *testing.T) {
golden: "output/repo-list.txt",
wantError: false,
},
{
name: "list without headers",
cmd: fmt.Sprintf("repo list --repository-config %s --repository-cache %s --no-headers", repoFile2, rootDir),
golden: "output/repo-list-no-headers.txt",
wantError: false,
},
}
runTestCmd(t, tests)

@ -0,0 +1,3 @@
charts https://charts.helm.sh/stable
firstexample http://firstexample.com
secondexample http://secondexample.com
Loading…
Cancel
Save