You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
39 lines
958 B
Go
39 lines
958 B
Go
2 years ago
|
package commands
|
||
|
|
||
|
import (
|
||
|
"context"
|
||
|
|
||
|
"github.com/docker/buildx/monitor/types"
|
||
|
"github.com/pkg/errors"
|
||
|
)
|
||
|
|
||
|
type DisconnectCmd struct {
|
||
|
m types.Monitor
|
||
|
}
|
||
|
|
||
|
func NewDisconnectCmd(m types.Monitor) types.Command {
|
||
|
return &DisconnectCmd{m}
|
||
|
}
|
||
|
|
||
|
func (cm *DisconnectCmd) Info() types.CommandInfo {
|
||
|
return types.CommandInfo{HelpMessage: "disconnect a client from a buildx server. Specific session ID can be specified an arg"}
|
||
|
}
|
||
|
|
||
|
func (cm *DisconnectCmd) Exec(ctx context.Context, args []string) error {
|
||
|
target := cm.m.AttachedSessionID()
|
||
|
if len(args) >= 2 {
|
||
|
target = args[1]
|
||
|
}
|
||
|
isProcess, err := isProcessID(ctx, cm.m, target)
|
||
|
if err == nil && isProcess {
|
||
|
if err := cm.m.DisconnectProcess(ctx, target); err != nil {
|
||
|
return errors.Errorf("disconnecting from process failed %v", target)
|
||
|
}
|
||
|
return nil
|
||
|
}
|
||
|
if err := cm.m.DisconnectSession(ctx, target); err != nil {
|
||
|
return errors.Errorf("disconnecting from session failed: %v", err)
|
||
|
}
|
||
|
return nil
|
||
|
}
|