From 390217d416537d3ca7abd7d2d0b4d0fd3d64aebe Mon Sep 17 00:00:00 2001 From: Adam Reese Date: Wed, 15 Mar 2017 22:00:43 -0700 Subject: [PATCH] ref(helmpath): simplify path building of helmpath --- pkg/helm/helmpath/helmhome.go | 26 +++++++++++++++++--------- 1 file changed, 17 insertions(+), 9 deletions(-) diff --git a/pkg/helm/helmpath/helmhome.go b/pkg/helm/helmpath/helmhome.go index 03f65c6bb..3063d5876 100644 --- a/pkg/helm/helmpath/helmhome.go +++ b/pkg/helm/helmpath/helmhome.go @@ -32,30 +32,37 @@ func (h Home) String() string { return string(h) } +// Path returns Home with elements appended. +func (h Home) Path(elem ...string) string { + p := []string{string(h)} + p = append(p, elem...) + return filepath.Join(p...) +} + // Repository returns the path to the local repository. func (h Home) Repository() string { - return filepath.Join(string(h), "repository") + return h.Path("repository") } // RepositoryFile returns the path to the repositories.yaml file. func (h Home) RepositoryFile() string { - return filepath.Join(string(h), "repository/repositories.yaml") + return h.Path("repository", "repositories.yaml") } // Cache returns the path to the local cache. func (h Home) Cache() string { - return filepath.Join(string(h), "repository/cache") + return h.Path("repository", "cache") } // CacheIndex returns the path to an index for the given named repository. func (h Home) CacheIndex(name string) string { target := fmt.Sprintf("repository/cache/%s-index.yaml", name) - return filepath.Join(string(h), target) + return h.Path(target) } // Starters returns the path to the Helm starter packs. func (h Home) Starters() string { - return filepath.Join(string(h), "starters") + return h.Path("starters") } // LocalRepository returns the location to the local repo. @@ -63,12 +70,13 @@ func (h Home) Starters() string { // The local repo is the one used by 'helm serve' // // If additional path elements are passed, they are appended to the returned path. -func (h Home) LocalRepository(paths ...string) string { - frag := append([]string{string(h), "repository/local"}, paths...) - return filepath.Join(frag...) +func (h Home) LocalRepository(elem ...string) string { + p := []string{"repository", "local"} + p = append(p, elem...) + return h.Path(p...) } // Plugins returns the path to the plugins directory. func (h Home) Plugins() string { - return filepath.Join(string(h), "plugins") + return h.Path("plugins") }