mirror of
https://github.com/Valkyrie00/bold-brew.git
synced 2026-03-14 14:25:53 +01:00
added update all packages command
This commit is contained in:
parent
8c0937601a
commit
fc8f5db5fd
3 changed files with 35 additions and 3 deletions
|
|
@ -8,6 +8,7 @@ import (
|
|||
)
|
||||
|
||||
type CommandServiceInterface interface {
|
||||
UpdateAllPackages(app *tview.Application, outputView *tview.TextView) error
|
||||
UpdatePackage(info models.Formula, app *tview.Application, outputView *tview.TextView) error
|
||||
RemovePackage(info models.Formula, app *tview.Application, outputView *tview.TextView) error
|
||||
InstallPackage(info models.Formula, app *tview.Application, outputView *tview.TextView) error
|
||||
|
|
@ -20,6 +21,11 @@ var NewCommandService = func() CommandServiceInterface {
|
|||
return &CommandService{}
|
||||
}
|
||||
|
||||
func (s *CommandService) UpdateAllPackages(app *tview.Application, outputView *tview.TextView) error {
|
||||
cmd := exec.Command("brew", "upgrade") // #nosec G204
|
||||
return s.executeCommand(app, cmd, outputView)
|
||||
}
|
||||
|
||||
func (s *CommandService) UpdatePackage(info models.Formula, app *tview.Application, outputView *tview.TextView) error {
|
||||
cmd := exec.Command("brew", "upgrade", info.Name) // #nosec G204
|
||||
return s.executeCommand(app, cmd, outputView)
|
||||
|
|
|
|||
|
|
@ -24,7 +24,7 @@ func (s *AppService) handleKeyEventInput(event *tcell.EventKey) *tcell.EventKey
|
|||
action()
|
||||
}
|
||||
},
|
||||
tcell.KeyCtrlU: s.handleUpdateHomebrewEvent,
|
||||
tcell.KeyCtrlU: s.handleUpdateAllPackagesEvent,
|
||||
tcell.KeyEsc: func() {
|
||||
s.app.SetRoot(s.LayoutService.GetGrid(), true).SetFocus(s.LayoutService.GetResultTable())
|
||||
},
|
||||
|
|
@ -46,8 +46,8 @@ func (s *AppService) handleQuitEvent() {
|
|||
s.app.Stop()
|
||||
}
|
||||
|
||||
//lint:ignore U1000 Temporarily unused
|
||||
func (s *AppService) handleUpdateHomebrewEvent() {
|
||||
// Update homebrew
|
||||
modal := s.LayoutService.GenerateModal("Are you sure you want to update Homebrew?", func() {
|
||||
s.app.SetRoot(s.LayoutService.GetGrid(), true).SetFocus(s.LayoutService.GetResultTable())
|
||||
s.LayoutService.GetOutputView().Clear()
|
||||
|
|
@ -129,3 +129,18 @@ func (s *AppService) handleUpdatePackageEvent() {
|
|||
s.app.SetRoot(modal, true).SetFocus(modal)
|
||||
}
|
||||
}
|
||||
|
||||
func (s *AppService) handleUpdateAllPackagesEvent() {
|
||||
modal := s.LayoutService.GenerateModal("Are you sure you want to update all packages?", func() {
|
||||
s.app.SetRoot(s.LayoutService.GetGrid(), true).SetFocus(s.LayoutService.GetResultTable())
|
||||
s.LayoutService.GetOutputView().Clear()
|
||||
go func() {
|
||||
if err := s.CommandService.UpdateAllPackages(s.app, s.LayoutService.GetOutputView()); err == nil {
|
||||
s.forceRefreshResults()
|
||||
}
|
||||
}()
|
||||
}, func() {
|
||||
s.app.SetRoot(s.LayoutService.GetGrid(), true).SetFocus(s.LayoutService.GetResultTable())
|
||||
})
|
||||
s.app.SetRoot(modal, true).SetFocus(modal)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -102,8 +102,19 @@ func (s *LayoutService) GetLegendView() *tview.TextView {
|
|||
}
|
||||
|
||||
func (s *LayoutService) SetLegendView() {
|
||||
legendText := tview.Escape(
|
||||
"[/] Search | " +
|
||||
"[f] Filter Installed | " +
|
||||
"[i] Install | " +
|
||||
"[u] Update | " +
|
||||
"[ctrl+u] Update All | " +
|
||||
"[r] Remove | " +
|
||||
"[Esc] Back to Table | " +
|
||||
"[q] Quit",
|
||||
)
|
||||
|
||||
s.legend = tview.NewTextView().
|
||||
SetText(tview.Escape("[/] Search | [f] Filter Installed | [i] Install | [u] Update | [r] Remove | [Esc] Back to Table | [ctrl+u] Update Homebrew | [q] Quit")).
|
||||
SetText(legendText).
|
||||
SetDynamicColors(true).
|
||||
SetTextAlign(tview.AlignCenter)
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue