diff options
Diffstat (limited to 'args/args.go')
| -rw-r--r-- | args/args.go | 58 |
1 files changed, 58 insertions, 0 deletions
diff --git a/args/args.go b/args/args.go new file mode 100644 index 0000000..6655f4a --- /dev/null +++ b/args/args.go @@ -0,0 +1,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 +} |
