From 174961ab6acc38bdc99d683f2f78310a7a4a0ce2 Mon Sep 17 00:00:00 2001 From: Michelle Noorali Date: Thu, 24 Mar 2016 14:06:18 -0600 Subject: [PATCH] feat(repo): list repo name and url * + fix addRepo --- cmd/helm/repository.go | 11 +++++++---- cmd/manager/manager/manager.go | 4 ++-- cmd/manager/testutil.go | 4 ++-- pkg/repo/inmem_repo_service.go | 6 +++--- pkg/repo/types.go | 2 +- 5 files changed, 15 insertions(+), 12 deletions(-) diff --git a/cmd/helm/repository.go b/cmd/helm/repository.go index c79105544..37f7709e4 100644 --- a/cmd/helm/repository.go +++ b/cmd/helm/repository.go @@ -66,19 +66,19 @@ func addRepo(c *cli.Context) error { return errors.New("'helm repo add' requires a name and repository url as arguments") } name := args[0] - repoURL := args[0] + repoURL := args[1] payload, _ := json.Marshal(repo.Repo{URL: repoURL, Name: name}) msg := "" if _, err := NewClient(c).Post(chartRepoPath, payload, &msg); err != nil { //TODO: Return more specific errors to the user return err } - format.Info(repoURL + " has been added to your chart repositories!") + format.Info(name + " has been added to your chart repositories!") return nil } func listRepos(c *cli.Context) error { - dest := []string{} + dest := map[string]string{} if _, err := NewClient(c).Get(chartRepoPath, &dest); err != nil { return err } @@ -87,7 +87,10 @@ func listRepos(c *cli.Context) error { format.Info("Add a chart repository using the `helm repo add [REPOSITORY_URL]` command.") } else { format.Msg("Chart Repositories:\n") - format.List(dest) + for k, v := range dest { + //TODO: make formatting pretty + format.Msg(k + "\t" + v + "\n") + } } return nil } diff --git a/cmd/manager/manager/manager.go b/cmd/manager/manager/manager.go index 9edf38ce3..435ad9a2d 100644 --- a/cmd/manager/manager/manager.go +++ b/cmd/manager/manager/manager.go @@ -58,7 +58,7 @@ type Manager interface { GetCredential(name string) (*repo.Credential, error) // Chart Repositories - ListChartRepos() ([]string, error) + ListChartRepos() (map[string]string, error) AddChartRepo(addition repo.IRepo) error RemoveChartRepo(name string) error GetChartRepo(URL string) (repo.IRepo, error) @@ -367,7 +367,7 @@ func (m *manager) GetChart(reference string) (*chart.Chart, error) { } // ListChartRepos returns the list of available chart repository URLs -func (m *manager) ListChartRepos() ([]string, error) { +func (m *manager) ListChartRepos() (map[string]string, error) { return m.service.ListRepos() } diff --git a/cmd/manager/testutil.go b/cmd/manager/testutil.go index aa500123d..1114a3d34 100644 --- a/cmd/manager/testutil.go +++ b/cmd/manager/testutil.go @@ -95,8 +95,8 @@ func (m *mockManager) AddChartRepo(addition repo.IRepo) error { return nil } -func (m *mockManager) ListChartRepos() ([]string, error) { - return []string{}, nil +func (m *mockManager) ListChartRepos() (map[string]string, error) { + return map[string]string{}, nil } func (m *mockManager) RemoveChartRepo(name string) error { diff --git a/pkg/repo/inmem_repo_service.go b/pkg/repo/inmem_repo_service.go index 6fa91247d..0904233ba 100644 --- a/pkg/repo/inmem_repo_service.go +++ b/pkg/repo/inmem_repo_service.go @@ -42,13 +42,13 @@ func NewInmemRepoService() IRepoService { } // ListRepos returns the list of all known chart repositories -func (rs *inmemRepoService) ListRepos() ([]string, error) { +func (rs *inmemRepoService) ListRepos() (map[string]string, error) { rs.RLock() defer rs.RUnlock() - ret := []string{} + ret := make(map[string]string) for _, r := range rs.repositories { - ret = append(ret, r.GetURL()) + ret[r.GetName()] = r.GetURL() } return ret, nil diff --git a/pkg/repo/types.go b/pkg/repo/types.go index 55d248374..3579e6f9c 100644 --- a/pkg/repo/types.go +++ b/pkg/repo/types.go @@ -118,7 +118,7 @@ type IStorageRepo interface { // repository based operations, such as search and chart reference resolution. type IRepoService interface { // ListRepos returns the list of all known chart repositories - ListRepos() ([]string, error) + ListRepos() (map[string]string, error) // CreateRepo adds a known repository to the list CreateRepo(repository IRepo) error // GetRepoByURL returns the repository with the given name