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

@ -48,6 +48,7 @@ type searchCmd struct {
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
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)
}

@ -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\n",
},
{
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\n",
},
}
cleanup := resetEnv()

Loading…
Cancel
Save