configs to root.

This commit is contained in:
Miroslav Šedivý 2022-01-14 00:22:23 +01:00
parent 62353c776d
commit 66d22dede4
3 changed files with 20 additions and 53 deletions

View File

@ -16,6 +16,8 @@ import (
"github.com/spf13/viper"
"demodesk/neko"
"demodesk/neko/internal/config"
"demodesk/neko/modules"
)
func Execute() error {
@ -30,6 +32,16 @@ var root = &cobra.Command{
}
func init() {
configs := append([]config.Config{
neko.Service.Configs.Root,
neko.Service.Configs.Desktop,
neko.Service.Configs.Capture,
neko.Service.Configs.WebRTC,
neko.Service.Configs.Member,
neko.Service.Configs.Session,
neko.Service.Configs.Server,
}, modules.Configs()...)
cobra.OnInitialize(func() {
//////
// logs
@ -126,11 +138,15 @@ func init() {
}
}
neko.Service.Configs.Root.Set()
for _, cfg := range configs {
cfg.Set()
}
})
if err := neko.Service.Configs.Root.Init(root); err != nil {
log.Panic().Err(err).Msg("unable to run root command")
for _, cfg := range configs {
if err := cfg.Init(root); err != nil {
log.Panic().Err(err).Msg("unable to initialize configuration")
}
}
root.SetVersionTemplate(neko.Service.Version.Details())

View File

@ -33,14 +33,7 @@ func init() {
Run: service.ServeCommand,
}
cobra.OnInitialize(func() {
service.Configs.Set()
service.Preflight()
})
if err := service.Configs.Init(command); err != nil {
log.Panic().Err(err).Msg("unable to run serve command")
}
cobra.OnInitialize(service.Preflight)
root.AddCommand(command)
}

42
neko.go
View File

@ -4,10 +4,7 @@ import (
"fmt"
"runtime"
"github.com/spf13/cobra"
"demodesk/neko/internal/config"
"demodesk/neko/modules"
)
const Header = `&34
@ -101,45 +98,6 @@ type Configs struct {
Server *config.Server
}
func (i *Configs) Set() {
i.Root.Set()
i.Desktop.Set()
i.Capture.Set()
i.WebRTC.Set()
i.Member.Set()
i.Session.Set()
i.Server.Set()
modules.SetConfigs()
}
func (i *Configs) Init(cmd *cobra.Command) error {
if err := i.Root.Init(cmd); err != nil {
return err
}
if err := i.Desktop.Init(cmd); err != nil {
return err
}
if err := i.Capture.Init(cmd); err != nil {
return err
}
if err := i.WebRTC.Init(cmd); err != nil {
return err
}
if err := i.Member.Init(cmd); err != nil {
return err
}
if err := i.Session.Init(cmd); err != nil {
return err
}
if err := i.Server.Init(cmd); err != nil {
return err
}
if err := modules.InitConfigs(cmd); err != nil {
return err
}
return nil
}
type Neko struct {
Version *Version
Configs *Configs