feat(repo): remove repo by name

pull/448/head
Michelle Noorali 9 years ago
parent 174961ab6a
commit e86b8db694

@ -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
}

@ -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
}

@ -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

@ -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
}

@ -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

Loading…
Cancel
Save