-
Notifications
You must be signed in to change notification settings - Fork 0
/
action.go
36 lines (27 loc) · 852 Bytes
/
action.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
package ctl
import (
"github.com/unqnown/esctl/internal/app"
"github.com/unqnown/esctl/pkg/check"
"github.com/unqnown/esctl/pkg/client"
"github.com/urfave/cli"
)
type ActionFunc = func(*cli.Context)
type CommandFunc func(conf app.Config, cli *client.Client, ctx *cli.Context) error
func NewAction(cmd CommandFunc) ActionFunc {
return func(c *cli.Context) {
conf, err := app.Open(c.GlobalString("config"))
check.Fatalf(err, "open config: %v", err)
err = conf.SetContext(c.GlobalString("context"))
check.Fatal(err)
cst, usr, err := conf.Conn()
check.Fatal(err)
conn, err := client.New(cst, usr)
check.Fatalf(err, "connect: %v", err)
check.Fatal(cmd(conf, conn, c))
}
}
func Call(cmd CommandFunc, conf app.Config, conn *client.Client) ActionFunc {
return func(ctx *cli.Context) {
check.Fatal(cmd(conf, conn, ctx))
}
}