Skip to content

Commit

Permalink
Create exercism directory on configuration handler
Browse files Browse the repository at this point in the history
  • Loading branch information
Tonkpils committed Oct 12, 2014
1 parent 8afa313 commit ec4de74
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 3 deletions.
9 changes: 7 additions & 2 deletions cmd/configure.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package cmd
import (
"fmt"
"log"
"os"

"github.com/codegangsta/cli"
"github.com/exercism/cli/config"
Expand All @@ -23,10 +24,14 @@ func Configure(ctx *cli.Context) {
dir := ctx.String("dir")
c.Update(key, host, dir)

err = c.Write()
if err != nil {
if err := os.MkdirAll(c.Dir, os.ModePerm); err != nil {
log.Fatalf("Error creating exercism directory %s\n", err)
}

if err := c.Write(); err != nil {
log.Fatal(err)
}

fmt.Printf("The configuration has been written to %s\n", c.File())
fmt.Printf("Your exercism directory can be found at %s\n", c.Dir)
}
2 changes: 1 addition & 1 deletion config/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ func TestReadNonexistantConfig(t *testing.T) {
assert.Equal(t, c.APIKey, "")
assert.Equal(t, c.API, "http://exercism.io")
assert.False(t, c.IsAuthenticated())
if !strings.HasSuffix(c.Dir, filepath.FromSlash("/exercism") ) {
if !strings.HasSuffix(c.Dir, filepath.FromSlash("/exercism")) {
t.Fatal("Default unconfigured config should use home dir")
}
}
Expand Down

0 comments on commit ec4de74

Please sign in to comment.