command.go
This file
Path
confirm/command.go
71 lines · 1.6 KiB · Go
Last changed by
chore: prepare v2 (#1116)Drew Smirnoffbefore adoption02d6f06
History of this fileTake it
The walk stopped after 200 commits: lines older than 6837ed2 point at it.
feat(deps): bump github.com/charmbracelet/bubbletea from 0.27.0 to 1.0.0 (#661)dependabot[bot]before adoption6837ed2
lines 1–3why, one step back1package confirm23import (fix: detect timeout error and apply default option (#888)Miguel Ibarsbefore adoptione292bbf
line 4why, one step back4 "context"feat: handle interrupts and timeouts (#747)Carlos Alexandro Beckerbefore adoption4f46952
line 5why, one step back5 "fmt"feat(deps): bump github.com/charmbracelet/bubbletea from 0.27.0 to 1.0.0 (#661)dependabot[bot]before adoption6837ed2
lines 6–7why, one step back6 "os"7chore: update to bubbletea v2 (#1112)Drew Smirnoffbefore adoptionf6dd28e
lines 8–9why, one step back8 "charm.land/bubbles/v2/help"9 tea "charm.land/bubbletea/v2"chore: prepare v2 (#1116)Drew Smirnoffbefore adoption02d6f06
lines 10–13why, one step back10 "charm.land/gum/v2/internal/exit"11 "charm.land/gum/v2/internal/stdin"12 "charm.land/gum/v2/internal/timeout"13 "charm.land/gum/v2/style"feat(deps): bump github.com/charmbracelet/bubbletea from 0.27.0 to 1.0.0 (#661)dependabot[bot]before adoption6837ed2
lines 14–18why, one step back14)1516// Run provides a shell script interface for prompting a user to confirm an17// action with an affirmative or negative answer.18func (o Options) Run() error {feat: yes|gum confirm (#772)Carlos Alexandro Beckerbefore adoption0b89ff8
lines 19–24why, one step back19 line, err := stdin.Read(stdin.SingleLine(true))20 if err == nil {21 switch line {22 case "yes", "y":23 return nil24 default:fix(confirm): do not print 'not confirmed' on exit 1 (#814)Carlos Alexandro Beckerbefore adoption30bc180
line 25why, one step back25 return exit.ErrExit(1)feat: yes|gum confirm (#772)Carlos Alexandro Beckerbefore adoption0b89ff8
lines 26–28why, one step back26 }27 }28feat: handle interrupts and timeouts (#747)Carlos Alexandro Beckerbefore adoption4f46952
lines 29–31why, one step back29 ctx, cancel := timeout.Context(o.Timeout)30 defer cancel()31feat: adding --padding to most commands (#960)Carlos Alexandro Beckerbefore adoption6045525
line 32why, one step back32 top, right, bottom, left := style.ParsePadding(o.Padding)feat: handle interrupts and timeouts (#747)Carlos Alexandro Beckerbefore adoption4f46952
line 33why, one step back33 m := model{refactor: removing huh as a dep (#742)Carlos Alexandro Beckerbefore adoptione30fc5e
lines 34–35why, one step back34 affirmative: o.Affirmative,35 negative: o.Negative,feat(confirm): add `--show-output` (#427)vahnrrbefore adoptiond1bfd56
line 36why, one step back36 showOutput: o.ShowOutput,refactor: removing huh as a dep (#742)Carlos Alexandro Beckerbefore adoptione30fc5e
lines 37–45why, one step back37 confirmation: o.Default,38 defaultSelection: o.Default,39 keys: defaultKeymap(o.Affirmative, o.Negative),40 help: help.New(),41 showHelp: o.ShowHelp,42 prompt: o.Prompt,43 selectedStyle: o.SelectedStyle.ToLipgloss(),44 unselectedStyle: o.UnselectedStyle.ToLipgloss(),45 promptStyle: o.PromptStyle.ToLipgloss(),feat: adding --padding to most commands (#960)Carlos Alexandro Beckerbefore adoption6045525
line 46why, one step back46 padding: []int{top, right, bottom, left},feat: handle interrupts and timeouts (#747)Carlos Alexandro Beckerbefore adoption4f46952
lines 47–52why, one step back47 }48 tm, err := tea.NewProgram(49 m,50 tea.WithOutput(os.Stderr),51 tea.WithContext(ctx),52 ).Run()fix: detect timeout error and apply default option (#888)Miguel Ibarsbefore adoptione292bbf
line 53why, one step back53 if err != nil && ctx.Err() != context.DeadlineExceeded {feat: handle interrupts and timeouts (#747)Carlos Alexandro Beckerbefore adoption4f46952
line 54why, one step back54 return fmt.Errorf("unable to confirm: %w", err)feat(confirm): add `--show-output` (#427)vahnrrbefore adoptiond1bfd56
line 55why, one step back55 }fix(confirm): ensure `--show-output` show the right answer (#853)Andrey Neringbefore adoption2b72e80
line 56why, one step back56 m = tm.(model)feat(confirm): add `--show-output` (#427)vahnrrbefore adoptiond1bfd56
lines 57–63why, one step back5758 if o.ShowOutput {59 confirmationText := m.negative60 if m.confirmation {61 confirmationText = m.affirmative62 }63 fmt.Println(m.prompt, confirmationText)feat(deps): bump github.com/charmbracelet/bubbletea from 0.27.0 to 1.0.0 (#661)dependabot[bot]before adoption6837ed2
lines 64–65why, one step back64 }65refactor: removing huh as a dep (#742)Carlos Alexandro Beckerbefore adoptione30fc5e
lines 66–68why, one step back66 if m.confirmation {67 return nil68 }feat(deps): bump github.com/charmbracelet/bubbletea from 0.27.0 to 1.0.0 (#661)dependabot[bot]before adoption6837ed2
line 69why, one step back69fix(confirm): do not print 'not confirmed' on exit 1 (#814)Carlos Alexandro Beckerbefore adoption30bc180
line 70why, one step back70 return exit.ErrExit(1)feat(deps): bump github.com/charmbracelet/bubbletea from 0.27.0 to 1.0.0 (#661)dependabot[bot]before adoption6837ed2
line 71why, one step back71}