mirror of
https://github.com/LeRoid-hub/Mensa-CLI.git
synced 2025-01-31 03:34:57 +00:00
some config
This commit is contained in:
parent
17bf99c828
commit
0fc5b36843
10
cmd/root.go
10
cmd/root.go
@ -34,6 +34,10 @@ func Execute() {
|
|||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
cobra.OnInitialize(initConfig)
|
cobra.OnInitialize(initConfig)
|
||||||
|
|
||||||
|
setDefaults()
|
||||||
|
|
||||||
|
viper.SafeWriteConfig()
|
||||||
// Here you will define your flags and configuration settings.
|
// Here you will define your flags and configuration settings.
|
||||||
// Cobra supports persistent flags, which, if defined here,
|
// Cobra supports persistent flags, which, if defined here,
|
||||||
// will be global for your application.
|
// will be global for your application.
|
||||||
@ -48,6 +52,11 @@ func init() {
|
|||||||
rootCmd.CompletionOptions.DisableDefaultCmd = true
|
rootCmd.CompletionOptions.DisableDefaultCmd = true
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func setDefaults() {
|
||||||
|
viper.SetDefault("Server", "https://mensa.barfuss.email")
|
||||||
|
viper.SetDefault("favorites", []string{})
|
||||||
|
}
|
||||||
|
|
||||||
func initConfig() {
|
func initConfig() {
|
||||||
if cfgFile != "" {
|
if cfgFile != "" {
|
||||||
viper.SetConfigFile(cfgFile)
|
viper.SetConfigFile(cfgFile)
|
||||||
@ -60,6 +69,7 @@ func initConfig() {
|
|||||||
viper.SetConfigName(".Mensa-CLI")
|
viper.SetConfigName(".Mensa-CLI")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
viper.SetEnvPrefix("MENSA")
|
||||||
viper.AutomaticEnv()
|
viper.AutomaticEnv()
|
||||||
|
|
||||||
if err := viper.ReadInConfig(); err == nil {
|
if err := viper.ReadInConfig(); err == nil {
|
||||||
|
@ -12,6 +12,7 @@ import (
|
|||||||
"github.com/manifoldco/promptui"
|
"github.com/manifoldco/promptui"
|
||||||
"github.com/rodaine/table"
|
"github.com/rodaine/table"
|
||||||
"github.com/spf13/cobra"
|
"github.com/spf13/cobra"
|
||||||
|
"github.com/spf13/viper"
|
||||||
)
|
)
|
||||||
|
|
||||||
// searchCmd represents the search command
|
// searchCmd represents the search command
|
||||||
@ -112,7 +113,9 @@ var searchCmd = &cobra.Command{
|
|||||||
}
|
}
|
||||||
|
|
||||||
if result == "favorites" {
|
if result == "favorites" {
|
||||||
// viper
|
favorites := viper.Get("favorites").([]string)
|
||||||
|
favorites = append(favorites, selectedCity+"/"+selectedMensa)
|
||||||
|
viper.Set("favorites", favorites)
|
||||||
}
|
}
|
||||||
|
|
||||||
},
|
},
|
||||||
|
Loading…
Reference in New Issue
Block a user