-
Notifications
You must be signed in to change notification settings - Fork 9
/
main.go
51 lines (41 loc) · 1.31 KB
/
main.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
46
47
48
49
50
51
package main
import (
"context"
"os"
hplugin "github.com/hashicorp/go-plugin"
"github.com/ignite/cli/ignite/services/plugin"
"github.com/ignite/cli-plugin-network/cmd"
)
type app struct{}
func (app) Manifest(context.Context) (*plugin.Manifest, error) {
m := &plugin.Manifest{Name: "network"}
m.ImportCobraCommand(cmd.NewNetwork(), "ignite")
return m, nil
}
func (app) Execute(_ context.Context, c *plugin.ExecutedCommand, _ plugin.ClientAPI) error {
// Instead of a switch on c.Use, we run the root command like if
// we were in a command line context. This implies to set os.Args
// correctly.
// Remove the first arg "ignite" from OsArgs because our network
// command root is "network" not "ignite".
os.Args = c.OsArgs[1:]
return cmd.NewNetwork().Execute()
}
func (app) ExecuteHookPre(context.Context, *plugin.ExecutedHook, plugin.ClientAPI) error {
return nil
}
func (app) ExecuteHookPost(context.Context, *plugin.ExecutedHook, plugin.ClientAPI) error {
return nil
}
func (app) ExecuteHookCleanUp(context.Context, *plugin.ExecutedHook, plugin.ClientAPI) error {
return nil
}
func main() {
hplugin.Serve(&hplugin.ServeConfig{
HandshakeConfig: plugin.HandshakeConfig(),
Plugins: map[string]hplugin.Plugin{
"cli-plugin-network": plugin.NewGRPC(&app{}),
},
GRPCServer: hplugin.DefaultGRPCServer,
})
}