mirror of
https://github.com/LeRoid-hub/Mensa-CLI.git
synced 2025-01-31 03:34:57 +00:00
fav delete
This commit is contained in:
parent
0f3200a8fe
commit
1a21f47555
@ -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()
|
||||
|
||||
},
|
||||
}
|
||||
|
||||
|
@ -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 {
|
||||
|
@ -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())
|
||||
}
|
||||
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user