-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
75 lines (65 loc) · 1.38 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
73
74
75
package main
import (
"compress/gzip"
"encoding/json"
"fmt"
"github.com/spf13/cobra"
"os"
"strings"
)
type RepoIdentifier struct {
Owner string
Name string
}
type Data struct {
CurrentRepo *RepoIdentifier
Repositories []Repository
}
var file = os.Getenv("HOME") + "/.github_issues"
func LoadData() (Data, error) {
f, err := os.Open(file)
if err != nil {
p := err.(*os.PathError)
//TODO: hacky
if p.Err.Error() == "no such file or directory" {
return Data{}, nil
}
return Data{}, err
}
defer f.Close()
var data Data
rd, err := gzip.NewReader(f)
if err != nil {
return Data{}, nil
}
return data, json.NewDecoder(rd).Decode(&data)
}
func SaveData(data Data) error {
f, err := os.Create(file)
if err != nil {
return err
}
defer f.Close()
writer := gzip.NewWriter(f)
defer writer.Close()
return json.NewEncoder(writer).Encode(data)
}
func ParseRepo(repo string) (owner, name string) {
index := strings.Index(repo, "/")
if index > -1 {
return repo[0:index], repo[index+1:]
}
return "", ""
}
var RootCmd = &cobra.Command{
Use: "gir",
Short: "gir is a very simple, fast and flexible github offline issues reader.",
Long: `gir is an offline github issues reader by github.com/JanBerktold
Go to https://github.com/JanBerktold/gir for further information.`,
}
func main() {
if err := RootCmd.Execute(); err != nil {
fmt.Println(err)
os.Exit(-1)
}
}