-
Notifications
You must be signed in to change notification settings - Fork 1
/
main.go
43 lines (38 loc) · 1.1 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
package main
import (
"flag"
"fmt"
"log"
"os"
"path/filepath"
"github.com/ankurkotwal/metarefcard/mrc"
)
func main() {
debugMode, gameArgs := parseCliArgs()
router, port := mrc.GetServer(debugMode, gameArgs)
err := router.Run(port)
if err != nil {
log.Fatal(err)
}
}
func parseCliArgs() (bool, mrc.GameToInputFiles) {
gameFiles := make(mrc.GameToInputFiles)
flag.Usage = func() {
fmt.Printf("Usage: %s file...\n\n", filepath.Base(os.Args[0]))
fmt.Printf("file\tSupported game input configration.\n")
flag.PrintDefaults()
}
var debugMode bool
flag.BoolVar(&debugMode, "d", false, "Enable debug mode & deploy GET handlers.")
var testDataDir string
flag.StringVar(&testDataDir, "t", "", "Directory to load test data from. Only used if debug mode is enabled.")
flag.Parse()
// If in debug mode and a test data dir was provided, read files by game label dir
if debugMode && len(testDataDir) > 0 {
for _, getGameInfo := range mrc.GamesInfo {
label, _, _, _ := getGameInfo()
gameFiles[label] = mrc.GetFilesFromDir(fmt.Sprintf("%s/%s", testDataDir, label))
}
}
return debugMode, gameFiles
}