-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathusage.go
37 lines (32 loc) · 955 Bytes
/
usage.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
package boa
import (
"fmt"
"log"
tea "github.com/charmbracelet/bubbletea"
"github.com/spf13/cobra"
)
// Inital options
var defaultOpts = defaultOptions()
// HelpFunc puts out the help for the command. Used when a user calls help [command].
// Set by calling Cobra's SetHelpFunc
func HelpFunc(cmd *cobra.Command, s []string) {
model := newCmdModel(defaultOpts, cmd)
if err := tea.NewProgram(model, defaultOpts.altScreen, defaultOpts.mouseCellMotion).Start(); err != nil {
log.Fatal(err)
}
if model.print {
fmt.Println(model.cmdChain)
}
}
// UsageFunc puts out the usage for the command. Used when a user provides invalid input.
// Set by calling Cobra's SetUsageFunc
func UsageFunc(cmd *cobra.Command) error {
model := newCmdModel(defaultOpts, cmd)
if err := tea.NewProgram(model, defaultOpts.altScreen, defaultOpts.mouseCellMotion).Start(); err != nil {
return err
}
if model.print {
fmt.Println(model.cmdChain)
}
return nil
}