Merge pull request #820 from technosophos/fix/778-search-panic

fix(helm): fix two panics in 'helm search'
pull/837/head
Matt Butcher 9 years ago committed by GitHub
commit 85f1e96851

@ -109,6 +109,15 @@ func checkArgsLength(expectedNum, actualNum int, requiredArgs ...string) error {
return nil 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. // prettyError unwraps or rewrites certain errors to make them more user-friendly.
func prettyError(err error) error { func prettyError(err error) error {
// This is ridiculous. Why is 'grpc.rpcError' not exported? The least they // This is ridiculous. Why is 'grpc.rpcError' not exported? The least they

@ -76,6 +76,19 @@ func installTiller() error {
return nil 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 // ensureHome checks to see if $HELM_HOME exists
// //
// If $HELM_HOME does not exist, this function will create it. // If $HELM_HOME does not exist, this function will create it.

@ -21,6 +21,7 @@ var searchCmd = &cobra.Command{
Short: "Search for a keyword in charts", Short: "Search for a keyword in charts",
Long: "Searches the known repositories cache files for the specified search string, looks at name and keywords", Long: "Searches the known repositories cache files for the specified search string, looks at name and keywords",
RunE: search, RunE: search,
PreRunE: requireInit,
} }
func search(cmd *cobra.Command, args []string) error { 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) matches = append(matches, k)
continue continue
} }
if c.Chartfile == nil {
continue
}
for _, keyword := range c.Chartfile.Keywords { for _, keyword := range c.Chartfile.Keywords {
if strings.Contains(keyword, search) { if strings.Contains(keyword, search) {
matches = append(matches, k) matches = append(matches, k)

Loading…
Cancel
Save