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 <jonathan.sternberg@docker.com>
This commit is contained in:
+1
-15
@@ -20,7 +20,6 @@ import (
|
|||||||
"github.com/containerd/console"
|
"github.com/containerd/console"
|
||||||
"github.com/docker/buildx/build"
|
"github.com/docker/buildx/build"
|
||||||
"github.com/docker/buildx/builder"
|
"github.com/docker/buildx/builder"
|
||||||
"github.com/docker/buildx/commands/debug"
|
|
||||||
"github.com/docker/buildx/monitor"
|
"github.com/docker/buildx/monitor"
|
||||||
"github.com/docker/buildx/store"
|
"github.com/docker/buildx/store"
|
||||||
"github.com/docker/buildx/store/storeutil"
|
"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 {
|
func buildCmd(dockerCli command.Cli, rootOpts *rootOptions, debugConfig *debugOptions) *cobra.Command {
|
||||||
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 {
|
|
||||||
cFlags := &commonFlags{}
|
cFlags := &commonFlags{}
|
||||||
options := &buildOptions{}
|
options := &buildOptions{}
|
||||||
|
|
||||||
|
|||||||
@@ -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
|
||||||
|
}
|
||||||
@@ -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
|
|
||||||
}
|
|
||||||
+1
-4
@@ -4,7 +4,6 @@ import (
|
|||||||
"fmt"
|
"fmt"
|
||||||
"os"
|
"os"
|
||||||
|
|
||||||
debugcmd "github.com/docker/buildx/commands/debug"
|
|
||||||
historycmd "github.com/docker/buildx/commands/history"
|
historycmd "github.com/docker/buildx/commands/history"
|
||||||
imagetoolscmd "github.com/docker/buildx/commands/imagetools"
|
imagetoolscmd "github.com/docker/buildx/commands/imagetools"
|
||||||
"github.com/docker/buildx/util/cobrautil/completion"
|
"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}),
|
historycmd.RootCmd(cmd, dockerCli, historycmd.RootOptions{Builder: &opts.builder}),
|
||||||
)
|
)
|
||||||
if confutil.IsExperimental() {
|
if confutil.IsExperimental() {
|
||||||
cmd.AddCommand(debugcmd.RootCmd(dockerCli,
|
cmd.AddCommand(debugCmd(dockerCli, opts))
|
||||||
newDebuggableBuild(dockerCli, opts),
|
|
||||||
))
|
|
||||||
}
|
}
|
||||||
|
|
||||||
cmd.RegisterFlagCompletionFunc( //nolint:errcheck
|
cmd.RegisterFlagCompletionFunc( //nolint:errcheck
|
||||||
|
|||||||
@@ -12,13 +12,12 @@ Start debugger (EXPERIMENTAL)
|
|||||||
|
|
||||||
### Options
|
### Options
|
||||||
|
|
||||||
| Name | Type | Default | Description |
|
| Name | Type | Default | Description |
|
||||||
|:----------------|:---------|:--------|:--------------------------------------------------------------------------------------------------------------------|
|
|:----------------|:---------|:--------|:-----------------------------------------------------------------|
|
||||||
| `--builder` | `string` | | Override the configured builder instance |
|
| `--builder` | `string` | | Override the configured builder instance |
|
||||||
| `-D`, `--debug` | `bool` | | Enable debug logging |
|
| `-D`, `--debug` | `bool` | | Enable debug logging |
|
||||||
| `--invoke` | `string` | | Launch a monitor with executing specified command (EXPERIMENTAL) |
|
| `--invoke` | `string` | | Launch a monitor with executing specified command (EXPERIMENTAL) |
|
||||||
| `--on` | `string` | `error` | When to launch the monitor ([always, error]) (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 |
|
|
||||||
|
|
||||||
|
|
||||||
<!---MARKER_GEN_END-->
|
<!---MARKER_GEN_END-->
|
||||||
|
|||||||
Reference in New Issue
Block a user