-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.go
45 lines (35 loc) · 788 Bytes
/
app.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 app
import (
"github.com/eddieowens/axon"
"github.com/eddieowens/kaa"
"github.com/fatih/color"
"github.com/spf13/cobra"
)
const Key = "App"
var Version string
type App interface {
kaa.Cmd
Start() error
}
type app struct {
Commands []axon.Instance `inject:"Commands"`
}
func (a *app) Command() *cobra.Command {
cmd := &cobra.Command{
Short: "A tool for interacting with Ranvier",
Use: "ranvier [flags] [command]",
Args: cobra.MinimumNArgs(1),
Version: Version,
}
for _, a := range a.Commands {
cmd.AddCommand(a.GetStructPtr().(kaa.Cmd).Command())
}
return cmd
}
func (a *app) Start() error {
kaa.OnError = func(ctx kaa.Context) int {
color.Red("An error occurred:\n%s", ctx.Error().Error())
return 1
}
return a.Command().Execute()
}