github.com/uhthomas/helm@v3.0.0-beta.3+incompatible/pkg/helmpath/lazypath.go (about) 1 // Copyright The Helm Authors. 2 // Licensed under the Apache License, Version 2.0 (the "License"); 3 // you may not use this file except in compliance with the License. 4 // You may obtain a copy of the License at 5 6 // http://www.apache.org/licenses/LICENSE-2.0 7 8 // Unless required by applicable law or agreed to in writing, software 9 // distributed under the License is distributed on an "AS IS" BASIS, 10 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 11 // See the License for the specific language governing permissions and 12 // limitations under the License. 13 package helmpath 14 15 import ( 16 "os" 17 "path/filepath" 18 19 "helm.sh/helm/pkg/helmpath/xdg" 20 ) 21 22 // lazypath is an lazy-loaded path buffer for the XDG base directory specification. 23 type lazypath string 24 25 func (l lazypath) path(envVar string, defaultFn func() string, elem ...string) string { 26 base := os.Getenv(envVar) 27 if base == "" { 28 base = defaultFn() 29 } 30 return filepath.Join(base, string(l), filepath.Join(elem...)) 31 } 32 33 // cachePath defines the base directory relative to which user specific non-essential data files 34 // should be stored. 35 func (l lazypath) cachePath(elem ...string) string { 36 return l.path(xdg.CacheHomeEnvVar, cacheHome, filepath.Join(elem...)) 37 } 38 39 // configPath defines the base directory relative to which user specific configuration files should 40 // be stored. 41 func (l lazypath) configPath(elem ...string) string { 42 return l.path(xdg.ConfigHomeEnvVar, configHome, filepath.Join(elem...)) 43 } 44 45 // dataPath defines the base directory relative to which user specific data files should be stored. 46 func (l lazypath) dataPath(elem ...string) string { 47 return l.path(xdg.DataHomeEnvVar, dataHome, filepath.Join(elem...)) 48 }