fix(helm): fix two panics in 'helm search'

pull/820/head
Matt Butcher 9 years ago
parent 632756a653
commit dde1524cab

@ -109,6 +109,15 @@ func checkArgsLength(expectedNum, actualNum int, requiredArgs ...string) error {
return nil
}
// requireInit is a PreRunE implementation for validating that $HELM_HOME is configured.
func requireInit(cmd *cobra.Command, args []string) error {
err := requireHome()
if err != nil {
return fmt.Errorf("%s (try running 'helm init')", err)
}
return nil
}
// prettyError unwraps or rewrites certain errors to make them more user-friendly.
func prettyError(err error) error {
// This is ridiculous. Why is 'grpc.rpcError' not exported? The least they

@ -76,6 +76,19 @@ func installTiller() error {
return nil
}
// requireHome checks to see if $HELM_HOME exists, and returns an error if it does not.
func requireHome() error {
dirs := []string{homePath(), repositoryDirectory(), cacheDirectory(), localRepoDirectory()}
for _, d := range dirs {
if fi, err := os.Stat(d); err != nil {
return fmt.Errorf("directory %q is not configured", d)
} else if !fi.IsDir() {
return fmt.Errorf("expected %q to be a directory", d)
}
}
return nil
}
// ensureHome checks to see if $HELM_HOME exists
//
// If $HELM_HOME does not exist, this function will create it.

@ -17,10 +17,11 @@ func init() {
}
var searchCmd = &cobra.Command{
Use: "search [keyword]",
Short: "Search for a keyword in charts",
Long: "Searches the known repositories cache files for the specified search string, looks at name and keywords",
RunE: search,
Use: "search [keyword]",
Short: "Search for a keyword in charts",
Long: "Searches the known repositories cache files for the specified search string, looks at name and keywords",
RunE: search,
PreRunE: requireInit,
}
func search(cmd *cobra.Command, args []string) error {
@ -47,6 +48,9 @@ func searchChartRefsForPattern(search string, chartRefs map[string]*repo.ChartRe
matches = append(matches, k)
continue
}
if c.Chartfile == nil {
continue
}
for _, keyword := range c.Chartfile.Keywords {
if strings.Contains(keyword, search) {
matches = append(matches, k)

Loading…
Cancel
Save