feat: yes|gum confirm (#772)

* feat: yes|gum confirm

Signed-off-by: Carlos Alexandro Becker <caarlos0@users.noreply.github.com>

* fix: rebase on main

---------

Signed-off-by: Carlos Alexandro Becker <caarlos0@users.noreply.github.com>
This commit is contained in:
Carlos Alexandro Becker 2024-12-17 14:17:43 -03:00 committed by GitHub
commit 0b89ff82d4
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -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
}