Archived
2
0
This repository has been archived on 2024-06-24. You can view files and clone it, but cannot push or open issues or pull requests.
neko-custom/server/internal/config/root.go

38 lines
866 B
Go
Raw Permalink Normal View History

2020-01-13 21:05:38 +13:00
package config
import (
"github.com/spf13/cobra"
"github.com/spf13/viper"
)
type Root struct {
Debug bool
Logs bool
CfgFile string
}
func (Root) Init(cmd *cobra.Command) error {
2020-01-29 14:27:59 +13:00
cmd.PersistentFlags().BoolP("debug", "d", false, "enable debug mode")
2020-01-13 21:05:38 +13:00
if err := viper.BindPFlag("debug", cmd.PersistentFlags().Lookup("debug")); err != nil {
return err
}
2020-01-29 14:27:59 +13:00
cmd.PersistentFlags().BoolP("logs", "l", false, "save logs to file")
2020-01-13 21:05:38 +13:00
if err := viper.BindPFlag("logs", cmd.PersistentFlags().Lookup("logs")); err != nil {
return err
}
2020-01-29 14:27:59 +13:00
cmd.PersistentFlags().String("config", "", "configuration file path")
2020-01-13 21:05:38 +13:00
if err := viper.BindPFlag("config", cmd.PersistentFlags().Lookup("config")); err != nil {
return err
}
return nil
}
func (s *Root) Set() {
s.Logs = viper.GetBool("logs")
s.Debug = viper.GetBool("debug")
s.CfgFile = viper.GetString("config")
}