mirror of
https://github.com/k3s-io/k3s.git
synced 2024-06-07 19:41:36 +00:00
26 lines
421 B
Go
26 lines
421 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
|
|
}
|