From bf6c6d57ccd3425c82bf8664b5a01a28c8cd747d Mon Sep 17 00:00:00 2001 From: Mikkel Krautz Date: Sat, 13 Jan 2018 20:51:25 +0100 Subject: [PATCH] Use %USERPROFILE% instead of $HOME on Windows for Grumble's default data dir. This also changes Grumble to use ".grumble" on Windows. Previously, it preferred the non-hidden "grumble" on Windows. Unfortunately, that now clashes with my grumble Git checkout, so let's make it consistent across platforms. --- cmd/grumble/args.go | 25 ++++++++++++++----------- 1 file changed, 14 insertions(+), 11 deletions(-) diff --git a/cmd/grumble/args.go b/cmd/grumble/args.go index 28573f5..4b2331c 100644 --- a/cmd/grumble/args.go +++ b/cmd/grumble/args.go @@ -9,10 +9,11 @@ import ( ) type UsageArgs struct { - Version string - BuildDate string - OS string - Arch string + Version string + BuildDate string + OS string + Arch string + DefaultDataDir string } var usageTmpl = `usage: grumble [options] @@ -23,7 +24,7 @@ var usageTmpl = `usage: grumble [options] --help Shows this help listing. - --datadir (default: $HOME/.grumble) + --datadir (default: {{.DefaultDataDir}}) Directory to use for server storage. --log (default: $DATADIR/grumble.log) @@ -54,11 +55,12 @@ type args struct { } func defaultDataDir() string { + homedir := os.Getenv("HOME") dirname := ".grumble" if runtime.GOOS == "windows" { - dirname = "grumble" + homedir = os.Getenv("USERPROFILE") } - return filepath.Join(os.Getenv("HOME"), dirname) + return filepath.Join(homedir, dirname) } func defaultLogPath() string { @@ -72,10 +74,11 @@ func Usage() { } err = t.Execute(os.Stdout, UsageArgs{ - Version: version, - BuildDate: buildDate, - OS: runtime.GOOS, - Arch: runtime.GOARCH, + Version: version, + BuildDate: buildDate, + OS: runtime.GOOS, + Arch: runtime.GOARCH, + DefaultDataDir: defaultDataDir(), }) if err != nil { panic("unable to execute usage template")