Skip to content

Commit

Permalink
Merge pull request #574 from exercism/do-not-clobber-workspace
Browse files Browse the repository at this point in the history
Clean up default workspace directory
  • Loading branch information
Katrina Owen authored Jun 22, 2018
2 parents 29a26ee + ff73e58 commit 29544e6
Showing 1 changed file with 11 additions and 1 deletion.
12 changes: 11 additions & 1 deletion cmd/configure.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@ package cmd

import (
"fmt"
"os"
"path"
"strings"
"text/tabwriter"

"github.com/exercism/cli/config"
Expand Down Expand Up @@ -34,8 +36,16 @@ You can also override certain default settings to suit your preferences.
if err != nil {
return err
}
usrCfg.Normalize()
if usrCfg.Workspace == "" {
usrCfg.Workspace = path.Join(usrCfg.Home, path.Base(BinaryName))
dirName := strings.Replace(path.Base(BinaryName), ".exe", "", 1)
defaultWorkspace := path.Join(usrCfg.Home, dirName)
_, err := os.Stat(defaultWorkspace)
// Sorry about the double negative.
if !os.IsNotExist(err) {
defaultWorkspace = fmt.Sprintf("%s-1", defaultWorkspace)
}
usrCfg.Workspace = defaultWorkspace
}

apiCfg := config.NewEmptyAPIConfig()
Expand Down

0 comments on commit 29544e6

Please sign in to comment.