mirror of
https://gitea.com/Lydanne/buildx.git
synced 2025-05-18 00:47:48 +08:00

Print more understandable messages on error: - When ps fails because the monitor doesn't attach to any session, print "no attaching session" instead of "unknown ref". - Avoid disconnect silently fails when the monitor doesn't attach to any session. Print "no attaching session" error instead. - Fix error message of "attach"'s arguments. ("server name must be passed" -> "ID of session or process must be passed") Signed-off-by: Kohei Tokunaga <ktokunaga.mail@gmail.com>
45 lines
1.1 KiB
Go
45 lines
1.1 KiB
Go
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]
|
|
} else if target == "" {
|
|
return errors.Errorf("no attaching session")
|
|
}
|
|
isProcess, err := isProcessID(ctx, cm.m, target)
|
|
if err == nil && isProcess {
|
|
sid := cm.m.AttachedSessionID()
|
|
if sid == "" {
|
|
return errors.Errorf("no attaching session")
|
|
}
|
|
if err := cm.m.DisconnectProcess(ctx, sid, 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
|
|
}
|