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:
38
cli-plugins/examples/helloworld/main.go
Normal file
38
cli-plugins/examples/helloworld/main.go
Normal 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",
|
||||
})
|
||||
}
|
Reference in New Issue
Block a user