@@ -16,13 +16,14 @@ import (
16
16
"github.com/docker/cli/cli-plugins/plugin"
17
17
"github.com/docker/cli/cli/command"
18
18
"github.com/docker/cli/cli/debug"
19
+ cliflags "github.com/docker/cli/cli/flags"
19
20
"github.com/moby/buildkit/util/appcontext"
20
21
"github.com/sirupsen/logrus"
21
22
"github.com/spf13/cobra"
22
23
"github.com/spf13/pflag"
23
24
)
24
25
25
- func NewRootCmd (name string , isPlugin bool , dockerCli command.Cli ) * cobra.Command {
26
+ func NewRootCmd (name string , isPlugin bool , dockerCli * command.DockerCli ) * cobra.Command {
26
27
var opt rootOptions
27
28
cmd := & cobra.Command {
28
29
Short : "Docker Buildx" ,
@@ -40,7 +41,17 @@ func NewRootCmd(name string, isPlugin bool, dockerCli command.Cli) *cobra.Comman
40
41
}
41
42
cmd .SetContext (appcontext .Context ())
42
43
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 )
44
55
}
45
56
return plugin .PersistentPreRunE (cmd , args )
46
57
},
0 commit comments