-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
236 lines (225 loc) · 4.66 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
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
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
package main
import (
"os"
"go.bbkane.com/warg"
"go.bbkane.com/warg/command"
"go.bbkane.com/warg/flag"
"go.bbkane.com/warg/section"
"go.bbkane.com/warg/value"
)
func app() *warg.App {
downloadCmd := command.New(
"Download star info",
githubStarsDownload,
command.Flag(
"--include-readmes",
"Search for README.md.",
value.Bool,
flag.Default("false"),
),
command.Flag(
"--max-languages",
"Max number of languages to query on a repo",
value.Int,
flag.Default("20"),
),
command.Flag(
"--max-repo-topics",
"Max number of topics to query on a repo",
value.Int,
flag.Default("20"),
),
command.Flag(
"--after-cursor",
"PageInfo EndCursor to start from",
value.String,
),
command.Flag(
"--max-pages",
"Max number of pages to fetch",
value.Int,
flag.Default("1"),
flag.Required(),
),
command.Flag(
"--output",
"Output filepath. Must not exist",
value.Path,
flag.Default("starghaze_download.jsonl"),
),
command.Flag(
"--page-size",
"Number of starred repos in page",
value.Int,
flag.Default("100"),
flag.Required(),
),
command.Flag(
"--timeout",
"Timeout for a run. Use https://pkg.go.dev/time#Duration to build it",
value.Duration,
flag.Default("10m"),
flag.Required(),
),
command.Flag(
"--token",
"Github PAT",
value.String,
flag.EnvVars("STARGHAZE_GITHUB_TOKEN", "GITHUB_TOKEN"),
flag.Required(),
),
)
formatCmd := command.New(
"Format downloaded GitHub Stars",
format,
command.Flag(
"--format",
"Output format",
value.StringEnum("csv", "jsonl", "sqlite", "zinc"),
flag.Default("csv"),
flag.Required(),
),
command.Flag(
"--date-format",
"Datetime output format. See https://github.com/lestrrat-go/strftime for details. If not passed, the GitHub default is RFC 3339. Consider using '%b %d, %Y' for csv format",
value.String,
),
command.Flag(
"--include-readmes",
"Search for README.md.",
value.Bool,
flag.Default("false"),
flag.Required(),
),
command.Flag(
"--sqlite-dsn",
"Sqlite DSN. Usually the file name. Only used for --format sqlite",
value.String,
flag.Default("starghaze.db"),
),
command.Flag(
"--zinc-index-name",
"Only used for --format zinc.",
value.String,
flag.Default("starghaze"),
),
command.Flag(
"--input",
"Input file",
value.String,
flag.Required(),
flag.Default("starghaze_download.jsonl"),
),
command.Flag(
"--max-line-size",
"Max line size in the file in MB",
value.Int,
flag.Default("10"),
flag.Required(),
),
command.Flag(
"--output",
"output file. Prints to stdout if not passed",
value.Path,
),
)
gsheetsSection := section.New(
"Google Sheets commands",
section.Command(
"open",
"Open spreadsheet in browser",
gSheetsOpen,
),
section.Command(
"upload",
"Upload CSV to Google Sheets. This will overwrite whatever is in the spreadsheet",
gSheetsUpload,
command.Flag(
"--csv-path",
"CSV file to upload",
value.Path,
flag.Required(),
),
command.Flag(
"--timeout",
"Timeout for a run. Use https://pkg.go.dev/time#Duration to build it",
value.Duration,
flag.Default("10m"),
flag.Required(),
),
),
section.Flag(
"--sheet-id",
"ID For the particulare sheet. Viewable from `gid` URL param",
value.Int,
flag.EnvVars("STARGHAZE_SHEET_ID"),
flag.Required(),
),
section.Flag(
"--spreadsheet-id",
"ID for the whole spreadsheet. Viewable from URL",
value.String,
flag.EnvVars("STARGHAZE_SPREADSHEET_ID"),
flag.Required(),
),
)
searchCmd := command.New(
"Full text search SQLite database",
search,
command.Flag(
"--limit",
"Max number of results",
value.Int,
flag.Default("50"),
flag.Required(),
),
command.Flag(
"--sqlite-dsn",
"Sqlite DSN. Usually the file name.",
value.String,
flag.Default("starghaze.db"),
flag.Required(),
),
command.Flag(
"--term",
"Search for this term",
value.String,
flag.Alias("-t"),
flag.Required(),
),
// TODO: how many results? limit by date added?
)
app := warg.New(
"starghaze",
section.New(
"Save GitHub Starred Repos",
section.Command(
"version",
"Print version",
printVersion,
),
section.ExistingCommand(
"download",
downloadCmd,
),
section.ExistingCommand(
"format",
formatCmd,
),
section.ExistingCommand(
"search",
searchCmd,
),
section.ExistingSection(
"gsheets",
gsheetsSection,
),
section.Footer("Homepage: https://github.com/bbkane/starghaze"),
),
warg.SkipValidation(),
)
return &app
}
func main() {
app().MustRun(os.Args, os.LookupEnv)
}