Skip to content

Commit 29544e6

Browse files
author
Katrina Owen
authored
Merge pull request #574 from exercism/do-not-clobber-workspace
Clean up default workspace directory
2 parents 29a26ee + ff73e58 commit 29544e6

File tree

1 file changed

+11
-1
lines changed

1 file changed

+11
-1
lines changed

cmd/configure.go

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,9 @@ package cmd
22

33
import (
44
"fmt"
5+
"os"
56
"path"
7+
"strings"
68
"text/tabwriter"
79

810
"github.com/exercism/cli/config"
@@ -34,8 +36,16 @@ You can also override certain default settings to suit your preferences.
3436
if err != nil {
3537
return err
3638
}
39+
usrCfg.Normalize()
3740
if usrCfg.Workspace == "" {
38-
usrCfg.Workspace = path.Join(usrCfg.Home, path.Base(BinaryName))
41+
dirName := strings.Replace(path.Base(BinaryName), ".exe", "", 1)
42+
defaultWorkspace := path.Join(usrCfg.Home, dirName)
43+
_, err := os.Stat(defaultWorkspace)
44+
// Sorry about the double negative.
45+
if !os.IsNotExist(err) {
46+
defaultWorkspace = fmt.Sprintf("%s-1", defaultWorkspace)
47+
}
48+
usrCfg.Workspace = defaultWorkspace
3949
}
4050

4151
apiCfg := config.NewEmptyAPIConfig()

0 commit comments

Comments
 (0)