MCPcopy Index your code
hub / github.com/docker/cli / main

Function main

cli-plugins/examples/helloworld/main.go:15–106  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

13)
14
15func main() {
16 plugin.Run(func(dockerCLI command.Cli) *cobra.Command {
17 goodbye := &cobra.Command{
18 Use: "goodbye",
19 Short: "Say Goodbye instead of Hello",
20 Run: func(cmd *cobra.Command, _ []string) {
21 _, _ = fmt.Fprintln(dockerCLI.Out(), "Goodbye World!")
22 },
23 }
24 apiversion := &cobra.Command{
25 Use: "apiversion",
26 Short: "Print the API version of the server",
27 RunE: func(_ *cobra.Command, _ []string) error {
28 apiClient := dockerCLI.Client()
29 ping, err := apiClient.Ping(context.Background(), client.PingOptions{})
30 if err != nil {
31 return err
32 }
33 _, _ = fmt.Println(ping.APIVersion)
34 return nil
35 },
36 }
37
38 exitStatus2 := &cobra.Command{
39 Use: "exitstatus2",
40 Short: "Exit with status 2",
41 RunE: func(_ *cobra.Command, _ []string) error {
42 _, _ = fmt.Fprintln(dockerCLI.Err(), "Exiting with error status 2")
43 os.Exit(2)
44 return nil
45 },
46 }
47
48 var (
49 who, optContext string
50 preRun, debug bool
51 )
52 cmd := &cobra.Command{
53 Use: "helloworld",
54 Short: "A basic Hello World plugin for tests",
55 PersistentPreRunE: func(cmd *cobra.Command, args []string) error {
56 if err := plugin.PersistentPreRunE(cmd, args); err != nil {
57 return err
58 }
59 if preRun {
60 _, _ = fmt.Fprintln(dockerCLI.Err(), "Plugin PersistentPreRunE called")
61 }
62 return nil
63 },
64 RunE: func(cmd *cobra.Command, args []string) error {
65 if debug {
66 _, _ = fmt.Fprintln(dockerCLI.Err(), "Plugin debug mode enabled")
67 }
68
69 switch optContext {
70 case "Christmas":
71 _, _ = fmt.Fprintln(dockerCLI.Out(), "Merry Christmas!")
72 return nil

Callers

nothing calls this directly

Calls 9

PrintlnMethod · 0.80
PluginConfigMethod · 0.80
SetPluginConfigMethod · 0.80
OutMethod · 0.65
ClientMethod · 0.65
ErrMethod · 0.65
ConfigFileMethod · 0.65
SaveMethod · 0.65
PingMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…