neko/internal/config/member.go

45 lines
1.3 KiB
Go
Raw Normal View History

2021-03-14 13:08:50 +13:00
package config
import (
"github.com/spf13/cobra"
"github.com/spf13/viper"
)
type Member struct {
Provider string
FilePath string
Password string
AdminPassword string
}
func (Member) Init(cmd *cobra.Command) error {
2021-03-15 01:06:48 +13:00
cmd.PersistentFlags().String("members_provider", "object", "choose members provider")
2021-03-14 13:08:50 +13:00
if err := viper.BindPFlag("members_provider", cmd.PersistentFlags().Lookup("members_provider")); err != nil {
return err
}
2021-03-15 01:06:48 +13:00
cmd.PersistentFlags().String("members_file_path", "", "mebmer file provider path")
2021-03-14 13:08:50 +13:00
if err := viper.BindPFlag("members_file_path", cmd.PersistentFlags().Lookup("members_file_path")); err != nil {
return err
}
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
}
return nil
}
func (s *Member) Set() {
s.Provider = viper.GetString("members_provider")
s.FilePath = viper.GetString("members_file_path")
s.Password = viper.GetString("password")
s.AdminPassword = viper.GetString("password_admin")
}