Skip to content

Commit

Permalink
feat: yes|gum confirm (#772)
Browse files Browse the repository at this point in the history
* feat: yes|gum confirm

Signed-off-by: Carlos Alexandro Becker <[email protected]>

* fix: rebase on main

---------

Signed-off-by: Carlos Alexandro Becker <[email protected]>
  • Loading branch information
caarlos0 authored Dec 17, 2024
1 parent 4cedf9f commit 0b89ff8
Showing 1 changed file with 14 additions and 1 deletion.
15 changes: 14 additions & 1 deletion confirm/command.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()

Expand Down Expand Up @@ -52,5 +65,5 @@ func (o Options) Run() error {
return nil
}

return errors.New("not confirmed")
return errNotConfirmed
}

0 comments on commit 0b89ff8

Please sign in to comment.