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
All checks were successful
ci/woodpecker/push/woodpecker Pipeline was successful
ci/woodpecker/tag/woodpecker Pipeline was successful

This commit is contained in:
Gregory Ballantine 2022-09-15 10:09:10 -04:00
parent 4d77a0e2bc
commit 1ccd481f9e
3 changed files with 12 additions and 21 deletions

View File

@ -2,9 +2,20 @@ package main
import ( import (
"git.metaunix.net/BitGoblin/adept/cmd" "git.metaunix.net/BitGoblin/adept/cmd"
"git.metaunix.net/BitGoblin/adept/config"
) )
// start the app - that's where all the good stuff happens // start the app - that's where all the good stuff happens
func main() { 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() cmd.Execute()
} }

View File

@ -7,7 +7,6 @@ import (
"github.com/spf13/cobra" "github.com/spf13/cobra"
"github.com/spf13/viper" "github.com/spf13/viper"
"git.metaunix.net/BitGoblin/adept/config"
"git.metaunix.net/BitGoblin/adept/transcoder" "git.metaunix.net/BitGoblin/adept/transcoder"
) )
@ -18,15 +17,6 @@ var rootCmd = &cobra.Command{
Long: `An automated video transcoder service that archives ingested footage. Long: `An automated video transcoder service that archives ingested footage.
https://git.metaunix.net/BitGoblin/adept`, https://git.metaunix.net/BitGoblin/adept`,
Run: func(cmd *cobra.Command, args []string) { 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 // initialize the video repository
r := transcoder.NewRepository(viper.GetString("transcoder.repository")) r := transcoder.NewRepository(viper.GetString("transcoder.repository"))

View File

@ -4,7 +4,6 @@ import (
"github.com/spf13/cobra" "github.com/spf13/cobra"
"github.com/spf13/viper" "github.com/spf13/viper"
"git.metaunix.net/BitGoblin/adept/config"
"git.metaunix.net/BitGoblin/adept/transcoder" "git.metaunix.net/BitGoblin/adept/transcoder"
) )
@ -16,17 +15,8 @@ func init() {
var setupCmd = &cobra.Command{ var setupCmd = &cobra.Command{
Use: "setup", Use: "setup",
Short: "Initialize the video directories.", 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) { 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 // initialize the video repository
r := transcoder.NewRepository(viper.GetString("transcoder.repository")) r := transcoder.NewRepository(viper.GetString("transcoder.repository"))
r.Setup() r.Setup()