-
Notifications
You must be signed in to change notification settings - Fork 0
/
cr.go
69 lines (59 loc) · 1.67 KB
/
cr.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
package main
import (
"fmt"
"github.com/spf13/cobra"
"os"
)
var CRCmd = &cobra.Command{
Use: "cr <owner/name>",
Short: "Selects an active repository which gir list and gir show work against",
Long: "gir cr <owner/name> allows you to set a default repository for gir list and gir show.\n" +
"Example:\n" +
"\t> gir repos\n" +
"\t\tgolang/go (1600 issues)\n" +
"\t> gir list\n" +
"\t\tNo repository specified. You either have to specify a repo as an argument or enter a scope.\n" +
"\t> gir cr golang/go\n" +
"\t> gir list\n" +
"\t\t1/CLOSED: Make Golang awesome (bradfitz)\n" +
"\t\t2/CLOSED: Think about generics (robpike)\n" +
"\t\t3/OPEN: Gir is a hip github issues reader (JanBerktold)\n" +
"\t> gir show 3\n" +
"\t\t> issues info here\n",
Run: func(cmd *cobra.Command, args []string) {
data, err := LoadData()
if err != nil {
fmt.Printf("Failed to load data with error: %q\n", err.Error())
os.Exit(-1)
}
var targetOwner string
var targetName string
if len(args) > 0 {
targetOwner, targetName = ParseRepo(args[0])
}
if len(targetOwner) == 0 {
data.CurrentRepo = nil
goto finished
}
for _, repo := range data.Repositories {
if repo.Owner.Name == targetOwner && repo.Name == targetName {
data.CurrentRepo = &RepoIdentifier{
Owner: targetOwner,
Name: targetName,
}
goto finished
}
}
fmt.Printf("Repository %s/%s is not cached. You may want to run gir add %s/%s\n",
targetOwner, targetName, targetOwner, targetName)
return
finished:
if err := SaveData(data); err != nil {
fmt.Printf("Failed to save data: %q\n", err.Error())
os.Exit(-1)
}
},
}
func init() {
RootCmd.AddCommand(CRCmd)
}