gum/confirm/command.go
Ayman Bagabas 7d51fd8b73
feat: add log command (#449)
* feat: add log command

* fix: lint

* refactor: remove switch

* fix: use one level style embed

* fix(log): lint

* Update log/command.go

Co-authored-by: Ayman Bagabas <ayman.bagabas@gmail.com>

---------

Co-authored-by: Maas Lalani <maas@lalani.dev>
2023-11-08 10:43:50 -05:00

51 lines
1.1 KiB
Go

package confirm
import (
"fmt"
"os"
"github.com/charmbracelet/gum/internal/exit"
"github.com/alecthomas/kong"
tea "github.com/charmbracelet/bubbletea"
"github.com/charmbracelet/gum/style"
)
// 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 {
m, err := tea.NewProgram(model{
affirmative: o.Affirmative,
negative: o.Negative,
confirmation: o.Default,
defaultSelection: o.Default,
timeout: o.Timeout,
hasTimeout: o.Timeout > 0,
prompt: o.Prompt,
selectedStyle: o.SelectedStyle.ToLipgloss(),
unselectedStyle: o.UnselectedStyle.ToLipgloss(),
promptStyle: o.PromptStyle.ToLipgloss(),
}, tea.WithOutput(os.Stderr)).Run()
if err != nil {
return fmt.Errorf("unable to run confirm: %w", err)
}
if m.(model).aborted {
os.Exit(exit.StatusAborted)
} else if m.(model).confirmation {
os.Exit(0)
}
os.Exit(1)
return nil
}
// BeforeReset hook. Used to unclutter style flags.
func (o Options) BeforeReset(ctx *kong.Context) error {
style.HideFlags(ctx)
return nil
}