diff --git a/internal/services/command.go b/internal/services/command.go index abccea4..f312ffd 100644 --- a/internal/services/command.go +++ b/internal/services/command.go @@ -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) diff --git a/internal/services/io.go b/internal/services/io.go index 46198af..d5d3c48 100644 --- a/internal/services/io.go +++ b/internal/services/io.go @@ -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) +} diff --git a/internal/services/layout.go b/internal/services/layout.go index d90ee0e..874932f 100644 --- a/internal/services/layout.go +++ b/internal/services/layout.go @@ -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) }