From 0b89ff82d4cdcd59e5303df5fb5cc05fc83cc270 Mon Sep 17 00:00:00 2001 From: Carlos Alexandro Becker Date: Tue, 17 Dec 2024 14:17:43 -0300 Subject: [PATCH] feat: yes|gum confirm (#772) * feat: yes|gum confirm Signed-off-by: Carlos Alexandro Becker * fix: rebase on main --------- Signed-off-by: Carlos Alexandro Becker --- confirm/command.go | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/confirm/command.go b/confirm/command.go index ac151ad72..103fbad16 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 }