From 39a9eab114b15740ef5186f7be16c5b016376ddb Mon Sep 17 00:00:00 2001 From: Michelle Noorali Date: Wed, 20 Apr 2016 16:59:56 -0600 Subject: [PATCH] ref(helm): comment + err cleanup on helm --- cmd/helm/init.go | 5 +++-- cmd/helm/search.go | 4 ++-- pkg/repo/local.go | 22 +++++++++++----------- 3 files changed, 16 insertions(+), 15 deletions(-) diff --git a/cmd/helm/init.go b/cmd/helm/init.go index dbd84c9d0..dc2bd16d0 100644 --- a/cmd/helm/init.go +++ b/cmd/helm/init.go @@ -97,7 +97,7 @@ func ensureHome(home string) error { repoPath := repositoriesFile(home) if fi, err := os.Stat(repoPath); err != nil { fmt.Printf("Creating %s \n", repoPath) - if err := ioutil.WriteFile(repoPath, []byte("local: localhost:8879/charts"), 0644); err != nil { + if err := ioutil.WriteFile(repoPath, []byte("local: localhost:8879/charts\n"), 0644); err != nil { return err } } else if fi.IsDir() { @@ -112,7 +112,8 @@ func ensureHome(home string) error { return err } - os.Symlink(localCacheFile, CacheDirectory(home)+"/local-cache.txt") + //TODO: take this out and replace with helm update functionality + os.Symlink(localCacheFile, CacheDirectory(home)+"/local-cache.yaml") } else if fi.IsDir() { return fmt.Errorf("%s must be a file, not a directory.", repoPath) } diff --git a/cmd/helm/search.go b/cmd/helm/search.go index 7551b6fdc..07bd846aa 100644 --- a/cmd/helm/search.go +++ b/cmd/helm/search.go @@ -18,7 +18,7 @@ func init() { var searchCmd = &cobra.Command{ Use: "search [CHART]", Short: "Search for charts", - Long: "", + Long: "", //TODO: add search command description RunE: Search, } @@ -51,7 +51,7 @@ func searchCacheForPattern(name string) ([]string, error) { for _, f := range fileList { cache, _ := repo.LoadCacheFile(f) repoName := filepath.Base(strings.TrimRight(f, "-cache.txt")) - for k, _ := range cache.Entries { + for k := range cache.Entries { if strings.Contains(k, name) { matches = append(matches, repoName+"/"+k) } diff --git a/pkg/repo/local.go b/pkg/repo/local.go index 888f87900..df65bf284 100644 --- a/pkg/repo/local.go +++ b/pkg/repo/local.go @@ -18,18 +18,18 @@ type CacheFile struct { } type ChartRef struct { - Name string `yaml:name` - Url string `yaml:url` + Name string + Url string } func StartLocalRepo(path string) { fmt.Println("Now serving you on localhost:8879...") localRepoPath = path - http.HandleFunc("/", homeHandler) + http.HandleFunc("/", rootHandler) http.HandleFunc("/charts/", indexHandler) http.ListenAndServe(":8879", nil) } -func homeHandler(w http.ResponseWriter, r *http.Request) { +func rootHandler(w http.ResponseWriter, r *http.Request) { fmt.Fprintf(w, "Welcome to the Kubernetes Package manager!\nBrowse charts on localhost:8879/charts!") } func indexHandler(w http.ResponseWriter, r *http.Request) { @@ -56,7 +56,7 @@ func AddChartToLocalRepo(ch *chart.Chart, path string) error { } err = ReindexCacheFile(ch, path+"/cache.yaml") if err != nil { - return nil + return err } fmt.Printf("Saved %s to $HELM_HOME/local", name) return nil @@ -65,16 +65,13 @@ func AddChartToLocalRepo(ch *chart.Chart, path string) error { func LoadCacheFile(path string) (*CacheFile, error) { b, err := ioutil.ReadFile(path) if err != nil { - fmt.Println("read file err") - fmt.Printf("err, %s", err) return nil, err } + //TODO: change variable name - y is not helpful :P var y CacheFile err = yaml.Unmarshal(b, &y) if err != nil { - fmt.Println("error unmarshaling") - fmt.Println("err, %s", err) return nil, err } return &y, nil @@ -82,9 +79,12 @@ func LoadCacheFile(path string) (*CacheFile, error) { func ReindexCacheFile(ch *chart.Chart, path string) error { name := ch.Chartfile().Name + "-" + ch.Chartfile().Version - y, _ := LoadCacheFile(path) //TODO: handle err later + y, err := LoadCacheFile(path) + if err != nil { + return err + } found := false - for k, _ := range y.Entries { + for k := range y.Entries { if k == name { found = true break