summaryrefslogtreecommitdiff
path: root/args/args.go
diff options
context:
space:
mode:
authorLizzy Hunt <lizzy.hunt@usu.edu>2024-03-26 16:00:05 -0600
committerLizzy Hunt <lizzy.hunt@usu.edu>2024-03-26 16:00:05 -0600
commitfe22956d5dbdeb2b80a9e56b46abe2be9f2bfcdb (patch)
tree6111f03c2da4eb42aff03cda72157a8961da27e8 /args/args.go
parent27aab70386c68f3a0f22c52e72b91cf16b289100 (diff)
downloadhatecomputers.club-fe22956d5dbdeb2b80a9e56b46abe2be9f2bfcdb.tar.gz
hatecomputers.club-fe22956d5dbdeb2b80a9e56b46abe2be9f2bfcdb.zip
initial commit
Diffstat (limited to 'args/args.go')
-rw-r--r--args/args.go53
1 files changed, 53 insertions, 0 deletions
diff --git a/args/args.go b/args/args.go
new file mode 100644
index 0000000..9176d27
--- /dev/null
+++ b/args/args.go
@@ -0,0 +1,53 @@
+package args
+
+import (
+ "errors"
+ "flag"
+ "os"
+)
+
+type Arguments struct {
+ DatabasePath string
+ TemplatePath string
+ StaticPath string
+ CloudflareToken string
+ CloudflareZone string
+ Port int
+ Server bool
+ Migrate bool
+}
+
+func GetArgs() (*Arguments, error) {
+ port := flag.Int("port", 8080, "Port to listen on")
+ databasePath := flag.String("database-path", "./hatecomputers.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")
+
+ server := flag.Bool("server", false, "Run the server")
+ migrate := flag.Bool("migrate", false, "Run the migrations")
+
+ flag.Parse()
+
+ cloudflareToken := os.Getenv("CLOUDFLARE_TOKEN")
+ cloudflareZone := os.Getenv("CLOUDFLARE_ZONE")
+
+ if cloudflareToken == "" {
+ return nil, errors.New("please set the CLOUDFLARE_TOKEN environment variable")
+ }
+ if cloudflareZone == "" {
+ return nil, errors.New("please set the CLOUDFLARE_ZONE environment variable")
+ }
+
+ arguments := &Arguments{
+ DatabasePath: *databasePath,
+ TemplatePath: *templatePath,
+ StaticPath: *staticPath,
+ CloudflareToken: cloudflareToken,
+ CloudflareZone: cloudflareZone,
+ Port: *port,
+ Server: *server,
+ Migrate: *migrate,
+ }
+
+ return arguments, nil
+}