github.com/torresashjian/cli@v0.10.1-0.20210916231452-89080fe7069c/docs/plugins.md (about) 1 <!-- 2 title: plugins 3 weight: 5020 4 pre: "<i class=\"fa fa-terminal\" aria-hidden=\"true\"></i> " 5 --> 6 7 # Plugins 8 9 The Flogo CLI has support for plugins. These plugins can be used to extend the Flogo CLI command. 10 11 ## Creating a CLI plugin 12 13 First lets setup the go project: 14 15 ```bash 16 # Create a directory for your plugin project 17 $ mkdir myplugin 18 19 # Go to the directory 20 $ cd myplugin 21 22 # Initialize the Go module information 23 $ go mod init github.com/myuser/myplugin 24 25 # Edit/Create the plugin code 26 $ vi myplugin.go 27 ``` 28 29 Next lets create the code for our simple plugin: 30 31 ```go 32 package myplugin 33 34 import ( 35 "fmt" 36 "github.com/torresashjian/cli/common" // Flogo CLI support code 37 "github.com/spf13/cobra" 38 ) 39 40 func init() { 41 common.RegisterPlugin(myCmd) 42 } 43 44 var myCmd = &cobra.Command{ 45 Use: "mycmd", 46 Short: "says hello world", 47 Long: "This plugin command says hello world", 48 Run: func(cmd *cobra.Command, args []string) { 49 fmt.Println("Hello World") 50 }, 51 } 52 ``` 53 Once you save the code, we need to fix up the Go Module dependencies. 54 55 ```bash 56 $ go mod tidy 57 ``` 58 59 Now you are ready to test out your plugin. First you must host your plugin in your git repository. Then you are ready to install and run your plugin 60 61 ``` 62 # Install your plugin 63 $ flogo plugin install github.com/myuser/myplugin 64 65 # Run your new plugin command 66 $ flogo mycmd 67 ```