-
Notifications
You must be signed in to change notification settings - Fork 12
Expand file tree
/
Copy pathmain.go
More file actions
428 lines (377 loc) · 9.73 KB
/
Copy pathmain.go
File metadata and controls
428 lines (377 loc) · 9.73 KB
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
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
package main
import (
"fmt"
"github.com/fatih/color"
prefixed "github.com/kisonecat/logrus-prefixed-formatter"
"github.com/sirupsen/logrus"
//"github.com/tcnksm/go-latest"
"github.com/urfave/cli"
"net/url"
"os"
"sort"
"sync"
)
var log = logrus.New()
var repository string
var keyFingerprint string
var ximeraUrl *url.URL
var workers int
func init() {
formatter := new(prefixed.TextFormatter)
formatter.DisableTimestamp = true
formatter.DisableUppercase = true
log.Formatter = formatter
}
func main() {
var group sync.WaitGroup
app := cli.NewApp()
app.Name = "xake"
app.Usage = "a build tool (make) for Ximera"
app.Version = "0.9.4"
// Check to see if this is the newest version Humorously,
// go-latest depends on go>=1.7 because that was when "context"
// was added to the main go libraries
/*
go func() {
group.Add(1)
githubTag := &latest.GithubTag{
Owner: "XimeraProject",
Repository: "xake",
FixVersionStrFunc: latest.DeleteFrontV(),
}
res, err := latest.Check(githubTag, app.Version)
if err != nil {
log.Warn("Could not check if " + app.Version + " is the latest version.")
log.Warn(err)
} else {
if res.Outdated {
log.Error(app.Version + " is not the latest version of xake.")
log.Error(fmt.Sprintf("You should upgrade to %s", res.Current))
}
}
group.Done()
}()
*/
app.EnableBashCompletion = true
// Do not display all the aliases
cli.AppHelpTemplate = `NAME:
{{.Name}}{{if .Usage}} - {{.Usage}}{{end}}
USAGE:
{{if .UsageText}}{{.UsageText}}{{else}}{{.HelpName}} {{if .VisibleFlags}}[global options]{{end}}{{if .Commands}} command [command options]{{end}} {{if .ArgsUsage}}{{.ArgsUsage}}{{else}}[arguments...]{{end}}{{end}}{{if .Version}}{{if not .HideVersion}}
VERSION:
{{.Version}}{{end}}{{end}}{{if .Description}}
DESCRIPTION:
{{.Description}}{{end}}{{if len .Authors}}
AUTHOR{{with $length := len .Authors}}{{if ne 1 $length}}S{{end}}{{end}}:
{{range $index, $author := .Authors}}{{if $index}}
{{end}}{{$author}}{{end}}{{end}}{{if .VisibleCommands}}
COMMANDS:{{range .VisibleCategories}}{{if .Name}}
{{.Name}}:{{end}}{{range .VisibleCommands}}
{{.Name}}{{"\t"}}{{.Usage}}{{end}}{{end}}{{end}}{{if .VisibleFlags}}
GLOBAL OPTIONS:
{{range $index, $option := .VisibleFlags}}{{if $index}}
{{end}}{{$option}}{{end}}{{end}}{{if .Copyright}}
COPYRIGHT:
{{.Copyright}}{{end}}
`
cli.VersionFlag = cli.BoolFlag{
Name: "version, V",
Usage: "print the version",
}
// BADBAD: This should produce nicer error outputs
w := log.Writer()
defer w.Close()
log.WriterLevel(logrus.ErrorLevel)
cli.ErrWriter = w
repository, _ = os.Getwd()
app.Flags = []cli.Flag{
cli.BoolFlag{
Name: "quiet, q",
Usage: "Do not display extra information",
},
cli.BoolFlag{
Name: "verbose, v, debug, d",
Usage: "Display additional debugging information",
},
cli.BoolFlag{
Name: "no-color, C",
Usage: "Disable color",
},
cli.IntFlag{
Name: "jobs, j",
Value: 2,
Usage: "The number of processes to run in parallel",
},
cli.StringFlag{
Name: "repository, r",
Value: repository,
Usage: "Perform operations on the repository at `PATH`",
},
cli.StringFlag{
Name: "key, k",
Value: keyFingerprint,
Usage: "Request authorization using GPG key with `FINGERPRINT`",
},
cli.StringFlag{
Name: "url, U",
Value: "https://ximera.osu.edu/",
Usage: "Use the Ximera server hosted at `URL`",
},
}
app.Commands = []cli.Command{
{
Name: "compile",
Aliases: []string{"c"},
Usage: "compile a .tex file into an .html file",
Action: func(c *cli.Context) error {
filename := c.Args().Get(0)
log.Info("Compiling " + filename + " in .")
_, err := Compile(".", filename)
if err != nil {
log.Error("Could not compile " + filename)
os.Exit(1)
}
return nil
},
},
{
Name: "clean",
Aliases: []string{"k"},
Usage: "remove built files from the working tree",
Action: func(c *cli.Context) error {
pathname := ""
if len(c.Args()) > 0 {
pathname = c.Args().Get(0)
}
err := RemoveBuiltFiles(pathname)
if err != nil {
log.Error(err)
}
return nil
},
},
{
Name: "name",
Aliases: []string{"n"},
Usage: "provide a name for this repository",
Action: func(c *cli.Context) error {
name := c.Args().Get(0)
Name(name)
return nil
},
},
{
Name: "lti",
Aliases: []string{"l"},
Usage: "fetch credentials for an LTI connection",
Action: func(c *cli.Context) error {
ltiKey := c.Args().Get(0)
ltiSecret, err := RequestLtiSecret(keyFingerprint, ltiKey)
if err != nil {
log.Error(err)
return err
}
fmt.Printf("LTI key: %s\n", ltiKey)
fmt.Printf(" secret: %s\n", ltiSecret)
return nil
},
},
{
Name: "bake",
// I have so much trouble typing this word
Aliases: []string{"b", "abke", "beak", "beka", "bkae", "bkea", "eabk", "eakb", "ebak", "ebka", "ekab", "ekba", "kabe", "kaeb", "kbae", "kbea", "keab", "keba"},
Usage: "compile all the files in the repository",
Action: func(c *cli.Context) error {
return Bake(workers)
},
},
{
Name: "frost",
Aliases: []string{"f, ice"},
Usage: "add a publication tag to the repository",
Action: func(c *cli.Context) error {
// BADBAD: should verify that we've commited the compiled source files
err := DisplayErrorsAboutUncommittedTexFiles(repository)
if err != nil {
log.Error(err)
} else {
err = Frost(app.Version)
if err != nil {
log.Error(err)
}
}
return err
},
},
{
Name: "serve",
Aliases: []string{"s"},
Usage: "push the publication tag to the server",
Action: func(c *cli.Context) error {
err := Serve()
if err != nil {
log.Error(err)
}
return err
},
},
{
Name: "pull",
Aliases: []string{"p"},
Usage: "pull published content from the server",
Action: func(c *cli.Context) error {
err := ServePull()
if err != nil {
log.Error(err)
}
return err
},
},
{
Name: "chat",
Aliases: []string{"c"},
Usage: "run a chat server",
Action: func(c *cli.Context) error {
err := Chat()
if err != nil {
log.Error(err)
}
return err
},
},
{
Name: "data",
Aliases: []string{"t"},
Usage: "operate on the learning record store",
Subcommands: []cli.Command{
{
Name: "json",
Usage: "dump log.sz as json entries",
Action: func(c *cli.Context) error {
err := DumpEventsAsJSON()
if err != nil {
log.Error(err)
}
return err
},
},
{
Name: "csv",
Usage: "dump log.sz as comma-separated values",
Action: func(c *cli.Context) error {
err := DumpEventsAsCSV()
if err != nil {
log.Error(err)
}
return err
},
},
{
Name: "download",
Usage: "download events to the log.sz file",
Action: func(c *cli.Context) error {
err := DownloadData()
if err != nil {
log.Error(err)
}
return err
},
},
},
},
{
Name: "view",
Hidden: true,
Aliases: []string{"v"},
Usage: "view a picture of a piece of a cake",
Action: func(c *cli.Context) error {
EasterEgg()
return nil
},
},
{
Name: "information",
Aliases: []string{"i", "info"},
Usage: "display information about the repository",
Action: func(c *cli.Context) error {
files, _, err := NeedingCompilation(repository)
if err != nil {
log.Error(err)
return err
}
for _, file := range files {
log.Warn(fmt.Sprintf("%s needs to be compiled", file))
}
return nil
},
},
}
app.Before = func(c *cli.Context) error {
if !c.Bool("quiet") {
fmt.Printf("This is xake, Version " + app.Version + "\n\n")
}
if c.Bool("verbose") {
log.Level = logrus.DebugLevel
}
workers = c.Int("jobs")
if workers == 0 {
workers = 2
}
if c.Bool("no-color") {
color.NoColor = true
plainLogs := new(prefixed.TextFormatter)
plainLogs.DisableColors = true
plainLogs.DisableTimestamp = true
log.Formatter = plainLogs
}
repository = c.String("repository")
repository, err := FindRepositoryAmongParentDirectories(repository)
if err != nil {
return err
}
log.Debug("Using repository " + repository)
keyFingerprint = c.String("key")
// Failing to be able to resolve the key is not a fatal error,
// because you don't necessarily need to have GPG installed in
// order to make use of xake
keyFingerprint, _ = ResolveKeyToFingerprint(keyFingerprint)
log.Debug("Using GPG key " + keyFingerprint)
urlString := c.String("url")
// BADBAD: This should actually default to whatever the ximera remote is in the current repo
ximeraUrl, err = url.Parse(urlString)
if err != nil {
return err
}
// Check to see if we can find ximeraLatex
go func() {
group.Add(1)
if !IsXimeraClassFileInstalled() {
log.Error("Could not find a copy of ximera.cls.")
log.Error("Xake requires that you install the ximeraLatex package.")
}
group.Done()
}()
// Check to see if the version of ximeraLatex is good
go func() {
group.Add(1)
err := CheckXimeraVersion()
if err != nil {
log.Error(err)
}
group.Done()
}()
//dependencies, _ := LatexDependencies("sample.tex")
//b, err := IsClean("/home/jim/ximeraSample", "/home/jim/ximeraSample/sample.tex")
//files, err := NeedingCompilation(repository)
//log.Error(err)
//log.Error(files)
return nil
}
app.CommandNotFound = func(c *cli.Context, command string) {
log.Error("I do not know how to '" + command + "'.")
}
sort.Sort(cli.FlagsByName(app.Flags))
sort.Sort(cli.CommandsByName(app.Commands))
app.Run(os.Args)
group.Wait()
}