Skip to content

Commit

Permalink
Merge pull request #11 from msgehard/demo-without-login
Browse files Browse the repository at this point in the history
`exercism demo` should not require login
  • Loading branch information
kytrinyx committed Sep 27, 2013
2 parents abfe0f9 + cc8a50f commit 54b4abd
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 2 deletions.
10 changes: 10 additions & 0 deletions src/exercism/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"encoding/json"
"fmt"
"io/ioutil"
"os"
)

const FILENAME = ".exercism.go"
Expand Down Expand Up @@ -40,6 +41,15 @@ func ConfigToFile(dir string, c Config) (err error) {
return
}

func DemoDirectory() (dir string, err error) {
dir, err = os.Getwd()
if err != nil {
return
}
dir = dir + "/exercism-demo"
return
}

func configFilename(dir string) string {
return dir + "/" + FILENAME
}
16 changes: 16 additions & 0 deletions src/exercism/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ package exercism
import (
"github.com/stretchr/testify/assert"
"io/ioutil"
"os"
"path/filepath"
"testing"
)

Expand All @@ -23,3 +25,17 @@ func TestReadingWritingConfig(t *testing.T) {

assert.Equal(t, writtenConfig, loadedConfig)
}

func TestDemoDir(t *testing.T) {
path, err := ioutil.TempDir("", "")
assert.NoError(t, err)
os.Chdir(path)

path, err = filepath.EvalSymlinks(path)
assert.NoError(t, err)

path = filepath.Join(path, "exercism-demo")

demoDir, err := DemoDirectory()
assert.Equal(t, demoDir, path)
}
13 changes: 11 additions & 2 deletions src/main/exercism.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,17 @@ func main() {
Action: func(c *cli.Context) {
config, err := exercism.ConfigFromFile(exercism.HomeDir())
if err != nil {
fmt.Println("Are you sure you are logged in? Please login again.")
return
demoDir, err2 := exercism.DemoDirectory()
if err2 != nil {
err = err2
fmt.Println(err)
return
}
config = exercism.Config{
Hostname: "http://exercism.io",
ApiKey: "",
ExercismDirectory: demoDir,
}
}
assignments, err := exercism.FetchAssignments(config.Hostname,
exercism.FetchEndpoints["demo"], config.ApiKey)
Expand Down

0 comments on commit 54b4abd

Please sign in to comment.