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

Function RunPlugin

cli-plugins/plugin/plugin.go:33–81  ·  view source on GitHub ↗

RunPlugin executes the specified plugin command

(dockerCli *command.DockerCli, plugin *cobra.Command, meta metadata.Metadata)

Source from the content-addressed store, hash-verified

31
32// RunPlugin executes the specified plugin command
33func RunPlugin(dockerCli *command.DockerCli, plugin *cobra.Command, meta metadata.Metadata) error {
34 tcmd := newPluginCommand(dockerCli, plugin, meta)
35
36 var persistentPreRunOnce sync.Once
37 PersistentPreRunE = func(cmd *cobra.Command, _ []string) error {
38 var retErr error
39 persistentPreRunOnce.Do(func() {
40 ctx, cancel := context.WithCancel(cmd.Context())
41 cmd.SetContext(ctx)
42 // Set up the context to cancel based on signalling via CLI socket.
43 socket.ConnectAndWait(cancel)
44
45 var opts []command.CLIOption
46 if os.Getenv("DOCKER_CLI_PLUGIN_USE_DIAL_STDIO") != "" {
47 opts = append(opts, withPluginClientConn(plugin.Name()))
48 }
49 opts = append(opts, command.WithEnableGlobalMeterProvider(), command.WithEnableGlobalTracerProvider())
50 retErr = tcmd.Initialize(opts...)
51 ogRunE := cmd.RunE
52 if ogRunE == nil {
53 ogRun := cmd.Run
54 // necessary because error will always be nil here
55 // see: https://github.com/golangci/golangci-lint/issues/1379
56 //nolint:unparam
57 ogRunE = func(cmd *cobra.Command, args []string) error {
58 ogRun(cmd, args)
59 return nil
60 }
61 cmd.Run = nil
62 }
63 cmd.RunE = func(cmd *cobra.Command, args []string) error {
64 stopInstrumentation := dockerCli.StartInstrumentation(cmd)
65 err := ogRunE(cmd, args)
66 stopInstrumentation(err)
67 return err
68 }
69 })
70 return retErr
71 }
72
73 cmd, args, err := tcmd.HandleGlobalFlags()
74 if err != nil {
75 return err
76 }
77 // We've parsed global args already, so reset args to those
78 // which remain.
79 cmd.SetArgs(args)
80 return cmd.Execute()
81}
82
83// Run is the top-level entry point to the CLI plugin framework. It should
84// be called from the plugin's "main()" function. It initializes a new

Callers 1

RunFunction · 0.85

Calls 7

withPluginClientConnFunction · 0.85
StartInstrumentationMethod · 0.80
HandleGlobalFlagsMethod · 0.80
SetArgsMethod · 0.80
newPluginCommandFunction · 0.70
NameMethod · 0.45
InitializeMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…