2019-03-24 12:30:29 +08:00
|
|
|
package commands
|
|
|
|
|
|
|
|
import (
|
2020-04-28 05:37:17 +08:00
|
|
|
"os"
|
|
|
|
|
2019-04-25 10:29:56 +08:00
|
|
|
imagetoolscmd "github.com/docker/buildx/commands/imagetools"
|
2019-03-26 10:01:31 +08:00
|
|
|
"github.com/docker/cli/cli-plugins/plugin"
|
2019-03-24 12:30:29 +08:00
|
|
|
"github.com/docker/cli/cli/command"
|
|
|
|
"github.com/spf13/cobra"
|
2020-04-28 05:37:17 +08:00
|
|
|
"github.com/spf13/pflag"
|
2019-03-24 12:30:29 +08:00
|
|
|
)
|
|
|
|
|
2019-04-12 00:09:03 +08:00
|
|
|
func NewRootCmd(name string, isPlugin bool, dockerCli command.Cli) *cobra.Command {
|
2019-03-24 12:30:29 +08:00
|
|
|
cmd := &cobra.Command{
|
|
|
|
Short: "Build with BuildKit",
|
2019-04-12 00:09:03 +08:00
|
|
|
Use: name,
|
|
|
|
}
|
|
|
|
if isPlugin {
|
|
|
|
cmd.PersistentPreRunE = func(cmd *cobra.Command, args []string) error {
|
2019-03-26 10:01:31 +08:00
|
|
|
return plugin.PersistentPreRunE(cmd, args)
|
2019-04-12 00:09:03 +08:00
|
|
|
}
|
2019-03-24 12:30:29 +08:00
|
|
|
}
|
2019-04-12 00:09:03 +08:00
|
|
|
|
2019-03-24 12:30:29 +08:00
|
|
|
addCommands(cmd, dockerCli)
|
|
|
|
return cmd
|
|
|
|
}
|
|
|
|
|
2020-04-28 05:37:17 +08:00
|
|
|
type rootOptions struct {
|
|
|
|
builder string
|
|
|
|
}
|
|
|
|
|
2019-03-24 12:30:29 +08:00
|
|
|
func addCommands(cmd *cobra.Command, dockerCli command.Cli) {
|
2020-04-28 05:37:17 +08:00
|
|
|
opts := &rootOptions{}
|
|
|
|
rootFlags(opts, cmd.PersistentFlags())
|
|
|
|
|
2019-03-24 12:30:29 +08:00
|
|
|
cmd.AddCommand(
|
2020-04-28 05:37:17 +08:00
|
|
|
buildCmd(dockerCli, opts),
|
|
|
|
bakeCmd(dockerCli, opts),
|
2019-04-12 08:24:24 +08:00
|
|
|
createCmd(dockerCli),
|
2020-04-28 05:37:17 +08:00
|
|
|
rmCmd(dockerCli, opts),
|
2019-04-12 08:24:24 +08:00
|
|
|
lsCmd(dockerCli),
|
2020-04-28 05:37:17 +08:00
|
|
|
useCmd(dockerCli, opts),
|
|
|
|
inspectCmd(dockerCli, opts),
|
|
|
|
stopCmd(dockerCli, opts),
|
2019-04-19 11:02:57 +08:00
|
|
|
installCmd(dockerCli),
|
|
|
|
uninstallCmd(dockerCli),
|
2019-04-25 07:16:30 +08:00
|
|
|
versionCmd(dockerCli),
|
2020-04-28 05:37:17 +08:00
|
|
|
pruneCmd(dockerCli, opts),
|
|
|
|
duCmd(dockerCli, opts),
|
2019-04-17 03:01:10 +08:00
|
|
|
imagetoolscmd.RootCmd(dockerCli),
|
2019-03-24 12:30:29 +08:00
|
|
|
)
|
|
|
|
}
|
2020-04-28 05:37:17 +08:00
|
|
|
|
|
|
|
func rootFlags(options *rootOptions, flags *pflag.FlagSet) {
|
|
|
|
flags.StringVar(&options.builder, "builder", os.Getenv("BUILDX_BUILDER"), "Override the configured builder instance")
|
|
|
|
}
|