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"
|
"io/ioutil"
|
||||||
"os"
|
"os"
|
||||||
"os/exec"
|
"os/exec"
|
||||||
|
"os/user"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
"runtime"
|
"runtime"
|
||||||
"strings"
|
"strings"
|
||||||
|
@ -100,6 +101,15 @@ func DirsWithPrefix(path string, prefix string) ([]string, error) {
|
||||||
return dirs, nil
|
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) {
|
func AskFor(question string) (string, error) {
|
||||||
fmt.Print(question + ": ")
|
fmt.Print(question + ": ")
|
||||||
reader := bufio.NewReader(os.Stdin)
|
reader := bufio.NewReader(os.Stdin)
|
||||||
|
|
Loading…
Reference in New Issue
Block a user