diff --git a/cmd/helm/repository.go b/cmd/helm/repository.go index 37f7709e4..3ec8b1b15 100644 --- a/cmd/helm/repository.go +++ b/cmd/helm/repository.go @@ -19,6 +19,7 @@ package main import ( "encoding/json" "errors" + "path/filepath" "github.com/codegangsta/cli" "github.com/kubernetes/helm/pkg/format" @@ -98,18 +99,12 @@ func listRepos(c *cli.Context) error { func removeRepo(c *cli.Context) error { args := c.Args() if len(args) < 1 { - return errors.New("'helm repo remove' requires a repository url as an argument") + return errors.New("'helm repo remove' requires a repository name as an argument") } - //arg := args[0] - //u, err := url.Parse(arg) - //if err != nil { - //return err - //} - //p := filepath.Join(chartRepoPath, u.String()) - //if _, err := NewClient(c).Delete(p, nil); err != nil { - //return err - //} - //format.Msg(arg + " has been removed.\n") - format.Info("TO BE IMPLEMENTED") + name := args[0] + if _, err := NewClient(c).Delete(filepath.Join(chartRepoPath, name), nil); err != nil { + return err + } + format.Msg(name + " has been removed.\n") return nil } diff --git a/cmd/manager/chartrepos.go b/cmd/manager/chartrepos.go index addd2d00c..08feb1819 100644 --- a/cmd/manager/chartrepos.go +++ b/cmd/manager/chartrepos.go @@ -7,7 +7,6 @@ import ( "github.com/kubernetes/helm/pkg/util" "encoding/json" - "fmt" "net/http" "net/url" "regexp" @@ -57,18 +56,17 @@ func removeChartRepoHandlerFunc(w http.ResponseWriter, r *http.Request, c *route handler := "manager: remove chart repository" util.LogHandlerEntry(handler, r) defer r.Body.Close() - URL, err := pos(w, r, 2) + name, err := pos(w, r, 2) if err != nil { return err } - fmt.Printf("URL: %#v \n", URL) - err = c.Manager.RemoveChartRepo(URL) + err = c.Manager.RemoveChartRepo(name) if err != nil { return err } - msg, _ := json.Marshal(URL + " has been removed from the list of chart repositories.") + msg, _ := json.Marshal(name + " has been removed from the list of chart repositories.") util.LogHandlerExitWithJSON(handler, w, msg, http.StatusOK) return nil } diff --git a/cmd/manager/manager/manager.go b/cmd/manager/manager/manager.go index 435ad9a2d..6649738db 100644 --- a/cmd/manager/manager/manager.go +++ b/cmd/manager/manager/manager.go @@ -377,8 +377,12 @@ func (m *manager) AddChartRepo(addition repo.IRepo) error { } // RemoveChartRepo removes a chart repository from the list by URL -func (m *manager) RemoveChartRepo(URL string) error { - return m.service.DeleteRepo(URL) +func (m *manager) RemoveChartRepo(name string) error { + url, err := m.service.GetRepoURLByName(name) + if err != nil { + return err + } + return m.service.DeleteRepo(url) } // GetChartRepo returns the chart repository with the given URL diff --git a/pkg/repo/inmem_repo_service.go b/pkg/repo/inmem_repo_service.go index 0904233ba..902320e74 100644 --- a/pkg/repo/inmem_repo_service.go +++ b/pkg/repo/inmem_repo_service.go @@ -117,3 +117,13 @@ func (rs *inmemRepoService) DeleteRepo(URL string) error { delete(rs.repositories, URL) return nil } + +func (rs *inmemRepoService) GetRepoURLByName(name string) (string, error) { + for url, r := range rs.repositories { + if r.GetName() == name { + return url, nil + } + } + err := fmt.Errorf("No repository url found with name %s", name) + return "", err +} diff --git a/pkg/repo/types.go b/pkg/repo/types.go index 3579e6f9c..497f653cd 100644 --- a/pkg/repo/types.go +++ b/pkg/repo/types.go @@ -123,6 +123,8 @@ type IRepoService interface { CreateRepo(repository IRepo) error // GetRepoByURL returns the repository with the given name GetRepoByURL(name string) (IRepo, error) + // GetRepoURLByName return url for a repository with the given name + GetRepoURLByName(name string) (string, error) // GetRepoByChartURL returns the repository that backs the given URL GetRepoByChartURL(URL string) (IRepo, error) // DeleteRepo removes a known repository from the list