2020-10-23 03:54:50 +13:00
|
|
|
package config
|
|
|
|
|
|
|
|
import (
|
|
|
|
"github.com/spf13/cobra"
|
|
|
|
"github.com/spf13/viper"
|
|
|
|
)
|
|
|
|
|
2020-11-02 06:39:12 +13:00
|
|
|
type Session struct {
|
2020-12-02 23:24:20 +13:00
|
|
|
Password string
|
|
|
|
AdminPassword string
|
|
|
|
ImplicitHosting bool
|
2020-12-07 05:28:15 +13:00
|
|
|
DatabaseAdapter string
|
|
|
|
FilePath string
|
2020-10-23 03:54:50 +13:00
|
|
|
}
|
|
|
|
|
2020-11-02 06:39:12 +13:00
|
|
|
func (Session) Init(cmd *cobra.Command) error {
|
2020-10-23 03:54:50 +13:00
|
|
|
cmd.PersistentFlags().String("password", "neko", "password for connecting to stream")
|
|
|
|
if err := viper.BindPFlag("password", cmd.PersistentFlags().Lookup("password")); err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
cmd.PersistentFlags().String("password_admin", "admin", "admin password for connecting to stream")
|
|
|
|
if err := viper.BindPFlag("password_admin", cmd.PersistentFlags().Lookup("password_admin")); err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
2020-12-02 23:24:20 +13:00
|
|
|
cmd.PersistentFlags().Bool("implicit_hosting", true, "allow implicit control switching")
|
|
|
|
if err := viper.BindPFlag("implicit_hosting", cmd.PersistentFlags().Lookup("implicit_hosting")); err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
2020-12-07 05:28:15 +13:00
|
|
|
cmd.PersistentFlags().String("database_adapter", "file", "choose database adapter for members")
|
|
|
|
if err := viper.BindPFlag("database_adapter", cmd.PersistentFlags().Lookup("database_adapter")); err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
cmd.PersistentFlags().String("file_path", "/home/neko/members.json", "file adapter: specify file path")
|
|
|
|
if err := viper.BindPFlag("file_path", cmd.PersistentFlags().Lookup("file_path")); err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
2020-10-23 03:54:50 +13:00
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2020-11-02 06:39:12 +13:00
|
|
|
func (s *Session) Set() {
|
2020-10-23 03:54:50 +13:00
|
|
|
s.Password = viper.GetString("password")
|
|
|
|
s.AdminPassword = viper.GetString("password_admin")
|
2020-12-02 23:24:20 +13:00
|
|
|
s.ImplicitHosting = viper.GetBool("implicit_hosting")
|
2020-12-07 05:28:15 +13:00
|
|
|
s.DatabaseAdapter = viper.GetString("database_adapter")
|
|
|
|
s.FilePath = viper.GetString("file_path")
|
2020-10-23 03:54:50 +13:00
|
|
|
}
|