mirror of
https://github.com/helm/helm.git
synced 2026-05-28 04:35:48 -04:00
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>
This commit is contained in:
parent
9bed143103
commit
6ef79bb8d5
3 changed files with 22 additions and 4 deletions
|
|
@ -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)
|
||||
|
|
|
|||
3
pkg/cmd/testdata/output/repo-list-no-headers.txt
vendored
Normal file
3
pkg/cmd/testdata/output/repo-list-no-headers.txt
vendored
Normal file
|
|
@ -0,0 +1,3 @@
|
|||
charts https://charts.helm.sh/stable
|
||||
firstexample http://firstexample.com
|
||||
secondexample http://secondexample.com
|
||||
Loading…
Reference in a new issue