From cd15661f087530929b10094aea8d9e1d87e0fac1 Mon Sep 17 00:00:00 2001 From: Gabe Kangas Date: Sun, 24 Oct 2021 23:09:30 -0700 Subject: [PATCH] Split out cli arg handling from main --- main.go | 31 ++++++++++++++++++------------- 1 file changed, 18 insertions(+), 13 deletions(-) diff --git a/main.go b/main.go index b590bf589..e77f861b5 100644 --- a/main.go +++ b/main.go @@ -23,10 +23,6 @@ func main() { enableDebugOptions := flag.Bool("enableDebugFeatures", false, "Enable additional debugging options.") enableVerboseLogging := flag.Bool("enableVerboseLogging", false, "Enable additional logging.") restoreDatabaseFile := flag.String("restoreDatabase", "", "Restore an Owncast database backup") - newStreamKey := flag.String("streamkey", "", "Set your stream key/admin password") - webServerPortOverride := flag.String("webserverport", "", "Force the web server to listen on a specific port") - webServerIPOverride := flag.String("webserverip", "", "Force web server to listen on this IP address") - rtmpPortOverride := flag.Int("rtmpport", 0, "Set listen port for the RTMP server") flag.Parse() @@ -75,6 +71,24 @@ func main() { log.Fatalln("failed to open database", err) } + handleCommandLineFlags() + + // starts the core + if err := core.Start(); err != nil { + log.Fatalln("failed to start the core package", err) + } + + if err := router.Start(); err != nil { + log.Fatalln("failed to start/run the router", err) + } +} + +func handleCommandLineFlags() { + newStreamKey := flag.String("streamkey", "", "Set your stream key/admin password") + webServerPortOverride := flag.String("webserverport", "", "Force the web server to listen on a specific port") + webServerIPOverride := flag.String("webserverip", "", "Force web server to listen on this IP address") + rtmpPortOverride := flag.Int("rtmpport", 0, "Set listen port for the RTMP server") + if *newStreamKey != "" { if err := data.SetStreamKey(*newStreamKey); err != nil { log.Errorln("Error setting your stream key.", err) @@ -115,15 +129,6 @@ func main() { log.Errorln(err) } } - - // starts the core - if err := core.Start(); err != nil { - log.Fatalln("failed to start the core package", err) - } - - if err := router.Start(); err != nil { - log.Fatalln("failed to start/run the router", err) - } } func configureLogging(enableDebugFeatures bool, enableVerboseLogging bool) {