Skip to content

Commit

Permalink
Adds catalog name in hub cli search command
Browse files Browse the repository at this point in the history
   - This patch displays the name of the catalog from which
     the resource is on searching the resource using
     `tkn hub search <resourceName>`

Signed-off-by: Puneet Punamiya <ppunamiy@redhat.com>
  • Loading branch information
PuneetPunamiya authored and tekton-robot committed Mar 28, 2021
1 parent 1ac610e commit 48bff7a
Show file tree
Hide file tree
Showing 6 changed files with 24 additions and 11 deletions.
11 changes: 6 additions & 5 deletions api/pkg/cli/cmd/search/search.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,18 +31,19 @@ import (
const resTemplate = `{{- $rl := len .Resources }}{{ if eq $rl 0 -}}
No Resources found
{{ else -}}
NAME KIND DESCRIPTION TAGS
NAME KIND CATALOG DESCRIPTION TAGS
{{ range $_, $r := .Resources -}}
{{ formatName $r.Name $r.LatestVersion.Version }} {{ $r.Kind }} {{ formatDesc $r.LatestVersion.Description 40 }} {{ formatTags $r.Tags }}
{{ formatName $r.Name $r.LatestVersion.Version }} {{ $r.Kind }} {{ formatCatalogName $r.Catalog.Name }} {{ formatDesc $r.LatestVersion.Description 40 }} {{ formatTags $r.Tags }}
{{ end }}
{{- end -}}
`

var (
funcMap = template.FuncMap{
"formatName": formatter.FormatName,
"formatDesc": formatter.FormatDesc,
"formatTags": formatter.FormatTags,
"formatName": formatter.FormatName,
"formatCatalogName": formatter.FormatCatalogName,
"formatDesc": formatter.FormatDesc,
"formatTags": formatter.FormatTags,
}
tmpl = template.Must(template.New("List Resources").Funcs(funcMap).Parse(resTemplate))
)
Expand Down
6 changes: 4 additions & 2 deletions api/pkg/cli/cmd/search/search_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ var res1 = &res.ResourceData{
Kind: "Task",
Catalog: &res.Catalog{
ID: 1,
Name: "tekton",
Type: "community",
},
Rating: 4.8,
Expand All @@ -47,8 +48,8 @@ var res1 = &res.ResourceData{
UpdatedAt: "2020-01-01 12:00:00 +0000 UTC",
},
Tags: []*res.Tag{
&res.Tag{ID: 3, Name: "tag3"},
&res.Tag{ID: 1, Name: "tag1"},
{ID: 3, Name: "tag3"},
{ID: 1, Name: "tag1"},
},
}

Expand All @@ -58,6 +59,7 @@ var res2 = &res.ResourceData{
Kind: "Pipeline",
Catalog: &res.Catalog{
ID: 1,
Name: "foo",
Type: "community",
},
Rating: 4,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
"Name": "foo-bar",
"Catalog": {
"ID": 1,
"Name": "",
"Name": "foo",
"Type": "community"
},
"Kind": "Pipeline",
Expand Down
6 changes: 3 additions & 3 deletions api/pkg/cli/cmd/search/testdata/TestSearch_TableFormat.golden
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
NAME KIND DESCRIPTION TAGS
foo (0.1) Task Description for task abc version 0.1 tag3, tag1
foo-bar (0.2) Pipeline Description for pipeline foo-bar versio... ---
NAME KIND CATALOG DESCRIPTION TAGS
foo (0.1) Task Tekton Description for task abc version 0.1 tag3, tag1
foo-bar (0.2) Pipeline Foo Description for pipeline foo-bar versio... ---
5 changes: 5 additions & 0 deletions api/pkg/cli/formatter/field.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,11 @@ func FormatName(name, latestVersion string) string {
return fmt.Sprintf("%s (%s)", name, latestVersion)
}

// FormatCatalogName returns name of catalog from which the resource is
func FormatCatalogName(catalogName string) string {
return fmt.Sprintf("%s", strings.Title(catalogName))
}

// FormatDesc returns first 40 char of resource description
func FormatDesc(desc string, num int) string {

Expand Down
5 changes: 5 additions & 0 deletions api/pkg/cli/formatter/field_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,11 @@ func TestFormatName(t *testing.T) {
assert.Equal(t, name, "abc (0.1)")
}

func TestFormatCatalogName(t *testing.T) {
catalog := FormatCatalogName("foo")
assert.Equal(t, catalog, "Foo")
}

func TestFormatDesc(t *testing.T) {

// Description greater than 40 char
Expand Down

0 comments on commit 48bff7a

Please sign in to comment.