mirror of https://github.com/helm/helm
Signed-off-by: Matthew Fisher <matt.fisher@microsoft.com>pull/5443/head
parent
d360705c83
commit
c728611e5a
@ -1,52 +0,0 @@
|
|||||||
/*
|
|
||||||
Copyright The Helm Authors.
|
|
||||||
|
|
||||||
Licensed under the Apache License, Version 2.0 (the "License");
|
|
||||||
you may not use this file except in compliance with the License.
|
|
||||||
You may obtain a copy of the License at
|
|
||||||
|
|
||||||
http://www.apache.org/licenses/LICENSE-2.0
|
|
||||||
|
|
||||||
Unless required by applicable law or agreed to in writing, software
|
|
||||||
distributed under the License is distributed on an "AS IS" BASIS,
|
|
||||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
||||||
See the License for the specific language governing permissions and
|
|
||||||
limitations under the License.
|
|
||||||
*/
|
|
||||||
|
|
||||||
package main
|
|
||||||
|
|
||||||
import (
|
|
||||||
"fmt"
|
|
||||||
"io"
|
|
||||||
|
|
||||||
"github.com/spf13/cobra"
|
|
||||||
|
|
||||||
"helm.sh/helm/cmd/helm/require"
|
|
||||||
)
|
|
||||||
|
|
||||||
var longHomeHelp = `
|
|
||||||
This command displays the location of HELM_HOME. This is where
|
|
||||||
any helm configuration files live.
|
|
||||||
`
|
|
||||||
|
|
||||||
func newHomeCmd(out io.Writer) *cobra.Command {
|
|
||||||
cmd := &cobra.Command{
|
|
||||||
Use: "home",
|
|
||||||
Short: "displays the location of HELM_HOME",
|
|
||||||
Long: longHomeHelp,
|
|
||||||
Args: require.NoArgs,
|
|
||||||
Run: func(cmd *cobra.Command, args []string) {
|
|
||||||
h := settings.Home
|
|
||||||
fmt.Fprintln(out, h)
|
|
||||||
if settings.Debug {
|
|
||||||
fmt.Fprintf(out, "Repository: %s\n", h.Repository())
|
|
||||||
fmt.Fprintf(out, "RepositoryFile: %s\n", h.RepositoryFile())
|
|
||||||
fmt.Fprintf(out, "Cache: %s\n", h.Cache())
|
|
||||||
fmt.Fprintf(out, "Starters: %s\n", h.Starters())
|
|
||||||
fmt.Fprintf(out, "Plugins: %s\n", h.Plugins())
|
|
||||||
}
|
|
||||||
},
|
|
||||||
}
|
|
||||||
return cmd
|
|
||||||
}
|
|
@ -0,0 +1,79 @@
|
|||||||
|
/*
|
||||||
|
Copyright The Helm Authors.
|
||||||
|
|
||||||
|
Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
you may not use this file except in compliance with the License.
|
||||||
|
You may obtain a copy of the License at
|
||||||
|
|
||||||
|
http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
|
||||||
|
Unless required by applicable law or agreed to in writing, software
|
||||||
|
distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
See the License for the specific language governing permissions and
|
||||||
|
limitations under the License.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package main
|
||||||
|
|
||||||
|
import (
|
||||||
|
"fmt"
|
||||||
|
"io"
|
||||||
|
|
||||||
|
"github.com/spf13/cobra"
|
||||||
|
|
||||||
|
"helm.sh/helm/cmd/helm/require"
|
||||||
|
"helm.sh/helm/pkg/helmpath"
|
||||||
|
)
|
||||||
|
|
||||||
|
var longPathHelp = `
|
||||||
|
This command displays the locations where Helm stores files.
|
||||||
|
|
||||||
|
To display a specific location, use 'helm path [config|data|cache]'.
|
||||||
|
`
|
||||||
|
|
||||||
|
var pathArgMap = map[string]string{
|
||||||
|
"config": helmpath.ConfigPath(),
|
||||||
|
"data": helmpath.DataPath(),
|
||||||
|
"cache": helmpath.CachePath(),
|
||||||
|
}
|
||||||
|
|
||||||
|
func newPathCmd(out io.Writer) *cobra.Command {
|
||||||
|
cmd := &cobra.Command{
|
||||||
|
Use: "path",
|
||||||
|
Short: "displays the locations where Helm stores files",
|
||||||
|
Aliases: []string{"home"},
|
||||||
|
Long: longPathHelp,
|
||||||
|
Args: require.MinimumNArgs(0),
|
||||||
|
RunE: func(cmd *cobra.Command, args []string) error {
|
||||||
|
if len(args) > 0 {
|
||||||
|
if p, ok := pathArgMap[args[0]]; ok {
|
||||||
|
fmt.Fprintln(out, p)
|
||||||
|
} else {
|
||||||
|
var validArgs []string
|
||||||
|
for arg := range pathArgMap {
|
||||||
|
validArgs = append(validArgs, arg)
|
||||||
|
}
|
||||||
|
return fmt.Errorf("invalid argument '%s'. Must be one of: %s", args[0], validArgs)
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
// NOTE(bacongobbler): the order here is important: we want to display the config path
|
||||||
|
// first so users can parse the first line to replicate Helm 2's `helm home`.
|
||||||
|
fmt.Fprintln(out, helmpath.ConfigPath())
|
||||||
|
fmt.Fprintln(out, helmpath.DataPath())
|
||||||
|
fmt.Fprintln(out, helmpath.CachePath())
|
||||||
|
if settings.Debug {
|
||||||
|
fmt.Fprintf(out, "Archive: %s\n", helmpath.Archive())
|
||||||
|
fmt.Fprintf(out, "PluginCache: %s\n", helmpath.PluginCache())
|
||||||
|
fmt.Fprintf(out, "Plugins: %s\n", helmpath.Plugins())
|
||||||
|
fmt.Fprintf(out, "Registry: %s\n", helmpath.Registry())
|
||||||
|
fmt.Fprintf(out, "RepositoryCache: %s\n", helmpath.RepositoryCache())
|
||||||
|
fmt.Fprintf(out, "RepositoryFile: %s\n", helmpath.RepositoryFile())
|
||||||
|
fmt.Fprintf(out, "Starters: %s\n", helmpath.Starters())
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
},
|
||||||
|
}
|
||||||
|
return cmd
|
||||||
|
}
|
@ -1,4 +1,4 @@
|
|||||||
name: env
|
name: env
|
||||||
usage: "env stuff"
|
usage: "env stuff"
|
||||||
description: "show the env"
|
description: "show the env"
|
||||||
command: "echo $HELM_HOME"
|
command: "echo $HELM_PATH_CONFIG"
|
@ -0,0 +1,84 @@
|
|||||||
|
/*
|
||||||
|
Copyright The Helm Authors.
|
||||||
|
|
||||||
|
Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
you may not use this file except in compliance with the License.
|
||||||
|
You may obtain a copy of the License at
|
||||||
|
|
||||||
|
http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
|
||||||
|
Unless required by applicable law or agreed to in writing, software
|
||||||
|
distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
See the License for the specific language governing permissions and
|
||||||
|
limitations under the License.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package ensure
|
||||||
|
|
||||||
|
import (
|
||||||
|
"io/ioutil"
|
||||||
|
"os"
|
||||||
|
"testing"
|
||||||
|
|
||||||
|
"helm.sh/helm/pkg/helmpath"
|
||||||
|
"helm.sh/helm/pkg/helmpath/xdg"
|
||||||
|
)
|
||||||
|
|
||||||
|
// HelmHome sets up a Helm Home in a temp dir.
|
||||||
|
func HelmHome(t *testing.T) {
|
||||||
|
t.Helper()
|
||||||
|
cachePath := TempDir(t)
|
||||||
|
configPath := TempDir(t)
|
||||||
|
dataPath := TempDir(t)
|
||||||
|
os.Setenv(xdg.CacheHomeEnvVar, cachePath)
|
||||||
|
os.Setenv(xdg.ConfigHomeEnvVar, configPath)
|
||||||
|
os.Setenv(xdg.DataHomeEnvVar, dataPath)
|
||||||
|
HomeDirs(t)
|
||||||
|
}
|
||||||
|
|
||||||
|
// HomeDirs creates a home directory like ensureHome, but without remote references.
|
||||||
|
func HomeDirs(t *testing.T) {
|
||||||
|
t.Helper()
|
||||||
|
for _, p := range []string{
|
||||||
|
helmpath.CachePath(),
|
||||||
|
helmpath.ConfigPath(),
|
||||||
|
helmpath.DataPath(),
|
||||||
|
helmpath.RepositoryCache(),
|
||||||
|
helmpath.Plugins(),
|
||||||
|
helmpath.PluginCache(),
|
||||||
|
helmpath.Starters(),
|
||||||
|
} {
|
||||||
|
if err := os.MkdirAll(p, 0755); err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// CleanHomeDirs removes the directories created by HomeDirs.
|
||||||
|
func CleanHomeDirs(t *testing.T) {
|
||||||
|
t.Helper()
|
||||||
|
for _, p := range []string{
|
||||||
|
helmpath.CachePath(),
|
||||||
|
helmpath.ConfigPath(),
|
||||||
|
helmpath.DataPath(),
|
||||||
|
helmpath.RepositoryCache(),
|
||||||
|
helmpath.Plugins(),
|
||||||
|
helmpath.PluginCache(),
|
||||||
|
helmpath.Starters(),
|
||||||
|
} {
|
||||||
|
if err := os.RemoveAll(p); err != nil {
|
||||||
|
t.Log(err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// TempDir ensures a scratch test directory for unit testing purposes.
|
||||||
|
func TempDir(t *testing.T) string {
|
||||||
|
t.Helper()
|
||||||
|
d, err := ioutil.TempDir("", "helm")
|
||||||
|
if err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
return d
|
||||||
|
}
|
@ -1,82 +0,0 @@
|
|||||||
/*
|
|
||||||
Copyright The Helm Authors.
|
|
||||||
Licensed under the Apache License, Version 2.0 (the "License");
|
|
||||||
you may not use this file except in compliance with the License.
|
|
||||||
You may obtain a copy of the License at
|
|
||||||
|
|
||||||
http://www.apache.org/licenses/LICENSE-2.0
|
|
||||||
|
|
||||||
Unless required by applicable law or agreed to in writing, software
|
|
||||||
distributed under the License is distributed on an "AS IS" BASIS,
|
|
||||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
||||||
See the License for the specific language governing permissions and
|
|
||||||
limitations under the License.
|
|
||||||
*/
|
|
||||||
|
|
||||||
package helmpath
|
|
||||||
|
|
||||||
import (
|
|
||||||
"fmt"
|
|
||||||
"os"
|
|
||||||
"path/filepath"
|
|
||||||
)
|
|
||||||
|
|
||||||
// Home describes the location of a CLI configuration.
|
|
||||||
//
|
|
||||||
// This helper builds paths relative to a Helm Home directory.
|
|
||||||
type Home string
|
|
||||||
|
|
||||||
// String returns Home as a string.
|
|
||||||
//
|
|
||||||
// Implements fmt.Stringer.
|
|
||||||
func (h Home) String() string {
|
|
||||||
return os.ExpandEnv(string(h))
|
|
||||||
}
|
|
||||||
|
|
||||||
// Path returns Home with elements appended.
|
|
||||||
func (h Home) Path(elem ...string) string {
|
|
||||||
p := []string{h.String()}
|
|
||||||
p = append(p, elem...)
|
|
||||||
return filepath.Join(p...)
|
|
||||||
}
|
|
||||||
|
|
||||||
// Registry returns the path to the local registry cache.
|
|
||||||
func (h Home) Registry() string {
|
|
||||||
return h.Path("registry")
|
|
||||||
}
|
|
||||||
|
|
||||||
// Repository returns the path to the local repository.
|
|
||||||
func (h Home) Repository() string {
|
|
||||||
return h.Path("repository")
|
|
||||||
}
|
|
||||||
|
|
||||||
// RepositoryFile returns the path to the repositories.yaml file.
|
|
||||||
func (h Home) RepositoryFile() string {
|
|
||||||
return h.Path("repository", "repositories.yaml")
|
|
||||||
}
|
|
||||||
|
|
||||||
// Cache returns the path to the local cache.
|
|
||||||
func (h Home) Cache() string {
|
|
||||||
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("%s-index.yaml", name)
|
|
||||||
return h.Path("repository", "cache", target)
|
|
||||||
}
|
|
||||||
|
|
||||||
// Starters returns the path to the Helm starter packs.
|
|
||||||
func (h Home) Starters() string {
|
|
||||||
return h.Path("starters")
|
|
||||||
}
|
|
||||||
|
|
||||||
// Plugins returns the path to the plugins directory.
|
|
||||||
func (h Home) Plugins() string {
|
|
||||||
return h.Path("plugins")
|
|
||||||
}
|
|
||||||
|
|
||||||
// Archive returns the path to download chart archives.
|
|
||||||
func (h Home) Archive() string {
|
|
||||||
return h.Path("cache", "archive")
|
|
||||||
}
|
|
@ -1,47 +0,0 @@
|
|||||||
// Copyright The Helm Authors.
|
|
||||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
||||||
// you may not use this file except in compliance with the License.
|
|
||||||
// You may obtain a copy of the License at
|
|
||||||
//
|
|
||||||
// http://www.apache.org/licenses/LICENSE-2.0
|
|
||||||
//
|
|
||||||
// Unless required by applicable law or agreed to in writing, software
|
|
||||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
||||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
||||||
// See the License for the specific language governing permissions and
|
|
||||||
// limitations under the License.
|
|
||||||
|
|
||||||
// +build darwin dragonfly freebsd linux nacl netbsd openbsd solaris
|
|
||||||
// +build !windows
|
|
||||||
|
|
||||||
package helmpath
|
|
||||||
|
|
||||||
import (
|
|
||||||
"runtime"
|
|
||||||
"testing"
|
|
||||||
)
|
|
||||||
|
|
||||||
func TestHelmHome(t *testing.T) {
|
|
||||||
hh := Home("/r/users/helmtest")
|
|
||||||
isEq := func(t *testing.T, a, b string) {
|
|
||||||
if a != b {
|
|
||||||
t.Error(runtime.GOOS)
|
|
||||||
t.Errorf("Expected %q, got %q", a, b)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
isEq(t, hh.String(), "/r/users/helmtest")
|
|
||||||
isEq(t, hh.Registry(), "/r/users/helmtest/registry")
|
|
||||||
isEq(t, hh.Repository(), "/r/users/helmtest/repository")
|
|
||||||
isEq(t, hh.RepositoryFile(), "/r/users/helmtest/repository/repositories.yaml")
|
|
||||||
isEq(t, hh.Cache(), "/r/users/helmtest/repository/cache")
|
|
||||||
isEq(t, hh.CacheIndex("t"), "/r/users/helmtest/repository/cache/t-index.yaml")
|
|
||||||
isEq(t, hh.Starters(), "/r/users/helmtest/starters")
|
|
||||||
isEq(t, hh.Archive(), "/r/users/helmtest/cache/archive")
|
|
||||||
}
|
|
||||||
|
|
||||||
func TestHelmHome_expand(t *testing.T) {
|
|
||||||
if Home("$HOME").String() == "$HOME" {
|
|
||||||
t.Error("expected variable expansion")
|
|
||||||
}
|
|
||||||
}
|
|
@ -0,0 +1,81 @@
|
|||||||
|
// Copyright The Helm Authors.
|
||||||
|
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
// you may not use this file except in compliance with the License.
|
||||||
|
// You may obtain a copy of the License at
|
||||||
|
|
||||||
|
// http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
|
||||||
|
// Unless required by applicable law or agreed to in writing, software
|
||||||
|
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
// See the License for the specific language governing permissions and
|
||||||
|
// limitations under the License.
|
||||||
|
|
||||||
|
package helmpath
|
||||||
|
|
||||||
|
import (
|
||||||
|
"fmt"
|
||||||
|
"path/filepath"
|
||||||
|
)
|
||||||
|
|
||||||
|
// This helper builds paths to Helm's configuration, cache and data paths.
|
||||||
|
var lp = lazypath{name: "helm"}
|
||||||
|
|
||||||
|
// ConfigPath returns the path where Helm stores configuration.
|
||||||
|
func ConfigPath() string {
|
||||||
|
return lp.configPath("")
|
||||||
|
}
|
||||||
|
|
||||||
|
// CachePath returns the path where Helm stores cached objects.
|
||||||
|
func CachePath() string {
|
||||||
|
return lp.cachePath("")
|
||||||
|
}
|
||||||
|
|
||||||
|
// DataPath returns the path where Helm stores data.
|
||||||
|
func DataPath() string {
|
||||||
|
return lp.dataPath("")
|
||||||
|
}
|
||||||
|
|
||||||
|
// Registry returns the path to the local registry cache.
|
||||||
|
func Registry() string {
|
||||||
|
return lp.cachePath("registry")
|
||||||
|
}
|
||||||
|
|
||||||
|
// RepositoryFile returns the path to the repositories.yaml file.
|
||||||
|
func RepositoryFile() string {
|
||||||
|
return lp.configPath("repositories.yaml")
|
||||||
|
}
|
||||||
|
|
||||||
|
// RepositoryCache returns the cache path for repository metadata.
|
||||||
|
func RepositoryCache() string {
|
||||||
|
return lp.cachePath("repository")
|
||||||
|
}
|
||||||
|
|
||||||
|
// CacheIndex returns the path to an index for the given named repository.
|
||||||
|
func CacheIndex(name string) string {
|
||||||
|
target := fmt.Sprintf("%s-index.yaml", name)
|
||||||
|
if name == "" {
|
||||||
|
target = "index.yaml"
|
||||||
|
}
|
||||||
|
return filepath.Join(RepositoryCache(), target)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Starters returns the path to the Helm starter packs.
|
||||||
|
func Starters() string {
|
||||||
|
return lp.dataPath("starters")
|
||||||
|
}
|
||||||
|
|
||||||
|
// PluginCache returns the cache path for plugins.
|
||||||
|
func PluginCache() string {
|
||||||
|
return lp.cachePath("plugins")
|
||||||
|
}
|
||||||
|
|
||||||
|
// Plugins returns the path to the plugins directory.
|
||||||
|
func Plugins() string {
|
||||||
|
return lp.dataPath("plugins")
|
||||||
|
}
|
||||||
|
|
||||||
|
// Archive returns the path to download chart archives.
|
||||||
|
func Archive() string {
|
||||||
|
return lp.cachePath("archive")
|
||||||
|
}
|
@ -0,0 +1,52 @@
|
|||||||
|
// Copyright The Helm Authors.
|
||||||
|
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
// you may not use this file except in compliance with the License.
|
||||||
|
// You may obtain a copy of the License at
|
||||||
|
//
|
||||||
|
// http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
//
|
||||||
|
// Unless required by applicable law or agreed to in writing, software
|
||||||
|
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
// See the License for the specific language governing permissions and
|
||||||
|
// limitations under the License.
|
||||||
|
|
||||||
|
// +build !windows
|
||||||
|
|
||||||
|
package helmpath
|
||||||
|
|
||||||
|
import (
|
||||||
|
"os"
|
||||||
|
"runtime"
|
||||||
|
"testing"
|
||||||
|
|
||||||
|
"helm.sh/helm/pkg/helmpath/xdg"
|
||||||
|
)
|
||||||
|
|
||||||
|
func TestHelmHome(t *testing.T) {
|
||||||
|
os.Setenv(xdg.CacheHomeEnvVar, "/cache")
|
||||||
|
os.Setenv(xdg.ConfigHomeEnvVar, "/config")
|
||||||
|
os.Setenv(xdg.DataHomeEnvVar, "/data")
|
||||||
|
isEq := func(t *testing.T, got, expected string) {
|
||||||
|
t.Helper()
|
||||||
|
if expected != got {
|
||||||
|
t.Error(runtime.GOOS)
|
||||||
|
t.Errorf("Expected %q, got %q", expected, got)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
isEq(t, CachePath(), "/cache/helm")
|
||||||
|
isEq(t, ConfigPath(), "/config/helm")
|
||||||
|
isEq(t, DataPath(), "/data/helm")
|
||||||
|
isEq(t, RepositoryFile(), "/config/helm/repositories.yaml")
|
||||||
|
isEq(t, RepositoryCache(), "/cache/helm/repository")
|
||||||
|
isEq(t, CacheIndex("t"), "/cache/helm/repository/t-index.yaml")
|
||||||
|
isEq(t, CacheIndex(""), "/cache/helm/repository/index.yaml")
|
||||||
|
isEq(t, Starters(), "/data/helm/starters")
|
||||||
|
isEq(t, Archive(), "/cache/helm/archive")
|
||||||
|
|
||||||
|
// test to see if lazy-loading environment variables at runtime works
|
||||||
|
os.Setenv(xdg.CacheHomeEnvVar, "/cache2")
|
||||||
|
|
||||||
|
isEq(t, CachePath(), "/cache2/helm")
|
||||||
|
}
|
@ -0,0 +1,52 @@
|
|||||||
|
// Copyright The Helm Authors.
|
||||||
|
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
// you may not use this file except in compliance with the License.
|
||||||
|
// You may obtain a copy of the License at
|
||||||
|
|
||||||
|
// http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
|
||||||
|
// Unless required by applicable law or agreed to in writing, software
|
||||||
|
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
// See the License for the specific language governing permissions and
|
||||||
|
// limitations under the License.
|
||||||
|
package helmpath
|
||||||
|
|
||||||
|
import (
|
||||||
|
"os"
|
||||||
|
"path/filepath"
|
||||||
|
|
||||||
|
"helm.sh/helm/pkg/helmpath/xdg"
|
||||||
|
)
|
||||||
|
|
||||||
|
// lazypath is an lazy-loaded path buffer for the XDG base directory specification.
|
||||||
|
//
|
||||||
|
// name is the base name of the application referenced in the base directories.
|
||||||
|
type lazypath struct {
|
||||||
|
name string
|
||||||
|
}
|
||||||
|
|
||||||
|
func (l lazypath) path(envVar string, defaultFn func() string, file string) string {
|
||||||
|
base := os.Getenv(envVar)
|
||||||
|
if base == "" {
|
||||||
|
base = defaultFn()
|
||||||
|
}
|
||||||
|
return filepath.Join(base, l.name, file)
|
||||||
|
}
|
||||||
|
|
||||||
|
// cachePath defines the base directory relative to which user specific non-essential data files
|
||||||
|
// should be stored.
|
||||||
|
func (l lazypath) cachePath(file string) string {
|
||||||
|
return l.path(xdg.CacheHomeEnvVar, cacheHome, file)
|
||||||
|
}
|
||||||
|
|
||||||
|
// configPath defines the base directory relative to which user specific configuration files should
|
||||||
|
// be stored.
|
||||||
|
func (l lazypath) configPath(file string) string {
|
||||||
|
return l.path(xdg.ConfigHomeEnvVar, configHome, file)
|
||||||
|
}
|
||||||
|
|
||||||
|
// dataPath defines the base directory relative to which user specific data files should be stored.
|
||||||
|
func (l lazypath) dataPath(file string) string {
|
||||||
|
return l.path(xdg.DataHomeEnvVar, dataHome, file)
|
||||||
|
}
|
@ -0,0 +1,34 @@
|
|||||||
|
// Copyright The Helm Authors.
|
||||||
|
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
// you may not use this file except in compliance with the License.
|
||||||
|
// You may obtain a copy of the License at
|
||||||
|
|
||||||
|
// http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
|
||||||
|
// Unless required by applicable law or agreed to in writing, software
|
||||||
|
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
// See the License for the specific language governing permissions and
|
||||||
|
// limitations under the License.
|
||||||
|
|
||||||
|
// +build darwin
|
||||||
|
|
||||||
|
package helmpath
|
||||||
|
|
||||||
|
import (
|
||||||
|
"path/filepath"
|
||||||
|
|
||||||
|
"k8s.io/client-go/util/homedir"
|
||||||
|
)
|
||||||
|
|
||||||
|
func dataHome() string {
|
||||||
|
return filepath.Join(homedir.HomeDir(), "Library")
|
||||||
|
}
|
||||||
|
|
||||||
|
func configHome() string {
|
||||||
|
return filepath.Join(homedir.HomeDir(), "Library", "Preferences")
|
||||||
|
}
|
||||||
|
|
||||||
|
func cacheHome() string {
|
||||||
|
return filepath.Join(homedir.HomeDir(), "Library", "Caches")
|
||||||
|
}
|
@ -0,0 +1,86 @@
|
|||||||
|
// Copyright The Helm Authors.
|
||||||
|
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
// you may not use this file except in compliance with the License.
|
||||||
|
// You may obtain a copy of the License at
|
||||||
|
|
||||||
|
// http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
|
||||||
|
// Unless required by applicable law or agreed to in writing, software
|
||||||
|
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
// See the License for the specific language governing permissions and
|
||||||
|
// limitations under the License.
|
||||||
|
|
||||||
|
// +build darwin
|
||||||
|
|
||||||
|
package helmpath
|
||||||
|
|
||||||
|
import (
|
||||||
|
"os"
|
||||||
|
"path/filepath"
|
||||||
|
"testing"
|
||||||
|
|
||||||
|
"helm.sh/helm/pkg/helmpath/xdg"
|
||||||
|
"k8s.io/client-go/util/homedir"
|
||||||
|
)
|
||||||
|
|
||||||
|
const (
|
||||||
|
appName string = "helm"
|
||||||
|
testFile string = "test.txt"
|
||||||
|
)
|
||||||
|
|
||||||
|
var lazy = lazypath{name: appName}
|
||||||
|
|
||||||
|
func TestDataPath(t *testing.T) {
|
||||||
|
os.Unsetenv(xdg.DataHomeEnvVar)
|
||||||
|
|
||||||
|
expected := filepath.Join(homedir.HomeDir(), "Library", appName, testFile)
|
||||||
|
|
||||||
|
if lazy.dataPath(testFile) != expected {
|
||||||
|
t.Errorf("expected '%s', got '%s'", expected, lazy.dataPath(testFile))
|
||||||
|
}
|
||||||
|
|
||||||
|
os.Setenv(xdg.DataHomeEnvVar, "/tmp")
|
||||||
|
|
||||||
|
expected = filepath.Join("/tmp", appName, testFile)
|
||||||
|
|
||||||
|
if lazy.dataPath(testFile) != expected {
|
||||||
|
t.Errorf("expected '%s', got '%s'", expected, lazy.dataPath(testFile))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestConfigPath(t *testing.T) {
|
||||||
|
os.Unsetenv(xdg.ConfigHomeEnvVar)
|
||||||
|
|
||||||
|
expected := filepath.Join(homedir.HomeDir(), "Library", "Preferences", appName, testFile)
|
||||||
|
|
||||||
|
if lazy.configPath(testFile) != expected {
|
||||||
|
t.Errorf("expected '%s', got '%s'", expected, lazy.configPath(testFile))
|
||||||
|
}
|
||||||
|
|
||||||
|
os.Setenv(xdg.ConfigHomeEnvVar, "/tmp")
|
||||||
|
|
||||||
|
expected = filepath.Join("/tmp", appName, testFile)
|
||||||
|
|
||||||
|
if lazy.configPath(testFile) != expected {
|
||||||
|
t.Errorf("expected '%s', got '%s'", expected, lazy.configPath(testFile))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestCachePath(t *testing.T) {
|
||||||
|
os.Unsetenv(xdg.CacheHomeEnvVar)
|
||||||
|
|
||||||
|
expected := filepath.Join(homedir.HomeDir(), "Library", "Caches", appName, testFile)
|
||||||
|
|
||||||
|
if lazy.cachePath(testFile) != expected {
|
||||||
|
t.Errorf("expected '%s', got '%s'", expected, lazy.cachePath(testFile))
|
||||||
|
}
|
||||||
|
|
||||||
|
os.Setenv(xdg.CacheHomeEnvVar, "/tmp")
|
||||||
|
|
||||||
|
expected = filepath.Join("/tmp", appName, testFile)
|
||||||
|
|
||||||
|
if lazy.cachePath(testFile) != expected {
|
||||||
|
t.Errorf("expected '%s', got '%s'", expected, lazy.cachePath(testFile))
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,45 @@
|
|||||||
|
// Copyright The Helm Authors.
|
||||||
|
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
// you may not use this file except in compliance with the License.
|
||||||
|
// You may obtain a copy of the License at
|
||||||
|
|
||||||
|
// http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
|
||||||
|
// Unless required by applicable law or agreed to in writing, software
|
||||||
|
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
// See the License for the specific language governing permissions and
|
||||||
|
// limitations under the License.
|
||||||
|
|
||||||
|
// +build !windows,!darwin
|
||||||
|
|
||||||
|
package helmpath
|
||||||
|
|
||||||
|
import (
|
||||||
|
"path/filepath"
|
||||||
|
|
||||||
|
"k8s.io/client-go/util/homedir"
|
||||||
|
)
|
||||||
|
|
||||||
|
// dataHome defines the base directory relative to which user specific data files should be stored.
|
||||||
|
//
|
||||||
|
// If $XDG_DATA_HOME is either not set or empty, a default equal to $HOME/.local/share is used.
|
||||||
|
func dataHome() string {
|
||||||
|
return filepath.Join(homedir.HomeDir(), ".local", "share")
|
||||||
|
}
|
||||||
|
|
||||||
|
// configHome defines the base directory relative to which user specific configuration files should
|
||||||
|
// be stored.
|
||||||
|
//
|
||||||
|
// If $XDG_CONFIG_HOME is either not set or empty, a default equal to $HOME/.config is used.
|
||||||
|
func configHome() string {
|
||||||
|
return filepath.Join(homedir.HomeDir(), ".config")
|
||||||
|
}
|
||||||
|
|
||||||
|
// cacheHome defines the base directory relative to which user specific non-essential data files
|
||||||
|
// should be stored.
|
||||||
|
//
|
||||||
|
// If $XDG_CACHE_HOME is either not set or empty, a default equal to $HOME/.cache is used.
|
||||||
|
func cacheHome() string {
|
||||||
|
return filepath.Join(homedir.HomeDir(), ".cache")
|
||||||
|
}
|
@ -0,0 +1,87 @@
|
|||||||
|
// Copyright The Helm Authors.
|
||||||
|
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
// you may not use this file except in compliance with the License.
|
||||||
|
// You may obtain a copy of the License at
|
||||||
|
|
||||||
|
// http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
|
||||||
|
// Unless required by applicable law or agreed to in writing, software
|
||||||
|
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
// See the License for the specific language governing permissions and
|
||||||
|
// limitations under the License.
|
||||||
|
|
||||||
|
// +build !windows,!darwin
|
||||||
|
|
||||||
|
package helmpath
|
||||||
|
|
||||||
|
import (
|
||||||
|
"os"
|
||||||
|
"path/filepath"
|
||||||
|
"testing"
|
||||||
|
|
||||||
|
"k8s.io/client-go/util/homedir"
|
||||||
|
|
||||||
|
"helm.sh/helm/pkg/helmpath/xdg"
|
||||||
|
)
|
||||||
|
|
||||||
|
const (
|
||||||
|
appName string = "helm"
|
||||||
|
testFile string = "test.txt"
|
||||||
|
)
|
||||||
|
|
||||||
|
var lazy = lazypath{name: appName}
|
||||||
|
|
||||||
|
func TestDataPath(t *testing.T) {
|
||||||
|
os.Unsetenv(xdg.DataHomeEnvVar)
|
||||||
|
|
||||||
|
expected := filepath.Join(homedir.HomeDir(), ".local", "share", appName, testFile)
|
||||||
|
|
||||||
|
if lazy.dataPath(testFile) != expected {
|
||||||
|
t.Errorf("expected '%s', got '%s'", expected, lazy.dataPath(testFile))
|
||||||
|
}
|
||||||
|
|
||||||
|
os.Setenv(xdg.DataHomeEnvVar, "/tmp")
|
||||||
|
|
||||||
|
expected = filepath.Join("/tmp", appName, testFile)
|
||||||
|
|
||||||
|
if lazy.dataPath(testFile) != expected {
|
||||||
|
t.Errorf("expected '%s', got '%s'", expected, lazy.dataPath(testFile))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestConfigPath(t *testing.T) {
|
||||||
|
os.Unsetenv(xdg.ConfigHomeEnvVar)
|
||||||
|
|
||||||
|
expected := filepath.Join(homedir.HomeDir(), ".config", appName, testFile)
|
||||||
|
|
||||||
|
if lazy.configPath(testFile) != expected {
|
||||||
|
t.Errorf("expected '%s', got '%s'", expected, lazy.configPath(testFile))
|
||||||
|
}
|
||||||
|
|
||||||
|
os.Setenv(xdg.ConfigHomeEnvVar, "/tmp")
|
||||||
|
|
||||||
|
expected = filepath.Join("/tmp", appName, testFile)
|
||||||
|
|
||||||
|
if lazy.configPath(testFile) != expected {
|
||||||
|
t.Errorf("expected '%s', got '%s'", expected, lazy.configPath(testFile))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestCachePath(t *testing.T) {
|
||||||
|
os.Unsetenv(xdg.CacheHomeEnvVar)
|
||||||
|
|
||||||
|
expected := filepath.Join(homedir.HomeDir(), ".cache", appName, testFile)
|
||||||
|
|
||||||
|
if lazy.cachePath(testFile) != expected {
|
||||||
|
t.Errorf("expected '%s', got '%s'", expected, lazy.cachePath(testFile))
|
||||||
|
}
|
||||||
|
|
||||||
|
os.Setenv(xdg.CacheHomeEnvVar, "/tmp")
|
||||||
|
|
||||||
|
expected = filepath.Join("/tmp", appName, testFile)
|
||||||
|
|
||||||
|
if lazy.cachePath(testFile) != expected {
|
||||||
|
t.Errorf("expected '%s', got '%s'", expected, lazy.cachePath(testFile))
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,30 @@
|
|||||||
|
// Copyright The Helm Authors.
|
||||||
|
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
// you may not use this file except in compliance with the License.
|
||||||
|
// You may obtain a copy of the License at
|
||||||
|
|
||||||
|
// http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
|
||||||
|
// Unless required by applicable law or agreed to in writing, software
|
||||||
|
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
// See the License for the specific language governing permissions and
|
||||||
|
// limitations under the License.
|
||||||
|
|
||||||
|
// +build windows
|
||||||
|
|
||||||
|
package helmpath
|
||||||
|
|
||||||
|
import "os"
|
||||||
|
|
||||||
|
func dataHome() string {
|
||||||
|
return configHome()
|
||||||
|
}
|
||||||
|
|
||||||
|
func configHome() string {
|
||||||
|
return os.Getenv("APPDATA")
|
||||||
|
}
|
||||||
|
|
||||||
|
func cacheHome() string {
|
||||||
|
return os.Getenv("TEMP")
|
||||||
|
}
|
@ -0,0 +1,88 @@
|
|||||||
|
// Copyright The Helm Authors.
|
||||||
|
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
// you may not use this file except in compliance with the License.
|
||||||
|
// You may obtain a copy of the License at
|
||||||
|
|
||||||
|
// http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
|
||||||
|
// Unless required by applicable law or agreed to in writing, software
|
||||||
|
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
// See the License for the specific language governing permissions and
|
||||||
|
// limitations under the License.
|
||||||
|
|
||||||
|
// +build windows
|
||||||
|
|
||||||
|
package helmpath
|
||||||
|
|
||||||
|
import (
|
||||||
|
"os"
|
||||||
|
"path/filepath"
|
||||||
|
"testing"
|
||||||
|
|
||||||
|
"k8s.io/client-go/util/homedir"
|
||||||
|
)
|
||||||
|
|
||||||
|
const (
|
||||||
|
appName string = "helm"
|
||||||
|
testFile string = "test.txt"
|
||||||
|
)
|
||||||
|
|
||||||
|
var lazy = lazypath{name: appName}
|
||||||
|
|
||||||
|
func TestDataPath(t *testing.T) {
|
||||||
|
os.Unsetenv(DataHomeEnvVar)
|
||||||
|
os.Setenv("APPDATA", filepath.Join(homedir.HomeDir(), "foo"))
|
||||||
|
|
||||||
|
expected := filepath.Join(homedir.HomeDir(), "foo", appName, testFile)
|
||||||
|
|
||||||
|
if lazy.dataPath(testFile) != expected {
|
||||||
|
t.Errorf("expected '%s', got '%s'", expected, lazy.dataPath(testFile))
|
||||||
|
}
|
||||||
|
|
||||||
|
os.Setenv(DataHomeEnvVar, filepath.Join(homedir.HomeDir(), "xdg")))
|
||||||
|
|
||||||
|
expected = filepath.Join(homedir.HomeDir(), "xdg" appName, testFile)
|
||||||
|
|
||||||
|
if lazy.dataPath(testFile) != expected {
|
||||||
|
t.Errorf("expected '%s', got '%s'", expected, lazy.dataPath(testFile))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestConfigPath(t *testing.T) {
|
||||||
|
os.Unsetenv(xdg.ConfigHomeEnvVar)
|
||||||
|
os.Setenv("APPDATA", filepath.Join(homedir.HomeDir(), "foo"))
|
||||||
|
|
||||||
|
expected := filepath.Join(homedir.HomeDir(), "foo", appName, testFile)
|
||||||
|
|
||||||
|
if lazy.configPath(testFile) != expected {
|
||||||
|
t.Errorf("expected '%s', got '%s'", expected, lazy.configPath(testFile))
|
||||||
|
}
|
||||||
|
|
||||||
|
os.Setenv(xdg.ConfigHomeEnvVar, filepath.Join(homedir.HomeDir(), "xdg")))
|
||||||
|
|
||||||
|
expected = filepath.Join(homedir.HomeDir(), "xdg" appName, testFile)
|
||||||
|
|
||||||
|
if lazy.configPath(testFile) != expected {
|
||||||
|
t.Errorf("expected '%s', got '%s'", expected, lazy.configPath(testFile))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestCachePath(t *testing.T) {
|
||||||
|
os.Unsetenv(CacheHomeEnvVar)
|
||||||
|
os.Setenv("APPDATA", filepath.Join(homedir.HomeDir(), "foo"))
|
||||||
|
|
||||||
|
expected := filepath.Join(homedir.HomeDir(), "foo", appName, testFile)
|
||||||
|
|
||||||
|
if lazy.cachePath(testFile) != expected {
|
||||||
|
t.Errorf("expected '%s', got '%s'", expected, lazy.cachePath(testFile))
|
||||||
|
}
|
||||||
|
|
||||||
|
os.Setenv(CacheHomeEnvVar, filepath.Join(homedir.HomeDir(), "xdg")))
|
||||||
|
|
||||||
|
expected = filepath.Join(homedir.HomeDir(), "xdg" appName, testFile)
|
||||||
|
|
||||||
|
if lazy.cachePath(testFile) != expected {
|
||||||
|
t.Errorf("expected '%s', got '%s'", expected, lazy.cachePath(testFile))
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,28 @@
|
|||||||
|
// Copyright The Helm Authors.
|
||||||
|
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
// you may not use this file except in compliance with the License.
|
||||||
|
// You may obtain a copy of the License at
|
||||||
|
|
||||||
|
// http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
|
||||||
|
// Unless required by applicable law or agreed to in writing, software
|
||||||
|
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
// See the License for the specific language governing permissions and
|
||||||
|
// limitations under the License.
|
||||||
|
|
||||||
|
package xdg
|
||||||
|
|
||||||
|
const (
|
||||||
|
// CacheHomeEnvVar is the environment variable used by the
|
||||||
|
// XDG base directory specification for the cache directory.
|
||||||
|
CacheHomeEnvVar = "XDG_CACHE_HOME"
|
||||||
|
|
||||||
|
// ConfigHomeEnvVar is the environment variable used by the
|
||||||
|
// XDG base directory specification for the config directory.
|
||||||
|
ConfigHomeEnvVar = "XDG_CONFIG_HOME"
|
||||||
|
|
||||||
|
// DataHomeEnvVar is the environment variable used by the
|
||||||
|
// XDG base directory specification for the data directory.
|
||||||
|
DataHomeEnvVar = "XDG_DATA_HOME"
|
||||||
|
)
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in new issue