mirror of
https://github.com/LeRoid-hub/Mensa-CLI.git
synced 2025-01-31 03:34:57 +00:00
commit
3f917040a2
@ -6,7 +6,9 @@ package cmd
|
|||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
|
|
||||||
|
"github.com/manifoldco/promptui"
|
||||||
"github.com/spf13/cobra"
|
"github.com/spf13/cobra"
|
||||||
|
"github.com/spf13/viper"
|
||||||
)
|
)
|
||||||
|
|
||||||
// deleteCmd represents the delete command
|
// deleteCmd represents the delete command
|
||||||
@ -15,7 +17,35 @@ var deleteCmd = &cobra.Command{
|
|||||||
Short: "Deletes a favorite mensa",
|
Short: "Deletes a favorite mensa",
|
||||||
Long: `Returns a list of your favorite mensas and prompts you to select one to delete.`,
|
Long: `Returns a list of your favorite mensas and prompts you to select one to delete.`,
|
||||||
Run: func(cmd *cobra.Command, args []string) {
|
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.`,
|
You can add mensas to your favorites using the search command.`,
|
||||||
Run: func(cmd *cobra.Command, args []string) {
|
Run: func(cmd *cobra.Command, args []string) {
|
||||||
favorites := viper.Get("favorites").([]interface{})
|
favorites := viper.Get("favorites").([]interface{})
|
||||||
fmt.Println(favorites)
|
|
||||||
|
|
||||||
s := make([]string, len(favorites))
|
s := make([]string, len(favorites))
|
||||||
for i, v := range favorites {
|
for i, v := range favorites {
|
||||||
s[i] = v.(string)
|
s[i] = v.(string)
|
||||||
}
|
}
|
||||||
fmt.Println(s, len(s), s[0])
|
|
||||||
|
|
||||||
for i := 0; i < len(s); i++ {
|
for i := 0; i < len(s); i++ {
|
||||||
data, err := internal.GetMenu(s[i])
|
data, err := internal.GetMenu(s[i])
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -4,7 +4,6 @@ Copyright © 2024 NAME HERE <EMAIL ADDRESS>
|
|||||||
package cmd
|
package cmd
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
|
||||||
"os"
|
"os"
|
||||||
|
|
||||||
"github.com/spf13/cobra"
|
"github.com/spf13/cobra"
|
||||||
@ -74,7 +73,7 @@ func initConfig() {
|
|||||||
viper.AutomaticEnv()
|
viper.AutomaticEnv()
|
||||||
|
|
||||||
if err := viper.ReadInConfig(); err == nil {
|
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