k3s/vendor/github.com/rancher/wrangler/pkg/resolvehome/main.go
Darren Shepherd 16f7aaab66 Update vendor
2019-05-25 23:44:33 -07:00

25 lines
420 B
Go

package resolvehome
import (
"github.com/pkg/errors"
"os"
"strings"
)
var (
homes = []string{"$HOME", "${HOME}", "~"}
)
func Resolve(s string) (string, error) {
for _, home := range homes {
if strings.Contains(s, home) {
homeDir, err := os.UserHomeDir()
if err != nil {
return "", errors.Wrap(err, "determining current user")
}
s = strings.Replace(s, home, homeDir, -1)
}
}
return s, nil
}