Merge pull request #2 from LeRoid-hub/dev

fav delete
This commit is contained in:
Jan 2024-09-20 16:37:49 +02:00 committed by GitHub
commit 3f917040a2
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 32 additions and 6 deletions

View File

@ -6,7 +6,9 @@ package cmd
import (
"fmt"
"github.com/manifoldco/promptui"
"github.com/spf13/cobra"
"github.com/spf13/viper"
)
// deleteCmd represents the delete command
@ -15,7 +17,35 @@ var deleteCmd = &cobra.Command{
Short: "Deletes a favorite mensa",
Long: `Returns a list of your favorite mensas and prompts you to select one to delete.`,
Run: func(cmd *cobra.Command, args []string) {
fmt.Println("delete called")
favorites := viper.Get("favorites").([]interface{})
s := make([]string, len(favorites))
for i, v := range favorites {
s[i] = v.(string)
}
prompt := promptui.Select{
Label: "Select Mensa to delete",
Items: s,
}
_, result, err := prompt.Run()
if err != nil {
fmt.Printf("Prompt failed %v\n", err)
return
}
for i := 0; i < len(s); i++ {
if s[i] == result {
s = append(s[:i], s[i+1:]...)
break
}
}
viper.Set("favorites", s)
viper.WriteConfig()
},
}

View File

@ -21,14 +21,11 @@ var favCmd = &cobra.Command{
You can add mensas to your favorites using the search command.`,
Run: func(cmd *cobra.Command, args []string) {
favorites := viper.Get("favorites").([]interface{})
fmt.Println(favorites)
s := make([]string, len(favorites))
for i, v := range favorites {
s[i] = v.(string)
}
fmt.Println(s, len(s), s[0])
for i := 0; i < len(s); i++ {
data, err := internal.GetMenu(s[i])
if err != nil {

View File

@ -4,7 +4,6 @@ Copyright © 2024 NAME HERE <EMAIL ADDRESS>
package cmd
import (
"fmt"
"os"
"github.com/spf13/cobra"
@ -74,7 +73,7 @@ func initConfig() {
viper.AutomaticEnv()
if err := viper.ReadInConfig(); err == nil {
fmt.Println("Using config file:", viper.ConfigFileUsed())
//fmt.Println("Using config file:", viper.ConfigFileUsed())
}
}