Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in
Toggle navigation
H
helm3
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Commits
Issue Boards
Open sidebar
go
helm3
Commits
a7b4b267
Commit
a7b4b267
authored
Oct 05, 2016
by
Matt Butcher
Committed by
GitHub
Oct 05, 2016
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #1281 from technosophos/fix/1261-search-uitable
fix(helm): fix 'helm search' to use UITable
parents
bcda0b87
79e5fd6b
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
31 additions
and
11 deletions
+31
-11
search.go
cmd/helm/search.go
+24
-5
search.go
cmd/helm/search/search.go
+3
-2
search_test.go
cmd/helm/search_test.go
+4
-4
No files found.
cmd/helm/search.go
View file @
a7b4b267
...
...
@@ -21,6 +21,7 @@ import (
"io"
"strings"
"github.com/gosuri/uitable"
"github.com/spf13/cobra"
"k8s.io/helm/cmd/helm/helmpath"
...
...
@@ -71,6 +72,7 @@ func (s *searchCmd) run(args []string) error {
if
len
(
args
)
==
0
{
s
.
showAllCharts
(
index
)
return
nil
}
q
:=
strings
.
Join
(
args
,
" "
)
...
...
@@ -80,17 +82,34 @@ func (s *searchCmd) run(args []string) error {
}
search
.
SortScore
(
res
)
for
_
,
r
:=
range
res
{
fmt
.
Fprintln
(
s
.
out
,
r
.
Name
)
}
fmt
.
Fprintln
(
s
.
out
,
s
.
formatSearchResults
(
res
))
return
nil
}
func
(
s
*
searchCmd
)
showAllCharts
(
i
*
search
.
Index
)
{
for
name
:=
range
i
.
Entries
()
{
fmt
.
Fprintln
(
s
.
out
,
name
)
e
:=
i
.
Entries
()
res
:=
make
([]
*
search
.
Result
,
len
(
e
))
j
:=
0
for
name
,
ch
:=
range
e
{
res
[
j
]
=
&
search
.
Result
{
Name
:
name
,
Chart
:
ch
,
}
j
++
}
search
.
SortScore
(
res
)
fmt
.
Fprintln
(
s
.
out
,
s
.
formatSearchResults
(
res
))
}
func
(
s
*
searchCmd
)
formatSearchResults
(
res
[]
*
search
.
Result
)
string
{
table
:=
uitable
.
New
()
table
.
MaxColWidth
=
50
table
.
AddRow
(
"NAME"
,
"VERSION"
,
"DESCRIPTION"
)
for
_
,
r
:=
range
res
{
table
.
AddRow
(
r
.
Name
,
r
.
Chart
.
Version
,
r
.
Chart
.
Description
)
}
return
table
.
String
()
}
func
(
s
*
searchCmd
)
buildIndex
()
(
*
search
.
Index
,
error
)
{
...
...
cmd/helm/search/search.go
View file @
a7b4b267
...
...
@@ -39,6 +39,7 @@ import (
type
Result
struct
{
Name
string
Score
int
Chart
*
repo
.
ChartVersion
}
// Index is a searchable index of chart information.
...
...
@@ -117,7 +118,7 @@ func (i *Index) SearchLiteral(term string, threshold int) []*Result {
for
k
,
v
:=
range
i
.
lines
{
res
:=
strings
.
Index
(
v
,
term
)
if
score
:=
i
.
calcScore
(
res
,
v
);
res
!=
-
1
&&
score
<
threshold
{
buf
=
append
(
buf
,
&
Result
{
Name
:
k
,
Score
:
score
})
buf
=
append
(
buf
,
&
Result
{
Name
:
k
,
Score
:
score
,
Chart
:
i
.
charts
[
k
]
})
}
}
return
buf
...
...
@@ -136,7 +137,7 @@ func (i *Index) SearchRegexp(re string, threshold int) ([]*Result, error) {
continue
}
if
score
:=
i
.
calcScore
(
ind
[
0
],
v
);
ind
[
0
]
>=
0
&&
score
<
threshold
{
buf
=
append
(
buf
,
&
Result
{
Name
:
k
,
Score
:
score
})
buf
=
append
(
buf
,
&
Result
{
Name
:
k
,
Score
:
score
,
Chart
:
i
.
charts
[
k
]
})
}
}
return
buf
,
nil
...
...
cmd/helm/search_test.go
View file @
a7b4b267
...
...
@@ -34,23 +34,23 @@ func TestSearchCmd(t *testing.T) {
{
name
:
"search for 'maria', expect one match"
,
args
:
[]
string
{
"maria"
},
expect
:
"
testing/mariadb
"
,
expect
:
"
NAME
\t
VERSION
\t
DESCRIPTION
\n
testing/mariadb
\t
0.3.0
\t
Chart for MariaDB
"
,
},
{
name
:
"search for 'alpine', expect two matches"
,
args
:
[]
string
{
"alpine"
},
expect
:
"
testing/alpine
"
,
expect
:
"
NAME
\t
VERSION
\t
DESCRIPTION
\n
testing/alpine
\t
0.1.0
\t
Deploy a basic Alpine Linux pod
"
,
},
{
name
:
"search for 'syzygy', expect no matches"
,
args
:
[]
string
{
"syzygy"
},
expect
:
""
,
expect
:
"
NAME
\t
VERSION
\t
DESCRIPTION
"
,
},
{
name
:
"search for 'alp[a-z]+', expect two matches"
,
args
:
[]
string
{
"alp[a-z]+"
},
flags
:
[]
string
{
"--regexp"
},
expect
:
"
testing/alpine
"
,
expect
:
"
NAME
\t
VERSION
\t
DESCRIPTION
\n
testing/alpine
\t
0.1.0
\t
Deploy a basic Alpine Linux pod
"
,
regexp
:
true
,
},
{
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment