backup-notify/args/args.go

56 lines
1.5 KiB
Go
Raw Normal View History

2024-04-21 21:46:40 -04:00
package args
import (
"flag"
"strings"
)
type Arguments struct {
DatabasePath string
TemplatePath string
StaticPath string
Migrate bool
Scheduler bool
NtfyEndpoint string
NtfyBackupTopics []string
NtfyAlertTopics []string
2024-04-21 21:46:40 -04:00
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", "")
2024-04-21 21:46:40 -04:00
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, ","),
2024-04-21 21:46:40 -04:00
}
return arguments, nil
}