forked from exercism/cli
/
debug.go
81 lines (67 loc) · 2.01 KB
/
debug.go
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
69
70
71
72
73
74
75
76
77
78
79
80
81
package cmd
import (
"fmt"
"log"
"net/http"
"os"
"runtime"
"time"
"github.com/codegangsta/cli"
"github.com/exercism/cli/config"
)
// Debug provides information about the user's environment and configuration.
func Debug(ctx *cli.Context) {
defer fmt.Printf("\nIf you are having trouble and need to file a GitHub issue (https://github.com/exercism/exercism.io/issues) please include this information (except your API key. Keep that private).\n")
client := http.Client{Timeout: 5 * time.Second}
fmt.Printf("\n**** Debug Information ****\n")
fmt.Printf("Exercism CLI Version: %s\n", ctx.App.Version)
rel, err := fetchLatestRelease(client)
if err != nil {
log.Println("unable to fetch latest release: " + err.Error())
} else {
if rel.Version() != ctx.App.Version {
defer fmt.Printf("\nA newer version of the CLI (%s) can be downloaded here: %s\n", rel.TagName, rel.Location)
}
fmt.Printf("Exercism CLI Latest Release: %s\n", rel.Version())
}
fmt.Printf("OS/Architecture: %s/%s\n", runtime.GOOS, runtime.GOARCH)
fmt.Printf("Build OS/Architecture %s/%s\n", BuildOS, BuildARCH)
if BuildARM != "" {
fmt.Printf("Build ARMv%s\n", BuildARM)
}
dir, err := config.Home()
if err != nil {
log.Fatal(err)
}
fmt.Printf("Home Dir: %s\n", dir)
c, err := config.New(ctx.GlobalString("config"))
if err != nil {
log.Fatal(err)
}
configured := true
if _, err = os.Stat(c.File); err != nil {
if os.IsNotExist(err) {
configured = false
} else {
log.Fatal(err)
}
}
if configured {
fmt.Printf("Config file: %s\n", c.File)
fmt.Printf("API Key: %s\n", c.APIKey)
} else {
fmt.Println("Config file: <not configured>")
fmt.Println("API Key: <not configured>")
}
fmt.Printf("API: %s [%s]\n", c.API, pingURL(client, c.API))
fmt.Printf("XAPI: %s [%s]\n", c.XAPI, pingURL(client, c.XAPI))
fmt.Printf("Exercises Directory: %s\n", c.Dir)
}
func pingURL(client http.Client, url string) string {
res, err := client.Get(url)
if err != nil {
return err.Error()
}
defer res.Body.Close()
return "connected"
}