-
-
Notifications
You must be signed in to change notification settings - Fork 369
Expand file tree
/
Copy pathlogin.go
More file actions
61 lines (49 loc) · 1.35 KB
/
login.go
File metadata and controls
61 lines (49 loc) · 1.35 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
package cmd
import (
"bufio"
"flag"
"fmt"
"log"
"os"
"path/filepath"
"github.com/codegangsta/cli"
"github.com/exercism/cli/config"
)
// Login interactively stores exercism API configuration.
// Delete when nobody is using 1.6.x anymore.
func Login(ctx *cli.Context) {
msg := `
*******************************************************************
DEPRECATED!
In the future use the 'exercism configure' command to configure:
exercism configure --key YOUR_API_KEY
*******************************************************************
`
fmt.Printf(msg)
dir, err := config.Home()
if err != nil {
log.Fatal(err)
}
dir = filepath.Join(dir, config.DirExercises)
bio := bufio.NewReader(os.Stdin)
fmt.Print("Your Exercism API key (found at http://exercism.io/account):\n> ")
key, err := bio.ReadString('\n')
if err != nil {
log.Fatal(err)
}
fmt.Println("What is your exercism exercises path?")
fmt.Printf("Press Enter to select the default (%s):\n> ", dir)
dir, err = bio.ReadString('\n')
if err != nil {
log.Fatal(err)
}
// overwrite the context
gSet := flag.NewFlagSet("global", 0)
gSet.String("config", ctx.GlobalString("config"), ":nodoc:")
cSet := flag.NewFlagSet("cmd", 0)
cSet.String("key", key, ":nodoc:")
cSet.String("dir", dir, ":nodoc:")
ctx = cli.NewContext(nil, cSet, gSet)
// call the Configure() handler
Configure(ctx)
}