From 1ccd481f9e31acee008aa4f328bf855db984425c Mon Sep 17 00:00:00 2001 From: Gregory Ballantine Date: Thu, 15 Sep 2022 10:09:10 -0400 Subject: [PATCH] Refactored a bit to put the configuration and logging setup before Cobra launches, so it doesn't need to be handled in every sub-command --- adept.go | 11 +++++++++++ cmd/root.go | 10 ---------- cmd/setup.go | 12 +----------- 3 files changed, 12 insertions(+), 21 deletions(-) diff --git a/adept.go b/adept.go index 6a368dd..e7f3eb7 100644 --- a/adept.go +++ b/adept.go @@ -2,9 +2,20 @@ package main import ( "git.metaunix.net/BitGoblin/adept/cmd" + "git.metaunix.net/BitGoblin/adept/config" ) // start the app - that's where all the good stuff happens func main() { + // load configuration via Viper + config.LoadConfig() + + // configure our app logging + logHandle := config.InitLogging() + if logHandle != nil { + defer logHandle.Close() + } + + // launch the Cobra CLI framework cmd.Execute() } diff --git a/cmd/root.go b/cmd/root.go index b726364..2887efd 100644 --- a/cmd/root.go +++ b/cmd/root.go @@ -7,7 +7,6 @@ import ( "github.com/spf13/cobra" "github.com/spf13/viper" - "git.metaunix.net/BitGoblin/adept/config" "git.metaunix.net/BitGoblin/adept/transcoder" ) @@ -18,15 +17,6 @@ var rootCmd = &cobra.Command{ Long: `An automated video transcoder service that archives ingested footage. https://git.metaunix.net/BitGoblin/adept`, Run: func(cmd *cobra.Command, args []string) { - // load configuration via Viper - config.LoadConfig() - - // configure our app logging - logHandle := config.InitLogging() - if logHandle != nil { - defer logHandle.Close() - } - // initialize the video repository r := transcoder.NewRepository(viper.GetString("transcoder.repository")) diff --git a/cmd/setup.go b/cmd/setup.go index 7404c7d..4bfa8e9 100644 --- a/cmd/setup.go +++ b/cmd/setup.go @@ -4,7 +4,6 @@ import ( "github.com/spf13/cobra" "github.com/spf13/viper" - "git.metaunix.net/BitGoblin/adept/config" "git.metaunix.net/BitGoblin/adept/transcoder" ) @@ -16,17 +15,8 @@ func init() { var setupCmd = &cobra.Command{ Use: "setup", Short: "Initialize the video directories.", - Long: `Adept can't run if it doesn't have a place to ingest/transcode files from.`, + Long: `Adept can't run gif it doesn't have a place to ingest/transcode files from.`, Run: func(cmd *cobra.Command, args []string) { - // load configuration via Viper - config.LoadConfig() - - // configure our app logging - logHandle := config.InitLogging() - if logHandle != nil { - defer logHandle.Close() - } - // initialize the video repository r := transcoder.NewRepository(viper.GetString("transcoder.repository")) r.Setup()