Skip to content

Commit 7f5ff6b

Browse files
committed
commands: remove debug package in commands
The package just causes the entire flow to be more complicated as build has to pretend it doesn't know about debug options and the debugger has to pretend it doesn't know about the build. This abstraction has been difficult when integrating a DAP command into this same workflow so I don't think this abstraction has much of a value. Signed-off-by: Jonathan A. Sternberg <[email protected]>
1 parent 32e9bfc commit 7f5ff6b

File tree

5 files changed

+42
-72
lines changed

5 files changed

+42
-72
lines changed

commands/build.go

Lines changed: 1 addition & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@ import (
2020
"github.com/containerd/console"
2121
"github.com/docker/buildx/build"
2222
"github.com/docker/buildx/builder"
23-
"github.com/docker/buildx/commands/debug"
2423
"github.com/docker/buildx/monitor"
2524
"github.com/docker/buildx/store"
2625
"github.com/docker/buildx/store/storeutil"
@@ -441,20 +440,7 @@ func runBuildWithOptions(ctx context.Context, dockerCli command.Cli, opts *Build
441440
}
442441
}
443442

444-
func newDebuggableBuild(dockerCli command.Cli, rootOpts *rootOptions) debug.DebuggableCmd {
445-
return &debuggableBuild{dockerCli: dockerCli, rootOpts: rootOpts}
446-
}
447-
448-
type debuggableBuild struct {
449-
dockerCli command.Cli
450-
rootOpts *rootOptions
451-
}
452-
453-
func (b *debuggableBuild) NewDebugger(cfg *debug.DebugConfig) *cobra.Command {
454-
return buildCmd(b.dockerCli, b.rootOpts, cfg)
455-
}
456-
457-
func buildCmd(dockerCli command.Cli, rootOpts *rootOptions, debugConfig *debug.DebugConfig) *cobra.Command {
443+
func buildCmd(dockerCli command.Cli, rootOpts *rootOptions, debugConfig *debugOptions) *cobra.Command {
458444
cFlags := &commonFlags{}
459445
options := &buildOptions{}
460446

commands/debug.go

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
package commands
2+
3+
import (
4+
"github.com/docker/buildx/util/cobrautil"
5+
"github.com/docker/cli/cli/command"
6+
"github.com/spf13/cobra"
7+
)
8+
9+
type debugOptions struct {
10+
// InvokeFlag is a flag to configure the launched debugger and the commaned executed on the debugger.
11+
InvokeFlag string
12+
13+
// OnFlag is a flag to configure the timing of launching the debugger.
14+
OnFlag string
15+
}
16+
17+
func debugCmd(dockerCli command.Cli, rootOpts *rootOptions) *cobra.Command {
18+
var options debugOptions
19+
20+
cmd := &cobra.Command{
21+
Use: "debug",
22+
Short: "Start debugger",
23+
}
24+
cobrautil.MarkCommandExperimental(cmd)
25+
26+
flags := cmd.Flags()
27+
flags.StringVar(&options.InvokeFlag, "invoke", "", "Launch a monitor with executing specified command")
28+
flags.StringVar(&options.OnFlag, "on", "error", "When to launch the monitor ([always, error])")
29+
30+
cobrautil.MarkFlagsExperimental(flags, "invoke", "on")
31+
32+
cmd.AddCommand(buildCmd(dockerCli, rootOpts, &options))
33+
return cmd
34+
}

commands/debug/root.go

Lines changed: 0 additions & 46 deletions
This file was deleted.

commands/root.go

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ import (
44
"fmt"
55
"os"
66

7-
debugcmd "github.com/docker/buildx/commands/debug"
87
historycmd "github.com/docker/buildx/commands/history"
98
imagetoolscmd "github.com/docker/buildx/commands/imagetools"
109
"github.com/docker/buildx/util/cobrautil/completion"
@@ -120,9 +119,7 @@ func addCommands(cmd *cobra.Command, opts *rootOptions, dockerCli command.Cli) {
120119
historycmd.RootCmd(cmd, dockerCli, historycmd.RootOptions{Builder: &opts.builder}),
121120
)
122121
if confutil.IsExperimental() {
123-
cmd.AddCommand(debugcmd.RootCmd(dockerCli,
124-
newDebuggableBuild(dockerCli, opts),
125-
))
122+
cmd.AddCommand(debugCmd(dockerCli, opts))
126123
}
127124

128125
cmd.RegisterFlagCompletionFunc( //nolint:errcheck

docs/reference/buildx_debug.md

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -12,13 +12,12 @@ Start debugger (EXPERIMENTAL)
1212

1313
### Options
1414

15-
| Name | Type | Default | Description |
16-
|:----------------|:---------|:--------|:--------------------------------------------------------------------------------------------------------------------|
17-
| `--builder` | `string` | | Override the configured builder instance |
18-
| `-D`, `--debug` | `bool` | | Enable debug logging |
19-
| `--invoke` | `string` | | Launch a monitor with executing specified command (EXPERIMENTAL) |
20-
| `--on` | `string` | `error` | When to launch the monitor ([always, error]) (EXPERIMENTAL) |
21-
| `--progress` | `string` | `auto` | Set type of progress output (`auto`, `plain`, `tty`, `rawjson`) for the monitor. Use plain to show container output |
15+
| Name | Type | Default | Description |
16+
|:----------------|:---------|:--------|:-----------------------------------------------------------------|
17+
| `--builder` | `string` | | Override the configured builder instance |
18+
| `-D`, `--debug` | `bool` | | Enable debug logging |
19+
| `--invoke` | `string` | | Launch a monitor with executing specified command (EXPERIMENTAL) |
20+
| `--on` | `string` | `error` | When to launch the monitor ([always, error]) (EXPERIMENTAL) |
2221

2322

2423
<!---MARKER_GEN_END-->

0 commit comments

Comments
 (0)