Use platform independent os.UserHomeDir() function

Pull request #7 replaced some code blocking cross-compilation. However,
the "HOME" environment variable is not available on Windows.

For this reason, Go introduced a dedicated method in the os package
starting from version 1.12.
This commit is contained in:
Bert Jacobs 2021-09-13 16:58:46 +02:00
parent 0066db5487
commit 8d703e95ae

View File

@ -28,6 +28,7 @@ import (
"log" "log"
"os" "os"
"path" "path"
"strings"
) )
const ( const (
@ -50,7 +51,7 @@ func usage() {
func main() { func main() {
taskName := flag.String("task", "default", "name of task to execute") taskName := flag.String("task", "default", "name of task to execute")
dstDir := flag.String("dest", os.Getenv("HOME"), "target directory for tasks") dstDir := flag.String("dest", "", "target directory for tasks")
force := flag.Bool("force", true, "create parent directories to target") force := flag.Bool("force", true, "create parent directories to target")
clobber := flag.Bool("clobber", false, "delete files and directories at target") clobber := flag.Bool("clobber", false, "delete files and directories at target")
verbose := flag.Bool("verbose", false, "verbose output") verbose := flag.Bool("verbose", false, "verbose output")
@ -94,6 +95,10 @@ func main() {
log.Fatal(err) log.Fatal(err)
} }
if strings.TrimSpace(*dstDir) == "" {
*dstDir, _ = os.UserHomeDir()
}
conf.srcDir = makeAbsPath(flag.Arg(1)) conf.srcDir = makeAbsPath(flag.Arg(1))
conf.dstDir = makeAbsPath(*dstDir) conf.dstDir = makeAbsPath(*dstDir)
conf.variant = *variant conf.variant = *variant