add function to obtain home dir
This commit is contained in:
parent
4ad5c8d93a
commit
2c5c9628c4
10
goutil.go
10
goutil.go
|
@ -8,6 +8,7 @@ import (
|
|||
"io/ioutil"
|
||||
"os"
|
||||
"os/exec"
|
||||
"os/user"
|
||||
"path/filepath"
|
||||
"runtime"
|
||||
"strings"
|
||||
|
@ -100,6 +101,15 @@ func DirsWithPrefix(path string, prefix string) ([]string, error) {
|
|||
return dirs, nil
|
||||
}
|
||||
|
||||
func HomeDir() (string, error) {
|
||||
d := ""
|
||||
currentUser, err := user.Current()
|
||||
if err == nil {
|
||||
d = currentUser.HomeDir
|
||||
}
|
||||
return d, err
|
||||
}
|
||||
|
||||
func AskFor(question string) (string, error) {
|
||||
fmt.Print(question + ": ")
|
||||
reader := bufio.NewReader(os.Stdin)
|
||||
|
|
Loading…
Reference in New Issue
Block a user