pull/4592/merge
pushthat 7 years ago committed by GitHub
commit bc1d98e342
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -44,10 +44,11 @@ type searchCmd struct {
out io.Writer out io.Writer
helmhome helmpath.Home helmhome helmpath.Home
versions bool versions bool
regexp bool regexp bool
version string version string
colWidth uint colWidth uint
shortOutput bool
} }
func newSearchCmd(out io.Writer) *cobra.Command { func newSearchCmd(out io.Writer) *cobra.Command {
@ -64,6 +65,7 @@ func newSearchCmd(out io.Writer) *cobra.Command {
} }
f := cmd.Flags() 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.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.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.StringVarP(&sc.version, "version", "v", "", "search using semantic versioning constraints")
@ -95,7 +97,7 @@ func (s *searchCmd) run(args []string) error {
return err return err
} }
fmt.Fprintln(s.out, s.formatSearchResults(data, s.colWidth)) fmt.Fprintln(s.out, s.formatSearchResults(data, s.colWidth, s.shortOutput))
return nil return nil
} }
@ -128,13 +130,15 @@ func (s *searchCmd) applyConstraint(res []*search.Result) ([]*search.Result, err
return data, nil 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 { if len(res) == 0 {
return "No results found" return "No results found"
} }
table := uitable.New() table := uitable.New()
table.MaxColWidth = colWidth 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 { for _, r := range res {
table.AddRow(r.Name, r.Chart.Version, r.Chart.AppVersion, r.Chart.Description) table.AddRow(r.Name, r.Chart.Version, r.Chart.AppVersion, r.Chart.Description)
} }

@ -84,6 +84,18 @@ func TestSearchCmd(t *testing.T) {
flags: []string{"--regexp"}, flags: []string{"--regexp"},
err: true, 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() cleanup := resetEnv()

Loading…
Cancel
Save