cmd: allow invoking without plugin

Signed-off-by: Tonis Tiigi <tonistiigi@gmail.com>
This commit is contained in:
Tonis Tiigi
2019-04-11 09:09:03 -07:00
parent 21754a42b1
commit 81d689e2e4
3 changed files with 31 additions and 7 deletions

View File

@@ -1,9 +1,13 @@
package main
import (
"fmt"
"os"
"github.com/docker/cli/cli-plugins/manager"
"github.com/docker/cli/cli-plugins/plugin"
"github.com/docker/cli/cli/command"
cliflags "github.com/docker/cli/cli/flags"
"github.com/spf13/cobra"
"github.com/tonistiigi/buildx/commands"
"github.com/tonistiigi/buildx/version"
@@ -13,8 +17,25 @@ import (
)
func main() {
if os.Getenv("DOCKER_CLI_PLUGIN_ORIGINAL_CLI_COMMAND") == "" {
if len(os.Args) < 2 || os.Args[1] != manager.MetadataSubcommandName {
dockerCli, err := command.NewDockerCli()
if err != nil {
fmt.Fprintln(os.Stderr, err)
os.Exit(1)
}
opts := cliflags.NewClientOptions()
dockerCli.Initialize(opts)
rootCmd := commands.NewRootCmd(os.Args[0], false, dockerCli)
if err := rootCmd.Execute(); err != nil {
os.Exit(1)
}
os.Exit(0)
}
}
plugin.Run(func(dockerCli command.Cli) *cobra.Command {
return commands.NewRootCmd(dockerCli)
return commands.NewRootCmd("buildx", true, dockerCli)
},
manager.Metadata{
SchemaVersion: "0.1.0",