Skip to content

Commit 9752fa5

Browse files
thaJeztahndeloof
authored andcommitted
pluginMain: remove uses of DockerCLI.Apply
The Apply method was added when CLI options for constructing the CLI were rewritten into functional options in [cli@7f207f3]. There was no mention in the pull request of this method specifically, and we want to remove or reduce functions that mutate the CLI configuration after initialization if possible (and likely remove the `Apply` method). This patch removes the use of the `Apply` function as an intermediate step; improvements will be made in the CLI itself for a more solid implementation. [cli@7f207f3]: docker/cli@7f207f3 Signed-off-by: Sebastiaan van Stijn <[email protected]>
1 parent 4761fd8 commit 9752fa5

File tree

1 file changed

+9
-18
lines changed

1 file changed

+9
-18
lines changed

cmd/main.go

Lines changed: 9 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -47,8 +47,15 @@ func pluginMain() {
4747
if err := plugin.PersistentPreRunE(cmd, args); err != nil {
4848
return err
4949
}
50-
// compose-specific initialization
51-
dockerCliPostInitialize(dockerCli)
50+
// compose-specific initialization. This must be called AFTER
51+
// plugin.PersistentPreRunE.
52+
//
53+
// FIXME(milas): remove once https://github.com/docker/cli/pull/4574 is merged; for now,
54+
// set it in a rather roundabout way by grabbing the underlying
55+
// concrete client and manually invoking an option on it
56+
if mobyClient, ok := dockerCli.Client().(*client.Client); ok {
57+
_ = client.WithUserAgent("compose/" + internal.Version)(mobyClient)
58+
}
5259

5360
if err := cmdtrace.Setup(cmd, dockerCli, os.Args[1:]); err != nil {
5461
logrus.Debugf("failed to enable tracing: %v", err)
@@ -75,22 +82,6 @@ func pluginMain() {
7582
})
7683
}
7784

78-
// dockerCliPostInitialize performs Compose-specific configuration for the
79-
// command.Cli instance provided by the plugin.Run() initialization.
80-
//
81-
// NOTE: This must be called AFTER plugin.PersistentPreRunE.
82-
func dockerCliPostInitialize(dockerCli command.Cli) {
83-
// HACK(milas): remove once docker/cli#4574 is merged; for now,
84-
// set it in a rather roundabout way by grabbing the underlying
85-
// concrete client and manually invoking an option on it
86-
_ = dockerCli.Apply(func(cli *command.DockerCli) error {
87-
if mobyClient, ok := cli.Client().(*client.Client); ok {
88-
_ = client.WithUserAgent("compose/" + internal.Version)(mobyClient)
89-
}
90-
return nil
91-
})
92-
}
93-
9485
func main() {
9586
if plugin.RunningStandalone() {
9687
os.Args = append([]string{"docker"}, compatibility.Convert(os.Args[1:])...)

0 commit comments

Comments
 (0)