-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
78 lines (61 loc) · 1.69 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
// Package main provides the executable for Nottify. This includes the command line interface, and
// web component management commands.
package main
import (
"fmt"
"os"
"github.com/cloudcloud/nottify/v1/core"
"gopkg.in/alecthomas/kingpin.v2"
)
var (
c = map[string]interface{}{}
)
// Essentially, run the CLI
func main() {
args := os.Args
if len(args) > 0 {
args = args[1:]
}
k := setupKingpin(
kingpin.New("nottify", "Nottify is your own personal audio streamer."),
)
cmd, err := k.Parse(args)
if err != nil {
k.Usage(args)
return
}
if *c["debug"].(*bool) {
fmt.Printf("Command selection is [%s]\n", cmd)
}
app(cmd, args, k)
}
func setupKingpin(k *kingpin.Application) *kingpin.Application {
c["debug"] = k.Flag("debug", "Enable debug mode.").
Short('d').Default("false").Bool()
c["dry-run"] = k.Flag("dry-run", "Run the command in dry-run mode.").
Short('r').Default("false").Bool()
c["initFile"] = k.Flag("filename", "Filename for the configuration to use.").
Short('c').Default(".nottify.json").String()
k.Command("init", "Initialise the local Nottify instance.")
ingest := k.Command("ingest", "Ingest files from the configured locations.")
c["ingestPaths"] = ingest.Arg("paths", "Paths to include for ingestion.").
Default("").Strings()
start := k.Command("start", "Bring up the Nottify server.")
c["start"] = start.Flag("foreground", "Run the server in the foreground.").
Short('f').Default("false").Bool()
return k
}
func app(cmd string, args []string, k *kingpin.Application) {
app := &core.Nottify{
Args: args,
Command: cmd,
}
switch cmd {
case "init":
app.Init(*c["initFile"].(*string))
case "ingest":
case "start":
default:
k.Usage(args)
}
}