@@ -16,13 +16,14 @@ import (
1616 "github.com/docker/cli/cli-plugins/plugin"
1717 "github.com/docker/cli/cli/command"
1818 "github.com/docker/cli/cli/debug"
19+ cliflags "github.com/docker/cli/cli/flags"
1920 "github.com/moby/buildkit/util/appcontext"
2021 "github.com/sirupsen/logrus"
2122 "github.com/spf13/cobra"
2223 "github.com/spf13/pflag"
2324)
2425
25- func NewRootCmd (name string , isPlugin bool , dockerCli command.Cli ) * cobra.Command {
26+ func NewRootCmd (name string , isPlugin bool , dockerCli * command.DockerCli ) * cobra.Command {
2627 var opt rootOptions
2728 cmd := & cobra.Command {
2829 Short : "Docker Buildx" ,
@@ -40,7 +41,17 @@ func NewRootCmd(name string, isPlugin bool, dockerCli command.Cli) *cobra.Comman
4041 }
4142 cmd .SetContext (appcontext .Context ())
4243 if ! isPlugin {
43- return nil
44+ // InstallFlags and SetDefaultOptions are necessary to match
45+ // the plugin mode behavior to handle env vars such as
46+ // DOCKER_TLS, DOCKER_TLS_VERIFY, ... and we also need to use a
47+ // new flagset to avoid conflict with the global debug flag
48+ // that we already handle in the root command otherwise it
49+ // would panic.
50+ nflags := pflag .NewFlagSet (cmd .DisplayName (), pflag .ContinueOnError )
51+ options := cliflags .NewClientOptions ()
52+ options .InstallFlags (nflags )
53+ options .SetDefaultOptions (nflags )
54+ return dockerCli .Initialize (options )
4455 }
4556 return plugin .PersistentPreRunE (cmd , args )
4657 },
0 commit comments