Skip to content

Commit fbe9964

Browse files
authored
Merge pull request #225 from kkirsche/enhancement/UserHomeDir
Fix #198 - Use os.UserHomeDir() instead of custom function
2 parents a27d885 + b8bbd12 commit fbe9964

File tree

3 files changed

+3
-32
lines changed

3 files changed

+3
-32
lines changed

.travis.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ addons:
77
- rpm
88

99
go:
10-
- 1.11.x
10+
- 1.12.x
1111

1212
env:
1313
- GO111MODULE=on

cmd/config.go

Lines changed: 1 addition & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ package cmd
33
import (
44
"bufio"
55
"encoding/json"
6-
"errors"
76
"fmt"
87
"io"
98
"os"
@@ -286,7 +285,7 @@ func getDefaultData(fs vfs.FS) (map[string]interface{}, error) {
286285
return nil, err
287286
}
288287

289-
homedir, err := userHomeDir()
288+
homedir, err := os.UserHomeDir()
290289
if err != nil {
291290
return nil, err
292291
}
@@ -387,31 +386,3 @@ func upperSnakeCaseToCamelCaseMap(m map[string]string) map[string]string {
387386
}
388387
return result
389388
}
390-
391-
// userHomeDir returns the current user's home directory.
392-
//
393-
// On Unix, including macOS, it returns the $HOME environment variable.
394-
// On Windows, it returns %USERPROFILE%.
395-
// On Plan 9, it returns the $home environment variable.
396-
//
397-
// FIXME this is copied from https://tip.golang.org/src/os/file.go?s=11606:11640#L379.
398-
// Replace it with os.UserHomeDir when Go 1.12 is released.
399-
func userHomeDir() (string, error) {
400-
env, enverr := "HOME", "$HOME"
401-
switch runtime.GOOS {
402-
case "windows":
403-
env, enverr = "USERPROFILE", "%userprofile%"
404-
case "plan9":
405-
env, enverr = "home", "$home"
406-
case "nacl", "android":
407-
return "/", nil
408-
case "darwin":
409-
if runtime.GOARCH == "arm" || runtime.GOARCH == "arm64" {
410-
return "/", nil
411-
}
412-
}
413-
if v := os.Getenv(env); v != "" {
414-
return v, nil
415-
}
416-
return "", errors.New(enverr + " is not defined")
417-
}

cmd/root.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ var rootCmd = &cobra.Command{
3535
func init() {
3636
rootCmd.Version = fmt.Sprintf("%s, commit %s, built at %s", version, commit, date)
3737

38-
homeDir, err := userHomeDir()
38+
homeDir, err := os.UserHomeDir()
3939
if err != nil {
4040
printErrorAndExit(err)
4141
}

0 commit comments

Comments
 (0)