Skip to content

Commit

Permalink
refactor(update): use better error handling + disable disableTUI sh…
Browse files Browse the repository at this point in the history
…ortcut flag
  • Loading branch information
AzraelSec committed Dec 7, 2023
1 parent 5750cf5 commit 2edc776
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 5 deletions.
2 changes: 1 addition & 1 deletion cmd/cli/commands/update/cli.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ func newCli(repos []config.LiveRepo, output bool) *cli {
ctx, cancelCtx := signal.NotifyContext(context.Background(), os.Interrupt, os.Kill)

updateFn, updateArgs := runnerArgs(ctx, repos, output)
return &cli{ctx, cancelCtx, repos, updateFn, updateArgs, output}
return &cli{ctx, cancelCtx, repos, updateFn, updateArgs, output}
}

func (c *cli) run() {
Expand Down
5 changes: 3 additions & 2 deletions cmd/cli/commands/update/tui.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,16 +46,17 @@ func (t *tui) initModel() *model {
}
}

func (t *tui) run() {
func (t *tui) run() error {
m, err := tea.NewProgram(t.initModel()).Run()
if err != nil {
panic(err)
return err
}

tm := m.(*model)
if tm.status == ABORTED {
fmt.Println(ui.RED.Render("Update aborted!"))
}
return nil
}

type task struct {
Expand Down
4 changes: 2 additions & 2 deletions cmd/cli/commands/update/update.go
Original file line number Diff line number Diff line change
Expand Up @@ -124,15 +124,15 @@ func (u *update) Command() *cobra.Command {
if *disableTui {
newCli(u.cm.Repos, *output).run()
} else {
newTui(u.cm.Repos).run()
return newTui(u.cm.Repos).run()
}

return nil
},
}

output = cmd.Flags().BoolP("output", "o", false, "Print the updaters output on stdout (mostly debugging purposes)")
disableTui = cmd.Flags().BoolP("disableTui", "c", false, "Disable TUI")
disableTui = cmd.Flags().Bool("disableTui", false, "Disable TUI")

return cmd
}

0 comments on commit 2edc776

Please # to comment.