1
0
mirror of https://github.com/docker/cli.git synced 2025-08-30 12:01:10 +03:00

Add basic framework for writing a CLI plugin

That is, the helper to be used from the plugin's `main`.

Also add a `helloworld` plugin example and build integration.

Signed-off-by: Ian Campbell <ijc@docker.com>
This commit is contained in:
Ian Campbell
2018-12-10 15:30:19 +00:00
parent 8cf946d1bc
commit e96240427f
10 changed files with 248 additions and 0 deletions

View File

@@ -0,0 +1,38 @@
package main
import (
"fmt"
"github.com/docker/cli/cli-plugins/manager"
"github.com/docker/cli/cli-plugins/plugin"
"github.com/docker/cli/cli/command"
"github.com/spf13/cobra"
)
func main() {
plugin.Run(func(dockerCli command.Cli) *cobra.Command {
goodbye := &cobra.Command{
Use: "goodbye",
Short: "Say Goodbye instead of Hello",
Run: func(cmd *cobra.Command, _ []string) {
fmt.Fprintln(dockerCli.Out(), "Goodbye World!")
},
}
cmd := &cobra.Command{
Use: "helloworld",
Short: "A basic Hello World plugin for tests",
Run: func(cmd *cobra.Command, args []string) {
fmt.Fprintln(dockerCli.Out(), "Hello World!")
},
}
cmd.AddCommand(goodbye)
return cmd
},
manager.Metadata{
SchemaVersion: "0.1.0",
Vendor: "Docker Inc.",
Version: "0.1.0",
})
}