-
Notifications
You must be signed in to change notification settings - Fork 7
/
boa.go
45 lines (39 loc) · 1 KB
/
boa.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
package boa
import (
"fmt"
"log"
tea "github.com/charmbracelet/bubbletea"
"github.com/spf13/cobra"
)
type Boa struct {
options *options
}
// Create a new instance of Boa with custom Options
func New(options ...Options) *Boa {
opts := defaultOptions()
for _, opt := range options {
opt.apply(opts)
}
return &Boa{
options: opts,
}
}
func (b *Boa) HelpFunc(cmd *cobra.Command, s []string) {
model := newCmdModel(b.options, cmd)
if err := tea.NewProgram(model, b.options.altScreen, b.options.mouseCellMotion).Start(); err != nil {
log.Fatal(err)
}
if model.print {
fmt.Println(b.options.styles.Border.Render(b.options.styles.CmdPrint.Render(model.cmdChain)))
}
}
func (b *Boa) UsageFunc(cmd *cobra.Command) error {
model := newCmdModel(b.options, cmd)
if err := tea.NewProgram(model, b.options.altScreen, b.options.mouseCellMotion).Start(); err != nil {
return err
}
if model.print {
fmt.Println(b.options.styles.Border.Render(b.options.styles.CmdPrint.Render(model.cmdChain)))
}
return nil
}