-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
106 lines (92 loc) · 2.14 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
package main
import (
"bytes"
"embed"
_ "embed"
"github.com/boggydigital/clo"
"github.com/boggydigital/nod"
"github.com/boggydigital/novus/cli"
"github.com/boggydigital/novus/data"
"github.com/boggydigital/novus/rest"
"github.com/boggydigital/pathways"
"html/template"
"os"
"sync"
)
var (
once = sync.Once{}
//go:embed "templates/*.gohtml"
templates embed.FS
//go:embed "stencil_app/styles/css.gohtml"
stencilAppStyles embed.FS
//go:embed "cli-commands.txt"
cliCommands []byte
//go:embed "cli-help.txt"
cliHelp []byte
)
var tmplFuncs = template.FuncMap{
"empty": empty,
}
const (
directoriesFilename = "directories.txt"
)
func main() {
nod.EnableStdOutPresenter()
ns := nod.Begin("novus is checking for any news")
defer ns.End()
if err := pathways.Setup(
directoriesFilename,
data.DefaultNovusRootDir,
nil,
data.AllAbsDirs()...); err != nil {
_ = ns.EndWithError(err)
os.Exit(1)
}
once.Do(func() {
if err := rest.Init(templates, tmplFuncs, stencilAppStyles); err != nil {
_ = ns.EndWithError(err)
os.Exit(1)
}
cli.Init(templates, tmplFuncs)
})
defs, err := clo.Load(
bytes.NewBuffer(cliCommands),
bytes.NewBuffer(cliHelp),
nil)
if err != nil {
_ = ns.EndWithError(err)
os.Exit(1)
}
clo.HandleFuncs(map[string]clo.Handler{
"backup": cli.BackupHandler,
"decode": cli.DecodeHandler,
"diff": cli.DiffHandler,
"get-content": cli.GetContentHandler,
"match-content": cli.MatchContentHandler,
"migrate": cli.MigrateHandler,
"publish-atom": cli.PublishAtomHandler,
"reduce": cli.ReduceHandler,
"reset-changes": cli.ResetChangesHandler,
"reset-errors": cli.ResetErrorsHandler,
"serve": cli.ServeHandler,
"sync": cli.SyncHandler,
"test-sources": cli.TestSourcesHandler,
"version": cli.VersionHandler,
})
if err := defs.AssertCommandsHaveHandlers(); err != nil {
_ = ns.EndWithError(err)
os.Exit(1)
}
if err := defs.Serve(os.Args[1:]); err != nil {
_ = ns.EndWithError(err)
os.Exit(1)
}
}
func empty(maps ...map[string][]string) bool {
for _, m := range maps {
if len(m) > 0 {
return false
}
}
return true
}