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

import (
	"flag"
	"strings"
)

type Arguments struct {
	DatabasePath string
	TemplatePath string
	StaticPath   string

	Migrate   bool
	Scheduler bool

	NtfyEndpoint     string
	NtfyBackupTopics []string
	NtfyAlertTopics  []string

	Port   int
	Server bool
}

func GetArgs() (*Arguments, error) {
	databasePath := flag.String("database-path", "./backupnotify.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")

	scheduler := flag.Bool("scheduler", false, "Run scheduled jobs via cron")
	migrate := flag.Bool("migrate", false, "Run the migrations")
	ntfyEndpoint := flag.String("ntfy-endpoint", "https://ntfy.sh", "")
	ntfyBackupTopics := flag.String("ntfy-topics", "server-backup", "")
	ntfyAlertTopics := flag.String("ntfy-alert-topics", "server-backup", "")

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

	flag.Parse()

	arguments := &Arguments{
		DatabasePath:     *databasePath,
		TemplatePath:     *templatePath,
		StaticPath:       *staticPath,
		Port:             *port,
		Server:           *server,
		Migrate:          *migrate,
		Scheduler:        *scheduler,
		NtfyEndpoint:     *ntfyEndpoint,
		NtfyBackupTopics: strings.Split(*ntfyBackupTopics, ","),
		NtfyAlertTopics:  strings.Split(*ntfyAlertTopics, ","),
	}

	return arguments, nil
}