monitor: Move commands to a separated package

This commit moves monitor commands to `monior/commands` package.
Commands still need access to the `monitor` object and buildx controller so this
commit enables this via `Monitor` interface stored in `monitor/types`.

Signed-off-by: Kohei Tokunaga <ktokunaga.mail@gmail.com>
This commit is contained in:
Kohei Tokunaga
2023-04-18 21:27:23 +09:00
parent 75ed3e296b
commit 0a7a2b1882
10 changed files with 624 additions and 206 deletions

27
monitor/commands/kill.go Normal file
View File

@ -0,0 +1,27 @@
package commands
import (
"context"
"github.com/docker/buildx/monitor/types"
"github.com/pkg/errors"
)
type KillCmd struct {
m types.Monitor
}
func NewKillCmd(m types.Monitor) types.Command {
return &KillCmd{m}
}
func (cm *KillCmd) Info() types.CommandInfo {
return types.CommandInfo{HelpMessage: "kill buildx server"}
}
func (cm *KillCmd) Exec(ctx context.Context, args []string) error {
if err := cm.m.Kill(ctx); err != nil {
return errors.Errorf("failed to kill: %v", err)
}
return nil
}