mirror of
https://gitea.com/Lydanne/buildx.git
synced 2025-05-18 09:17:49 +08:00
Merge pull request #18 from tonistiigi/no-plugin
cmd: allow invoking without plugin
This commit is contained in:
commit
4586e0ed18
@ -1,9 +1,13 @@
|
|||||||
package main
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"fmt"
|
||||||
|
"os"
|
||||||
|
|
||||||
"github.com/docker/cli/cli-plugins/manager"
|
"github.com/docker/cli/cli-plugins/manager"
|
||||||
"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"
|
||||||
|
cliflags "github.com/docker/cli/cli/flags"
|
||||||
"github.com/spf13/cobra"
|
"github.com/spf13/cobra"
|
||||||
"github.com/tonistiigi/buildx/commands"
|
"github.com/tonistiigi/buildx/commands"
|
||||||
"github.com/tonistiigi/buildx/version"
|
"github.com/tonistiigi/buildx/version"
|
||||||
@ -13,8 +17,25 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
func main() {
|
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 {
|
plugin.Run(func(dockerCli command.Cli) *cobra.Command {
|
||||||
return commands.NewRootCmd(dockerCli)
|
return commands.NewRootCmd("buildx", true, dockerCli)
|
||||||
},
|
},
|
||||||
manager.Metadata{
|
manager.Metadata{
|
||||||
SchemaVersion: "0.1.0",
|
SchemaVersion: "0.1.0",
|
||||||
|
@ -6,14 +6,17 @@ import (
|
|||||||
"github.com/spf13/cobra"
|
"github.com/spf13/cobra"
|
||||||
)
|
)
|
||||||
|
|
||||||
func NewRootCmd(dockerCli command.Cli) *cobra.Command {
|
func NewRootCmd(name string, isPlugin bool, dockerCli command.Cli) *cobra.Command {
|
||||||
cmd := &cobra.Command{
|
cmd := &cobra.Command{
|
||||||
Short: "Build with BuildKit",
|
Short: "Build with BuildKit",
|
||||||
Use: "buildx",
|
Use: name,
|
||||||
PersistentPreRunE: func(cmd *cobra.Command, args []string) error {
|
|
||||||
return plugin.PersistentPreRunE(cmd, args)
|
|
||||||
},
|
|
||||||
}
|
}
|
||||||
|
if isPlugin {
|
||||||
|
cmd.PersistentPreRunE = func(cmd *cobra.Command, args []string) error {
|
||||||
|
return plugin.PersistentPreRunE(cmd, args)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
addCommands(cmd, dockerCli)
|
addCommands(cmd, dockerCli)
|
||||||
return cmd
|
return cmd
|
||||||
}
|
}
|
||||||
|
2
vendor/modules.txt
vendored
2
vendor/modules.txt
vendored
@ -101,6 +101,7 @@ github.com/docker/cli/cli/compose/types
|
|||||||
github.com/docker/cli/cli-plugins/manager
|
github.com/docker/cli/cli-plugins/manager
|
||||||
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/cli/cli/flags
|
||||||
github.com/docker/cli/cli
|
github.com/docker/cli/cli
|
||||||
github.com/docker/cli/cli/compose/interpolation
|
github.com/docker/cli/cli/compose/interpolation
|
||||||
github.com/docker/cli/cli/compose/schema
|
github.com/docker/cli/cli/compose/schema
|
||||||
@ -115,7 +116,6 @@ github.com/docker/cli/cli/context/docker
|
|||||||
github.com/docker/cli/cli/context/kubernetes
|
github.com/docker/cli/cli/context/kubernetes
|
||||||
github.com/docker/cli/cli/context/store
|
github.com/docker/cli/cli/context/store
|
||||||
github.com/docker/cli/cli/debug
|
github.com/docker/cli/cli/debug
|
||||||
github.com/docker/cli/cli/flags
|
|
||||||
github.com/docker/cli/cli/manifest/store
|
github.com/docker/cli/cli/manifest/store
|
||||||
github.com/docker/cli/cli/registry/client
|
github.com/docker/cli/cli/registry/client
|
||||||
github.com/docker/cli/cli/streams
|
github.com/docker/cli/cli/streams
|
||||||
|
Loading…
x
Reference in New Issue
Block a user