diff --git a/cmd/helm/search.go b/cmd/helm/search.go index 84f328d41..df910b60b 100644 --- a/cmd/helm/search.go +++ b/cmd/helm/search.go @@ -44,10 +44,11 @@ type searchCmd struct { out io.Writer helmhome helmpath.Home - versions bool - regexp bool - version string - colWidth uint + versions bool + regexp bool + version string + colWidth uint + shortOutput bool } func newSearchCmd(out io.Writer) *cobra.Command { @@ -64,6 +65,7 @@ func newSearchCmd(out io.Writer) *cobra.Command { } f := cmd.Flags() + f.BoolVarP(&sc.shortOutput, "short-output", "s", false, "only display chart information") 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") @@ -95,7 +97,7 @@ func (s *searchCmd) run(args []string) error { return err } - fmt.Fprintln(s.out, s.formatSearchResults(data, s.colWidth)) + fmt.Fprintln(s.out, s.formatSearchResults(data, s.colWidth, s.shortOutput)) return nil } @@ -128,13 +130,15 @@ func (s *searchCmd) applyConstraint(res []*search.Result) ([]*search.Result, err return data, nil } -func (s *searchCmd) formatSearchResults(res []*search.Result, colWidth uint) string { +func (s *searchCmd) formatSearchResults(res []*search.Result, colWidth uint, shortOutput bool) string { if len(res) == 0 { return "No results found" } table := uitable.New() table.MaxColWidth = colWidth - table.AddRow("NAME", "CHART VERSION", "APP VERSION", "DESCRIPTION") + if !shortOutput { + 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/cmd/helm/search_test.go b/cmd/helm/search_test.go index 233f94572..459a12a3e 100644 --- a/cmd/helm/search_test.go +++ b/cmd/helm/search_test.go @@ -84,6 +84,18 @@ func TestSearchCmd(t *testing.T) { flags: []string{"--regexp"}, err: true, }, + { + name: "search for 'maria', expect one match, expect to be the short version", + args: []string{"maria"}, + flags: []string{"--short-output"}, + expected: "testing/mariadb\t0.3.0 \t \tChart for MariaDB", + }, + { + name: "search for 'maria', expect one match, expect to be the short version", + args: []string{"maria"}, + flags: []string{"-s"}, + expected: "testing/mariadb\t0.3.0 \t \tChart for MariaDB", + }, } cleanup := resetEnv()