refactor(kong): Implement Run(...) error interface

Instead of needing to run the commands manually in main.go, we can implement the `Run(...) error` method to satisfy the command interface so that `kong` can Run our commands for us.
This commit is contained in:
Maas Lalani 2022-07-12 22:12:02 -04:00
commit 7190822247
No known key found for this signature in database
GPG key ID: 5A6ED5CBF1A0A000
12 changed files with 61 additions and 74 deletions

View file

@ -6,15 +6,23 @@ import (
"github.com/charmbracelet/bubbles/textinput"
tea "github.com/charmbracelet/bubbletea"
"github.com/charmbracelet/gum/internal/stdin"
)
// Run provides a shell script interface for the text input bubble.
// https://github.com/charmbracelet/bubbles/textinput
func (o Options) Run() {
i := textinput.New()
i.Focus()
func (o Options) Run() error {
in, _ := stdin.Read()
i.SetValue(o.Value)
i := textinput.New()
if in != "" && o.Value == "" {
i.SetValue(in)
} else {
i.SetValue(o.Value)
}
i.Focus()
i.Prompt = o.Prompt
i.Placeholder = o.Placeholder
i.Width = o.Width
@ -22,6 +30,7 @@ func (o Options) Run() {
i.CursorStyle = o.CursorStyle.ToLipgloss()
p := tea.NewProgram(model{i}, tea.WithOutput(os.Stderr))
m, _ := p.StartReturningModel()
m, err := p.StartReturningModel()
fmt.Println(m.(model).textinput.Value())
return err
}