@@ -24,6 +24,7 @@ import (
24
24
"github.com/docker/cli/cli-plugins/plugin"
25
25
"github.com/docker/cli/cli/command"
26
26
"github.com/docker/compose/v2/cmd/cmdtrace"
27
+ "github.com/docker/docker/client"
27
28
"github.com/spf13/cobra"
28
29
29
30
"github.com/docker/compose/v2/cmd/compatibility"
@@ -42,6 +43,9 @@ func pluginMain() {
42
43
if err := plugin .PersistentPreRunE (cmd , args ); err != nil {
43
44
return err
44
45
}
46
+ // compose-specific initialization
47
+ dockerCliPostInitialize (dockerCli )
48
+
45
49
// TODO(milas): add an env var to enable logging from the
46
50
// OTel components for debugging purposes
47
51
_ = cmdtrace .Setup (cmd , dockerCli , os .Args [1 :])
@@ -67,6 +71,22 @@ func pluginMain() {
67
71
})
68
72
}
69
73
74
+ // dockerCliPostInitialize performs Compose-specific configuration for the
75
+ // command.Cli instance provided by the plugin.Run() initialization.
76
+ //
77
+ // NOTE: This must be called AFTER plugin.PersistentPreRunE.
78
+ func dockerCliPostInitialize (dockerCli command.Cli ) {
79
+ // HACK(milas): remove once docker/cli#4574 is merged; for now,
80
+ // set it in a rather roundabout way by grabbing the underlying
81
+ // concrete client and manually invoking an option on it
82
+ _ = dockerCli .Apply (func (cli * command.DockerCli ) error {
83
+ if mobyClient , ok := cli .Client ().(* client.Client ); ok {
84
+ _ = client .WithUserAgent ("compose/" + internal .Version )(mobyClient )
85
+ }
86
+ return nil
87
+ })
88
+ }
89
+
70
90
func main () {
71
91
if plugin .RunningStandalone () {
72
92
os .Args = append ([]string {"docker" }, compatibility .Convert (os .Args [1 :])... )
0 commit comments