diff --git a/commands/build.go b/commands/build.go index e1b8f86b6ed6..f2b126c3e5e9 100644 --- a/commands/build.go +++ b/commands/build.go @@ -20,7 +20,6 @@ import ( "github.com/containerd/console" "github.com/docker/buildx/build" "github.com/docker/buildx/builder" - "github.com/docker/buildx/commands/debug" "github.com/docker/buildx/monitor" "github.com/docker/buildx/store" "github.com/docker/buildx/store/storeutil" @@ -441,20 +440,7 @@ func runBuildWithOptions(ctx context.Context, dockerCli command.Cli, opts *Build } } -func newDebuggableBuild(dockerCli command.Cli, rootOpts *rootOptions) debug.DebuggableCmd { - return &debuggableBuild{dockerCli: dockerCli, rootOpts: rootOpts} -} - -type debuggableBuild struct { - dockerCli command.Cli - rootOpts *rootOptions -} - -func (b *debuggableBuild) NewDebugger(cfg *debug.DebugConfig) *cobra.Command { - return buildCmd(b.dockerCli, b.rootOpts, cfg) -} - -func buildCmd(dockerCli command.Cli, rootOpts *rootOptions, debugConfig *debug.DebugConfig) *cobra.Command { +func buildCmd(dockerCli command.Cli, rootOpts *rootOptions, debugConfig *debugOptions) *cobra.Command { cFlags := &commonFlags{} options := &buildOptions{} diff --git a/commands/debug.go b/commands/debug.go new file mode 100644 index 000000000000..1779b47a9248 --- /dev/null +++ b/commands/debug.go @@ -0,0 +1,34 @@ +package commands + +import ( + "github.com/docker/buildx/util/cobrautil" + "github.com/docker/cli/cli/command" + "github.com/spf13/cobra" +) + +type debugOptions struct { + // InvokeFlag is a flag to configure the launched debugger and the commaned executed on the debugger. + InvokeFlag string + + // OnFlag is a flag to configure the timing of launching the debugger. + OnFlag string +} + +func debugCmd(dockerCli command.Cli, rootOpts *rootOptions) *cobra.Command { + var options debugOptions + + cmd := &cobra.Command{ + Use: "debug", + Short: "Start debugger", + } + cobrautil.MarkCommandExperimental(cmd) + + flags := cmd.Flags() + flags.StringVar(&options.InvokeFlag, "invoke", "", "Launch a monitor with executing specified command") + flags.StringVar(&options.OnFlag, "on", "error", "When to launch the monitor ([always, error])") + + cobrautil.MarkFlagsExperimental(flags, "invoke", "on") + + cmd.AddCommand(buildCmd(dockerCli, rootOpts, &options)) + return cmd +} diff --git a/commands/debug/root.go b/commands/debug/root.go deleted file mode 100644 index 8ddc0df1d585..000000000000 --- a/commands/debug/root.go +++ /dev/null @@ -1,46 +0,0 @@ -package debug - -import ( - "github.com/docker/buildx/util/cobrautil" - "github.com/docker/cli/cli/command" - "github.com/spf13/cobra" -) - -// DebugConfig is a user-specified configuration for the debugger. -type DebugConfig struct { - // InvokeFlag is a flag to configure the launched debugger and the commaned executed on the debugger. - InvokeFlag string - - // OnFlag is a flag to configure the timing of launching the debugger. - OnFlag string -} - -// DebuggableCmd is a command that supports debugger with recognizing the user-specified DebugConfig. -type DebuggableCmd interface { - // NewDebugger returns the new *cobra.Command with support for the debugger with recognizing DebugConfig. - NewDebugger(*DebugConfig) *cobra.Command -} - -func RootCmd(dockerCli command.Cli, children ...DebuggableCmd) *cobra.Command { - var progressMode string - var options DebugConfig - - cmd := &cobra.Command{ - Use: "debug", - Short: "Start debugger", - } - cobrautil.MarkCommandExperimental(cmd) - - flags := cmd.Flags() - flags.StringVar(&options.InvokeFlag, "invoke", "", "Launch a monitor with executing specified command") - flags.StringVar(&options.OnFlag, "on", "error", "When to launch the monitor ([always, error])") - flags.StringVar(&progressMode, "progress", "auto", `Set type of progress output ("auto", "plain", "tty", "rawjson") for the monitor. Use plain to show container output`) - - cobrautil.MarkFlagsExperimental(flags, "invoke", "on") - - for _, c := range children { - cmd.AddCommand(c.NewDebugger(&options)) - } - - return cmd -} diff --git a/commands/root.go b/commands/root.go index d42eb44b08b9..d34d5ed110f5 100644 --- a/commands/root.go +++ b/commands/root.go @@ -4,7 +4,6 @@ import ( "fmt" "os" - debugcmd "github.com/docker/buildx/commands/debug" historycmd "github.com/docker/buildx/commands/history" imagetoolscmd "github.com/docker/buildx/commands/imagetools" "github.com/docker/buildx/util/cobrautil/completion" @@ -120,9 +119,7 @@ func addCommands(cmd *cobra.Command, opts *rootOptions, dockerCli command.Cli) { historycmd.RootCmd(cmd, dockerCli, historycmd.RootOptions{Builder: &opts.builder}), ) if confutil.IsExperimental() { - cmd.AddCommand(debugcmd.RootCmd(dockerCli, - newDebuggableBuild(dockerCli, opts), - )) + cmd.AddCommand(debugCmd(dockerCli, opts)) } cmd.RegisterFlagCompletionFunc( //nolint:errcheck diff --git a/docs/reference/buildx_debug.md b/docs/reference/buildx_debug.md index afe695674592..028be05cd3d6 100644 --- a/docs/reference/buildx_debug.md +++ b/docs/reference/buildx_debug.md @@ -12,13 +12,12 @@ Start debugger (EXPERIMENTAL) ### Options -| Name | Type | Default | Description | -|:----------------|:---------|:--------|:--------------------------------------------------------------------------------------------------------------------| -| `--builder` | `string` | | Override the configured builder instance | -| `-D`, `--debug` | `bool` | | Enable debug logging | -| `--invoke` | `string` | | Launch a monitor with executing specified command (EXPERIMENTAL) | -| `--on` | `string` | `error` | When to launch the monitor ([always, error]) (EXPERIMENTAL) | -| `--progress` | `string` | `auto` | Set type of progress output (`auto`, `plain`, `tty`, `rawjson`) for the monitor. Use plain to show container output | +| Name | Type | Default | Description | +|:----------------|:---------|:--------|:-----------------------------------------------------------------| +| `--builder` | `string` | | Override the configured builder instance | +| `-D`, `--debug` | `bool` | | Enable debug logging | +| `--invoke` | `string` | | Launch a monitor with executing specified command (EXPERIMENTAL) | +| `--on` | `string` | `error` | When to launch the monitor ([always, error]) (EXPERIMENTAL) |