-
-
Notifications
You must be signed in to change notification settings - Fork 369
Expand file tree
/
Copy pathexercism.go
More file actions
68 lines (55 loc) · 1.27 KB
/
exercism.go
File metadata and controls
68 lines (55 loc) · 1.27 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
package main
import (
"fmt"
"github.com/exercism/cli/configuration"
"os"
"path/filepath"
)
func logout(dir string) {
os.Remove(configuration.Filename(dir))
}
func absolutePath(path string) (string, error) {
path, err := filepath.Abs(path)
if err != nil {
return "", err
}
return filepath.EvalSymlinks(path)
}
func askForConfigInfo() (c configuration.Config) {
var un, key, dir string
currentDir, err := os.Getwd()
if err != nil {
panic(err)
}
fmt.Print("Your GitHub username: ")
_, err = fmt.Scanln(&un)
if err != nil {
panic(err)
}
fmt.Print("Your exercism.io API key: ")
_, err = fmt.Scanln(&key)
if err != nil {
panic(err)
}
fmt.Println("What is your exercism exercises project path?")
fmt.Printf("Press Enter to select the default (%s):\n", currentDir)
fmt.Print("> ")
_, err = fmt.Scanln(&dir)
if err != nil && err.Error() != "unexpected newline" {
panic(err)
}
if dir == "" {
dir = currentDir
}
dir = configuration.ReplaceTilde(dir)
err = os.MkdirAll(dir, 0755)
if err != nil {
err = fmt.Errorf("Error making directory %v: [%v]", dir, err)
return
}
dir, err = absolutePath(dir)
if err != nil {
panic(err)
}
return configuration.Config{GithubUsername: un, ApiKey: key, ExercismDirectory: dir, Hostname: "http://exercism.io"}
}