From 7a65f7479acd2ae76289b0742d5e2349c22fec18 Mon Sep 17 00:00:00 2001 From: Marat Garafutdinov Date: Mon, 23 Apr 2018 16:35:29 -0700 Subject: [PATCH] add --col-width to `helm search` (#3949) * add customizeable --col-width * make docs. whitespacing --- cmd/helm/search.go | 8 +++++--- docs/helm/helm_search.md | 3 ++- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/cmd/helm/search.go b/cmd/helm/search.go index 845bfd0be..ab284a898 100644 --- a/cmd/helm/search.go +++ b/cmd/helm/search.go @@ -47,6 +47,7 @@ type searchCmd struct { versions bool regexp bool version string + colWidth uint } func newSearchCmd(out io.Writer) *cobra.Command { @@ -66,6 +67,7 @@ func newSearchCmd(out io.Writer) *cobra.Command { f.BoolVarP(&sc.regexp, "regexp", "r", false, "use regular expressions for searching") f.BoolVarP(&sc.versions, "versions", "l", false, "show the long listing, with each version of each chart on its own line") f.StringVarP(&sc.version, "version", "v", "", "search using semantic versioning constraints") + f.UintVar(&sc.colWidth, "col-width", 60, "specifies the max column width of output") return cmd } @@ -93,7 +95,7 @@ func (s *searchCmd) run(args []string) error { return err } - fmt.Fprintln(s.out, s.formatSearchResults(data)) + fmt.Fprintln(s.out, s.formatSearchResults(data, s.colWidth)) return nil } @@ -126,12 +128,12 @@ func (s *searchCmd) applyConstraint(res []*search.Result) ([]*search.Result, err return data, nil } -func (s *searchCmd) formatSearchResults(res []*search.Result) string { +func (s *searchCmd) formatSearchResults(res []*search.Result, colWidth uint) string { if len(res) == 0 { return "No results found" } table := uitable.New() - table.MaxColWidth = 50 + table.MaxColWidth = colWidth table.AddRow("NAME", "CHART VERSION", "APP VERSION", "DESCRIPTION") for _, r := range res { table.AddRow(r.Name, r.Chart.Version, r.Chart.AppVersion, r.Chart.Description) diff --git a/docs/helm/helm_search.md b/docs/helm/helm_search.md index f59814b9a..1ed04e880 100644 --- a/docs/helm/helm_search.md +++ b/docs/helm/helm_search.md @@ -19,6 +19,7 @@ helm search [keyword] ### Options ``` + --col-width uint specifies the max column width of output (default 60) -r, --regexp use regular expressions for searching -v, --version string search using semantic versioning constraints -l, --versions show the long listing, with each version of each chart on its own line @@ -38,4 +39,4 @@ helm search [keyword] ### SEE ALSO * [helm](helm.md) - The Helm package manager for Kubernetes. -###### Auto generated by spf13/cobra on 8-Mar-2018 +###### Auto generated by spf13/cobra on 23-Apr-2018