mirror of
https://github.com/LeRoid-hub/Mensa-CLI.git
synced 2025-01-31 03:34:57 +00:00
viper not working
This commit is contained in:
parent
0fc5b36843
commit
86048da2cb
22
cmd/fav.go
22
cmd/fav.go
@ -1,27 +1,31 @@
|
||||
/*
|
||||
Copyright © 2024 NAME HERE <EMAIL ADDRESS>
|
||||
|
||||
*/
|
||||
package cmd
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"strings"
|
||||
|
||||
"github.com/spf13/cobra"
|
||||
"github.com/spf13/viper"
|
||||
)
|
||||
|
||||
// favCmd represents the fav command
|
||||
var favCmd = &cobra.Command{
|
||||
Use: "fav",
|
||||
Short: "A brief description of your command",
|
||||
Long: `A longer description that spans multiple lines and likely contains examples
|
||||
and usage of using your command. For example:
|
||||
|
||||
Cobra is a CLI library for Go that empowers applications.
|
||||
This application is a tool to generate the needed files
|
||||
to quickly create a Cobra application.`,
|
||||
Short: "Retrieves the favorite mensa menus",
|
||||
Long: `Retrieves the favorite mensa menus for the current day.
|
||||
You can add mensas to your favorites using the search command.`,
|
||||
Run: func(cmd *cobra.Command, args []string) {
|
||||
fmt.Println("fav called")
|
||||
favorites := viper.GetStringSlice("favorites")
|
||||
if len(favorites) == 0 {
|
||||
fmt.Println("You have no favorites")
|
||||
return
|
||||
}
|
||||
|
||||
fmt.Println("Your favorites: " + strings.Join(favorites, ", "))
|
||||
|
||||
},
|
||||
}
|
||||
|
||||
|
@ -115,7 +115,10 @@ var searchCmd = &cobra.Command{
|
||||
if result == "favorites" {
|
||||
favorites := viper.Get("favorites").([]string)
|
||||
favorites = append(favorites, selectedCity+"/"+selectedMensa)
|
||||
fmt.Println("Added " + selectedCity + "/" + selectedMensa + " to your favorites")
|
||||
viper.Set("favorites", favorites)
|
||||
fmt.Println(viper.Get("favorites"))
|
||||
viper.SafeWriteConfig()
|
||||
}
|
||||
|
||||
},
|
||||
|
Loading…
Reference in New Issue
Block a user