MCPcopy Index your code
hub / github.com/deepflowio/deepflow / RegisterPluginCommand

Function RegisterPluginCommand

cli/ctl/plugin.go:35–91  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

33)
34
35func RegisterPluginCommand() *cobra.Command {
36 plugin := &cobra.Command{
37 Use: "plugin",
38 Short: "plugin operation commands",
39 Run: func(cmd *cobra.Command, args []string) {
40 fmt.Printf("please run with 'list | create | delete.'\n")
41 },
42 }
43
44 var createType, image, name, user string
45 create := &cobra.Command{
46 Use: "create",
47 Short: "create plugin",
48 Example: "deepflow-ctl plugin create --type wasm --image /home/tom/hello.wasm --name hello\n" +
49 "deepflow-ctl plugin create --type so --image /home/tom/hello.so --name hello\n" +
50 "deepflow-ctl plugin create --type lua --image /home/tom/hello.lua --name hello --user server",
51 Run: func(cmd *cobra.Command, args []string) {
52 if _, err := os.Stat(image); errors.Is(err, os.ErrNotExist) {
53 fmt.Printf("file(%s) not found\n", image)
54 return
55 }
56 if err := createPlugin(cmd, createType, image, name, user); err != nil {
57 fmt.Println(err)
58 }
59 },
60 }
61 create.Flags().StringVarP(&createType, "type", "", "", "type of image file, currently supports: wasm | so | lua")
62 create.Flags().StringVarP(&image, "image", "", "", "plugin image to upload")
63 create.Flags().StringVarP(&name, "name", "", "", "specify a unique alias for image")
64 create.Flags().StringVarP(&user, "user", "", "agent", "specify the component for which plugin is used. the optional value is agent/server")
65 create.MarkFlagsRequiredTogether("type", "image", "name")
66
67 list := &cobra.Command{
68 Use: "list",
69 Short: "list plugin",
70 Example: "deepflow-ctl plugin list",
71 Run: func(cmd *cobra.Command, args []string) {
72 listPlugin(cmd)
73 },
74 }
75
76 delete := &cobra.Command{
77 Use: "delete",
78 Short: "delete plugin",
79 Example: "deepflow-ctl plugin delete <name>\n(get name from command `deepflow-ctl plugin list`)",
80 Run: func(cmd *cobra.Command, args []string) {
81 if err := deletePlugin(cmd, args); err != nil {
82 fmt.Println(err)
83 }
84 },
85 }
86
87 plugin.AddCommand(create)
88 plugin.AddCommand(list)
89 plugin.AddCommand(delete)
90 return plugin
91}
92

Callers 1

ExecuteFunction · 0.85

Calls 3

listPluginFunction · 0.85
createPluginFunction · 0.70
deletePluginFunction · 0.70

Tested by

no test coverage detected