Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
ignite
GitHub Repository: ignite/cli
Path: blob/main/integration/plugin/testdata/example-plugin/main.go
1007 views
1
package main
2
3
import (
4
"context"
5
"fmt"
6
7
hplugin "github.com/hashicorp/go-plugin"
8
9
"github.com/ignite/cli/v29/ignite/services/plugin"
10
)
11
12
type p struct{}
13
14
func (p) Manifest(context.Context) (*plugin.Manifest, error) {
15
return &plugin.Manifest{
16
Name: "example-plugin",
17
Commands: []*plugin.Command{
18
{
19
Use: "example-plugin",
20
Short: "Explain what the command is doing...",
21
Long: "Long description goes here...",
22
Flags: plugin.Flags{
23
{Name: "my-flag", Type: plugin.FlagTypeString, Usage: "my flag description"},
24
},
25
PlaceCommandUnder: "ignite",
26
},
27
},
28
Hooks: []*plugin.Hook{},
29
}, nil
30
}
31
32
func (p) Execute(ctx context.Context, cmd *plugin.ExecutedCommand, api plugin.ClientAPI) error {
33
fmt.Printf("Hello I'm the example-plugin plugin\n")
34
fmt.Printf("My executed command: %q\n", cmd.Path)
35
fmt.Printf("My args: %v\n", cmd.Args)
36
37
flags, err := cmd.NewFlags()
38
if err != nil {
39
return err
40
}
41
42
myFlag, _ := flags.GetString("my-flag")
43
fmt.Printf("My flags: my-flag=%q\n", myFlag)
44
fmt.Printf("My config parameters: %v\n", cmd.With)
45
46
fmt.Println(api.GetChainInfo(ctx))
47
fmt.Println(api.GetIgniteInfo(ctx))
48
49
return nil
50
}
51
52
func (p) ExecuteHookPre(_ context.Context, h *plugin.ExecutedHook, _ plugin.ClientAPI) error {
53
fmt.Printf("Executing hook pre %q\n", h.Hook.GetName())
54
return nil
55
}
56
57
func (p) ExecuteHookPost(_ context.Context, h *plugin.ExecutedHook, _ plugin.ClientAPI) error {
58
fmt.Printf("Executing hook post %q\n", h.Hook.GetName())
59
return nil
60
}
61
62
func (p) ExecuteHookCleanUp(_ context.Context, h *plugin.ExecutedHook, _ plugin.ClientAPI) error {
63
fmt.Printf("Executing hook cleanup %q\n", h.Hook.GetName())
64
return nil
65
}
66
67
func main() {
68
hplugin.Serve(&hplugin.ServeConfig{
69
HandshakeConfig: plugin.HandshakeConfig(),
70
Plugins: map[string]hplugin.Plugin{
71
"example-plugin": plugin.NewGRPC(&p{}),
72
},
73
GRPCServer: hplugin.DefaultGRPCServer,
74
})
75
}
76
77