-
Notifications
You must be signed in to change notification settings - Fork 10
/
continue.go
104 lines (90 loc) · 2.32 KB
/
continue.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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
package externalsecret
import (
"fmt"
"github.com/charmbracelet/bubbles/list"
tea "github.com/charmbracelet/bubbletea"
"github.com/AliyunContainerService/ack-secret-manager/ack-secret-manager-cli/pkg/k8s"
"github.com/AliyunContainerService/ack-secret-manager/ack-secret-manager-cli/pkg/model"
"github.com/AliyunContainerService/ack-secret-manager/ack-secret-manager-cli/pkg/model/info"
)
type ContinueModel struct {
list list.Model
choice string
quitting bool
preModel model.Model
}
func init() {
m := initContinueModel()
model.InitModelMap["continue"] = m
}
func initContinueModel() *ContinueModel {
items := []list.Item{
item("Yes"),
item("No"),
}
l := list.New(items, itemDelegate{}, defaultWidth, listHeight)
l.SetShowStatusBar(false)
l.SetFilteringEnabled(false)
l.Styles.Title = titleStyle
l.Styles.PaginationStyle = paginationStyle
l.Styles.HelpStyle = helpStyle
return &ContinueModel{
list: l,
}
}
func (m *ContinueModel) Init() tea.Cmd {
return nil
}
func (m *ContinueModel) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
switch msg := msg.(type) {
case tea.WindowSizeMsg:
m.list.SetWidth(msg.Width)
return m, nil
case tea.KeyMsg:
switch keypress := msg.String(); keypress {
case "ctrl+c":
m.quitting = true
return m, tea.Quit
case "enter":
i, ok := m.list.SelectedItem().(item)
if ok {
m.choice = string(i)
}
return m.Next()
}
}
var cmd tea.Cmd
m.list, cmd = m.list.Update(msg)
return m, cmd
}
func (m *ContinueModel) View() string {
return "\n" + m.list.View()
}
func (m *ContinueModel) SetPreModel(preModel model.Model) {
m.preModel = preModel
}
func (m *ContinueModel) SetTitle(title string) {
m.list.Title = title
}
func (m *ContinueModel) Next() (model.Model, tea.Cmd) {
tempModel := model.InitModelMap["info"]
eModel, ok := tempModel.(*info.InfoModel)
if !ok {
return m, nil
}
if m.choice == "Yes" {
next := model.InitModelMap["data"]
next.SetPreModel(m)
return next, nil
} else {
err := k8s.CreateExternalSecret(data, process, externalSecretName, externalSecretNamespace, secretType)
if err != nil {
eModel.SetInfo(err.Error())
eModel.SetPreModel(nil)
return eModel, nil
}
eModel.SetInfo(fmt.Sprintf("create externalsecret %s/%s success", externalSecretNamespace, externalSecretName))
eModel.SetPreModel(nil)
return eModel, nil
}
}