mirror of
https://github.com/m1k1o/neko.git
synced 2024-07-24 14:40:50 +12:00
configs to root.
This commit is contained in:
parent
62353c776d
commit
66d22dede4
22
cmd/root.go
22
cmd/root.go
@ -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())
|
||||
|
@ -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
42
neko.go
@ -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
|
||||
|
Loading…
Reference in New Issue
Block a user