-
Notifications
You must be signed in to change notification settings - Fork 0
/
types.go
129 lines (106 loc) · 2.04 KB
/
types.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
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
package main
import (
"encoding/json"
"fmt"
"os"
"path/filepath"
"strings"
"time"
)
type void struct{}
// Data is the generic content map passed on to the page template.
type Data map[string]interface{}
type page struct {
Base string
Data
Title string
}
type branch struct {
Commits []commit
Name string
Project string
}
func (b branch) String() string {
return b.Name
}
type diff struct {
Body string
Commit commit
Parent string
}
type overview struct {
Body string
Hash string
Parent string
}
type hash struct {
Hash string
Short string
}
func (h hash) String() string {
return h.Hash
}
type object struct {
Hash string
Path string
}
func (o object) Dir() string {
return filepath.Join(o.Hash[0:2], o.Hash[2:])
}
type show struct {
Body string
Bin bool
Lines []int
object
}
type commit struct {
Branch string
Body string
Abbr string
History []overview
Parents []string
Hash string
Author author
Date time.Time
Project string
Tree []object
Types map[string]bool
Subject string
}
type author struct {
Email string
Name string
}
// https://stackoverflow.com/questions/28322997/how-to-get-a-list-of-values-into-a-flag-in-golang/
type manyflag []string
func (f *manyflag) Set(value string) error {
// Make sure there are no duplicates.
if !contains(*f, value) {
*f = append(*f, value)
}
return nil
}
func (f *manyflag) String() string {
return strings.Join(*f, ", ")
}
type options struct {
Branches manyflag `json:"branches"`
config string
Export bool `json:"export"`
Force bool `json:"force"`
Name string `json:"name"`
Quiet bool `json:"quiet"`
Source string `json:"source"`
Template string `json:"template"`
}
// Helps store options as JSON.
func (o *options) save(p string) error {
bs, err := json.MarshalIndent(o, "", " ")
if err != nil {
return fmt.Errorf("failed to encode options: %v", err)
}
if err := os.WriteFile(filepath.Join(p, o.config), bs, 0644); err != nil {
return fmt.Errorf("failed to write options: %v", err)
}
return nil
}