-
Notifications
You must be signed in to change notification settings - Fork 0
/
delete.go
56 lines (50 loc) · 1.36 KB
/
delete.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
/*
Copyright © 2023 Utibeabasi Umanah utibeabasiumanah6@gmail.com
*/
package cmd
import (
"log"
"github.com/charmbracelet/bubbles/spinner"
tea "github.com/charmbracelet/bubbletea"
"github.com/charmbracelet/lipgloss"
"github.com/runvelocity/cli/internal/api"
"github.com/runvelocity/cli/internal/tui"
"github.com/spf13/cobra"
"github.com/spf13/viper"
)
var functionNameToDelete string
func initialDeleteModel() tui.DeleteModel {
return tui.DeleteModel{
Function: nil,
ApiClient: api.ApiClient{
BaseUrl: viper.Get("managerurl").(string),
},
Error: nil,
Spinner: spinner.New(
spinner.WithSpinner(spinner.Dot),
spinner.WithStyle(lipgloss.NewStyle().Foreground(lipgloss.Color("205"))),
),
Name: functionNameToDelete,
}
}
// deleteCmd represents the delete command
var deleteCmd = &cobra.Command{
Use: "delete",
Short: "Delete a function",
Run: func(cmd *cobra.Command, args []string) {
// Send the UI for rendering
deleteTuiModel := initialDeleteModel()
p := tea.NewProgram(deleteTuiModel)
if _, err := p.Run(); err != nil {
log.Fatalf("Alas, there's been an error: %v", err)
}
},
}
func init() {
rootCmd.AddCommand(deleteCmd)
deleteCmd.Flags().StringVar(&functionNameToDelete, "name", "", "Function name to delete")
err := deleteCmd.MarkFlagRequired("name")
if err != nil {
log.Fatalln("A fatal error occured: " + err.Error())
}
}