-
-
Notifications
You must be signed in to change notification settings - Fork 369
Expand file tree
/
Copy pathconfigure.go
More file actions
40 lines (32 loc) · 890 Bytes
/
configure.go
File metadata and controls
40 lines (32 loc) · 890 Bytes
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
package cmd
import (
"fmt"
"log"
"os"
"github.com/codegangsta/cli"
"github.com/exercism/cli/config"
)
// Configure stores settings in a JSON file.
// If a setting is not passed as an argument, default
// values are used.
func Configure(ctx *cli.Context) {
c, err := config.New(ctx.GlobalString("config"))
if err != nil {
log.Fatal(err)
}
key := ctx.String("key")
host := ctx.String("host")
dir := ctx.String("dir")
api := ctx.String("api")
if err := c.Update(key, host, dir, api); err != nil {
log.Fatalf("Error updating your configuration %s\n", err)
}
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)
}