diff --git a/confirm/command.go b/confirm/command.go index ac151ad..103fbad 100644 --- a/confirm/command.go +++ b/confirm/command.go @@ -7,12 +7,25 @@ import ( "github.com/charmbracelet/bubbles/help" tea "github.com/charmbracelet/bubbletea" + "github.com/charmbracelet/gum/internal/stdin" "github.com/charmbracelet/gum/internal/timeout" ) +var errNotConfirmed = errors.New("not confirmed") + // Run provides a shell script interface for prompting a user to confirm an // action with an affirmative or negative answer. func (o Options) Run() error { + line, err := stdin.Read(stdin.SingleLine(true)) + if err == nil { + switch line { + case "yes", "y": + return nil + default: + return errNotConfirmed + } + } + ctx, cancel := timeout.Context(o.Timeout) defer cancel() @@ -52,5 +65,5 @@ func (o Options) Run() error { return nil } - return errors.New("not confirmed") + return errNotConfirmed }