This repository has been archived by the owner on Mar 24, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
/
main.go
72 lines (66 loc) · 1.65 KB
/
main.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
package main
import (
"fmt"
"os"
"strconv"
"github.com/pivotal/gumshoe/repos/cli"
"github.com/pivotal/gumshoe/term"
"github.com/pivotal/gumshoe/trackerapi"
)
func main() {
app := cli.NewApp()
app.Name = "gumshoe"
app.Usage = "talks to tracker"
config := trackerapi.NewConfiguration()
client, err := trackerapi.NewClient(config)
if err != nil {
panic(err)
}
terminal := term.New()
app.Commands = []cli.Command{
{
Name: "me",
Usage: "prints out Tracker's representation of your account",
Action: func(c *cli.Context) {
handleAuthentication(client, terminal)
output := client.Me()
fmt.Println(output)
},
},
{
Name: "projects",
Usage: "prints out a list of Tracker projects for your account",
Action: func(c *cli.Context) {
handleAuthentication(client, terminal)
output := client.Projects()
fmt.Println(output)
},
},
{
Name: "activity",
Usage: "lists last 5 activities for a given project",
Action: func(c *cli.Context) {
if len(c.Args()) == 0 {
fmt.Println("Please supply a project ID")
os.Exit(1)
}
projectID, err := strconv.Atoi(c.Args()[0])
if err != nil {
fmt.Println("Something went wrong parsing the Project ID.", err)
os.Exit(1)
}
handleAuthentication(client, terminal)
output := client.Activity(projectID)
fmt.Println(output)
},
},
}
app.Run(os.Args)
}
func handleAuthentication(client *trackerapi.Client, terminal *term.Terminal) {
if !client.IsAuthenticated() {
username := terminal.Prompt("Username: ", term.EnableEcho)
password := terminal.Prompt("Password: ", term.DisableEcho)
client.Authenticate(username, password)
}
}