summaryrefslogtreecommitdiff
path: root/args/args.go
blob: 6655f4adbef5401de3558f75130be6cc70ac04b5 (plain) (blame)
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
package args

import (
	"flag"
	"os"
)

type Arguments struct {
	DatabasePath string
	TemplatePath string
	StaticPath   string

	Migrate   bool
	Scheduler bool

	Port   int
	Server bool

	// DevMAC (env DEV_MAC) forces every client's MAC, for testing auth from
	// loopback where the browser never appears in the ARP table.
	DevMAC string

	// Minecraft RCON, for the server status panel. Empty address disables it.
	RconAddress  string
	RconPassword string

	// LanSubnet (env LAN_SUBNET, e.g. 192.168.8.0/24) is swept to populate the
	// ARP table for idle devices. Empty disables the sweep.
	LanSubnet string
}

func GetArgs() (*Arguments, error) {
	databasePath := flag.String("database-path", "./db/penguins.db", "Path to the SQLite database")
	templatePath := flag.String("template-path", "./templates", "Path to the template directory")
	staticPath := flag.String("static-path", "./static", "Path to the static directory")

	migrate := flag.Bool("migrate", false, "Run the migrations on startup")
	scheduler := flag.Bool("scheduler", false, "Run the background scheduler (ARP refresh, session cleanup)")

	port := flag.Int("port", 8080, "Port to listen on")
	server := flag.Bool("server", false, "Run the HTTP server")

	flag.Parse()

	return &Arguments{
		DatabasePath: *databasePath,
		TemplatePath: *templatePath,
		StaticPath:   *staticPath,
		Migrate:      *migrate,
		Scheduler:    *scheduler,
		Port:         *port,
		Server:       *server,
		DevMAC:       os.Getenv("DEV_MAC"),
		RconAddress:  os.Getenv("RCON_ADDRESS"),
		RconPassword: os.Getenv("RCON_PASSWORD"),
		LanSubnet:    os.Getenv("LAN_SUBNET"),
	}, nil
}