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
|
|
|
ImplicitHosting bool
|
2021-03-16 01:34:14 +13:00
|
|
|
APIToken string
|
2020-10-23 03:54:50 +13:00
|
|
|
}
|
|
|
|
|
2020-11-02 06:39:12 +13:00
|
|
|
func (Session) Init(cmd *cobra.Command) error {
|
2021-03-17 03:24:58 +13:00
|
|
|
cmd.PersistentFlags().Bool("session.implicit_hosting", true, "allow implicit control switching")
|
|
|
|
if err := viper.BindPFlag("session.implicit_hosting", cmd.PersistentFlags().Lookup("session.implicit_hosting")); err != nil {
|
2020-12-02 23:24:20 +13:00
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
2021-03-17 03:24:58 +13:00
|
|
|
cmd.PersistentFlags().String("session.api_token", "", "API token for interacting with external services")
|
|
|
|
if err := viper.BindPFlag("session.api_token", cmd.PersistentFlags().Lookup("session.api_token")); err != nil {
|
2021-03-16 01:34:14 +13:00
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
2020-10-23 03:54:50 +13:00
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2020-11-02 06:39:12 +13:00
|
|
|
func (s *Session) Set() {
|
2021-03-17 03:24:58 +13:00
|
|
|
s.ImplicitHosting = viper.GetBool("session.implicit_hosting")
|
|
|
|
s.APIToken = viper.GetString("session.api_token")
|
2020-10-23 03:54:50 +13:00
|
|
|
}
|