mirror of
https://github.com/docker/compose.git
synced 2025-11-11 17:30:04 +01:00
cmd: pluginMain: use WithUserAgent option
Rewrite the custom user agent to use the new options that were added in the cli: - plugin.Run now accepts custom CLI options to allow customizing the CLI's - cli/command now has a WithUserAgent option to customize the CLI's user- agent, allowing it to be overridden from the default. Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
This commit is contained in:
parent
38ba35e165
commit
032e0309ee
18
cmd/main.go
18
cmd/main.go
@ -24,7 +24,6 @@ import (
|
|||||||
"github.com/docker/cli/cli-plugins/plugin"
|
"github.com/docker/cli/cli-plugins/plugin"
|
||||||
"github.com/docker/cli/cli/command"
|
"github.com/docker/cli/cli/command"
|
||||||
"github.com/docker/compose/v2/cmd/cmdtrace"
|
"github.com/docker/compose/v2/cmd/cmdtrace"
|
||||||
"github.com/docker/docker/client"
|
|
||||||
"github.com/sirupsen/logrus"
|
"github.com/sirupsen/logrus"
|
||||||
"github.com/spf13/cobra"
|
"github.com/spf13/cobra"
|
||||||
|
|
||||||
@ -35,7 +34,8 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
func pluginMain() {
|
func pluginMain() {
|
||||||
plugin.Run(func(dockerCli command.Cli) *cobra.Command {
|
plugin.Run(
|
||||||
|
func(dockerCli command.Cli) *cobra.Command {
|
||||||
// TODO(milas): this cast is safe but we should not need to do this,
|
// TODO(milas): this cast is safe but we should not need to do this,
|
||||||
// we should expose the concrete service type so that we do not need
|
// we should expose the concrete service type so that we do not need
|
||||||
// to rely on the `api.Service` interface internally
|
// to rely on the `api.Service` interface internally
|
||||||
@ -47,16 +47,6 @@ func pluginMain() {
|
|||||||
if err := plugin.PersistentPreRunE(cmd, args); err != nil {
|
if err := plugin.PersistentPreRunE(cmd, args); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
// compose-specific initialization. This must be called AFTER
|
|
||||||
// plugin.PersistentPreRunE.
|
|
||||||
//
|
|
||||||
// FIXME(milas): remove once https://github.com/docker/cli/pull/4574 is merged; for now,
|
|
||||||
// set it in a rather roundabout way by grabbing the underlying
|
|
||||||
// concrete client and manually invoking an option on it
|
|
||||||
if mobyClient, ok := dockerCli.Client().(*client.Client); ok {
|
|
||||||
_ = client.WithUserAgent("compose/" + internal.Version)(mobyClient)
|
|
||||||
}
|
|
||||||
|
|
||||||
if err := cmdtrace.Setup(cmd, dockerCli, os.Args[1:]); err != nil {
|
if err := cmdtrace.Setup(cmd, dockerCli, os.Args[1:]); err != nil {
|
||||||
logrus.Debugf("failed to enable tracing: %v", err)
|
logrus.Debugf("failed to enable tracing: %v", err)
|
||||||
}
|
}
|
||||||
@ -79,7 +69,9 @@ func pluginMain() {
|
|||||||
SchemaVersion: "0.1.0",
|
SchemaVersion: "0.1.0",
|
||||||
Vendor: "Docker Inc.",
|
Vendor: "Docker Inc.",
|
||||||
Version: internal.Version,
|
Version: internal.Version,
|
||||||
})
|
},
|
||||||
|
command.WithUserAgent("compose/"+internal.Version),
|
||||||
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user