-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.go
73 lines (57 loc) · 1.25 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
package main
import (
"flag"
"fmt"
"os"
"time"
"github.com/j0hax/mz/app"
"github.com/j0hax/mz/config"
)
// Flags set by goreleaser
var (
version = "dev"
commit = "-"
date = "-"
)
// Our Save State object
var cfg = config.LoadConfig()
func customUsage() {
out := flag.CommandLine.Output()
fmt.Fprintf(out, "Usage: %s [OPTIONS] [CANTEEN NAME]\n", os.Args[0])
flag.PrintDefaults()
}
func versionString() string {
shortCommit := commit
if len(commit) > 8 {
shortCommit = commit[0:7]
}
var shortDate string
date, err := time.Parse(time.RFC3339, date)
if err != nil {
shortDate = "unknown"
} else {
shortDate = date.Format(time.DateOnly)
}
return fmt.Sprintf("mz %s (commit %s, built %s)", version, shortCommit, shortDate)
}
func main() {
reset := flag.Bool("r", false, "reset last saved mensa")
vflag := flag.Bool("v", false, "print version information")
flag.Usage = customUsage
flag.Parse()
if *reset {
cfg.Last.Name = ""
}
if *vflag {
out := flag.CommandLine.Output()
fmt.Fprintf(out, "%s\n", versionString())
os.Exit(0)
}
// Load the mensa from CLI args, otherwise from config
if len(flag.Args()) > 0 {
cfg.Last.Name = flag.Arg(0)
}
// Write the config to disk at the end
defer cfg.Save()
app.StartApp(cfg)
}