2022-04-16 07:28:00 +12:00
|
|
|
package config
|
|
|
|
|
|
|
|
import (
|
|
|
|
"github.com/spf13/cobra"
|
|
|
|
"github.com/spf13/viper"
|
|
|
|
)
|
|
|
|
|
|
|
|
type Plugins struct {
|
2023-03-31 23:02:33 +13:00
|
|
|
Enabled bool
|
|
|
|
Dir string
|
|
|
|
Required bool
|
2022-04-16 07:28:00 +12:00
|
|
|
}
|
|
|
|
|
|
|
|
func (Plugins) Init(cmd *cobra.Command) error {
|
|
|
|
cmd.PersistentFlags().Bool("plugins.enabled", false, "load plugins in runtime")
|
|
|
|
if err := viper.BindPFlag("plugins.enabled", cmd.PersistentFlags().Lookup("plugins.enabled")); err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
cmd.PersistentFlags().String("plugins.dir", "./bin/plugins", "path to neko plugins to load")
|
|
|
|
if err := viper.BindPFlag("plugins.dir", cmd.PersistentFlags().Lookup("plugins.dir")); err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
2023-03-31 23:02:33 +13:00
|
|
|
cmd.PersistentFlags().Bool("plugins.required", false, "if true, neko will exit if there is an error when loading a plugin")
|
|
|
|
if err := viper.BindPFlag("plugins.required", cmd.PersistentFlags().Lookup("plugins.required")); err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
2022-04-16 07:28:00 +12:00
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func (s *Plugins) Set() {
|
|
|
|
s.Enabled = viper.GetBool("plugins.enabled")
|
|
|
|
s.Dir = viper.GetString("plugins.dir")
|
2023-03-31 23:02:33 +13:00
|
|
|
s.Required = viper.GetBool("plugins.required")
|
2022-04-16 07:28:00 +12:00
|
|
|
}
|