Skip to content

Commit f80d63e

Browse files
committed
fix: fix cleanup value files
1 parent e87eda6 commit f80d63e

File tree

2 files changed

+21
-17
lines changed

2 files changed

+21
-17
lines changed

Diff for: repositories/install.go

+18-17
Original file line numberDiff line numberDiff line change
@@ -75,20 +75,25 @@ func (m InstallModel) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
7575
}
7676
m.Inputs[i].Blur()
7777
}
78+
return m, tea.Batch(cmds...)
79+
case types.InstallMsg:
80+
m.installStep = 0
81+
releaseName := m.Inputs[nameStep].Value()
82+
namespace := m.Inputs[namespaceStep].Value()
83+
if namespace == "" {
84+
namespace = "default"
85+
}
86+
folder := fmt.Sprintf("%s/%s", namespace, releaseName)
87+
cmds = append(cmds, m.cleanValueFile(folder), m.blurAllInputs(), m.resetAllInputs())
88+
7889
return m, tea.Batch(cmds...)
7990
case tea.KeyMsg:
8091
switch msg.String() {
8192
case "enter":
8293
if m.installStep == confirmStep {
8394
m.installStep = 0
8495

85-
cmd = m.installPackage()
86-
cmds = append(cmds, cmd)
87-
88-
cmd = m.blurAllInputs()
89-
cmds = append(cmds, cmd)
90-
91-
cmd = m.resetAllInputs()
96+
cmd = m.installPackage(m.Inputs[valuesStep].Value())
9297
cmds = append(cmds, cmd)
9398

9499
return m, tea.Batch(cmds...)
@@ -167,7 +172,7 @@ func (m InstallModel) resetAllInputs() tea.Cmd {
167172
return nil
168173
}
169174

170-
func (m InstallModel) installPackage() tea.Cmd {
175+
func (m InstallModel) installPackage(mode string) tea.Cmd {
171176
releaseName := m.Inputs[nameStep].Value()
172177
namespace := m.Inputs[namespaceStep].Value()
173178
if namespace == "" {
@@ -180,7 +185,7 @@ func (m InstallModel) installPackage() tea.Cmd {
180185

181186
var cmd *exec.Cmd
182187
// Create the command
183-
if m.Inputs[valuesStep].Value() == "y" {
188+
if mode == "y" {
184189
cmd = exec.Command("helm", "install", releaseName, m.Chart, "--version", m.Version, "--values", file, "--namespace", namespace, "--create-namespace")
185190
} else {
186191
cmd = exec.Command("helm", "install", releaseName, m.Chart, "--version", m.Version, "--namespace", namespace, "--create-namespace")
@@ -234,13 +239,9 @@ func (m InstallModel) openEditorDefaultValues() tea.Cmd {
234239
})
235240
}
236241

237-
func (m InstallModel) cleanValueFile() tea.Msg {
238-
releaseName := m.Inputs[nameStep].Value()
239-
namespace := m.Inputs[namespaceStep].Value()
240-
if namespace == "" {
241-
namespace = "default"
242+
func (m InstallModel) cleanValueFile(folder string) tea.Cmd {
243+
return func() tea.Msg {
244+
_ = os.RemoveAll(folder)
245+
return nil
242246
}
243-
folder := fmt.Sprintf("%s/%s", namespace, releaseName)
244-
_ = os.RemoveAll(folder)
245-
return nil
246247
}

Diff for: repositories/ui.go

+3
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,9 @@ func (m Model) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
122122
}
123123
case types.InstallMsg:
124124
m.installing = false
125+
mod, cmd := m.installModel.Update(msg)
126+
cmds = append(cmds, cmd)
127+
m.installModel = mod.(InstallModel)
125128
return m, cmd
126129
}
127130
mod, cmd := m.installModel.Update(msg)

0 commit comments

Comments
 (0)