Skip to content

Commit b61fa9c

Browse files
committed
Fix import cycle
1 parent 0454d16 commit b61fa9c

File tree

5 files changed

+41
-8
lines changed

5 files changed

+41
-8
lines changed

client.go

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,19 @@ func RemoteExecer(conn *websocket.Conn) Execer {
2121
return remoteExec{conn: conn}
2222
}
2323

24-
func (r remoteExec) Start(ctx context.Context, c proto.Command) (Process, error) {
24+
type Command struct {
25+
Command string
26+
Args []string
27+
TTY bool
28+
UID uint32
29+
GID uint32
30+
Env []string
31+
WorkingDir string
32+
}
33+
34+
func (r remoteExec) Start(ctx context.Context, c Command) (Process, error) {
2535
header := proto.ClientStartHeader{
26-
Command: c,
36+
Command: mapToProtoCmd(c),
2737
Type: proto.TypeStart,
2838
}
2939
payload, err := json.Marshal(header)

dev/client/main.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ import (
66
"os"
77

88
"cdr.dev/wsep"
9-
"cdr.dev/wsep/internal/proto"
109
"github.com/spf13/pflag"
1110
"go.coder.com/cli"
1211
"go.coder.com/flog"
@@ -64,7 +63,7 @@ func do(fl *pflag.FlagSet, tty bool) {
6463
if len(fl.Args()) > 1 {
6564
args = fl.Args()[1:]
6665
}
67-
process, err := executor.Start(ctx, proto.Command{
66+
process, err := executor.Start(ctx, wsep.Command{
6867
Command: fl.Arg(0),
6968
Args: args,
7069
TTY: tty,

exec.go

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,5 +34,30 @@ type Process interface {
3434

3535
// Execer starts commands.
3636
type Execer interface {
37-
Start(ctx context.Context, c proto.Command) (Process, error)
37+
Start(ctx context.Context, c Command) (Process, error)
38+
}
39+
40+
// theses maps are needed to prevent an import cycle
41+
func mapToProtoCmd(c Command) proto.Command {
42+
return proto.Command{
43+
Command: c.Command,
44+
Args: c.Args,
45+
TTY: c.TTY,
46+
UID: c.UID,
47+
GID: c.GID,
48+
Env: c.Env,
49+
WorkingDir: c.WorkingDir,
50+
}
51+
}
52+
53+
func mapToClientCmd(c proto.Command) Command {
54+
return Command{
55+
Command: c.Command,
56+
Args: c.Args,
57+
TTY: c.TTY,
58+
UID: c.UID,
59+
GID: c.GID,
60+
Env: c.Env,
61+
WorkingDir: c.WorkingDir,
62+
}
3863
}

localexec.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ import (
77
"os/exec"
88
"syscall"
99

10-
"cdr.dev/wsep/internal/proto"
1110
"github.com/creack/pty"
1211
"golang.org/x/xerrors"
1312
)
@@ -66,7 +65,7 @@ func (l *localProcess) Pid() int {
6665
return l.cmd.Process.Pid
6766
}
6867

69-
func (l LocalExecer) Start(ctx context.Context, c proto.Command) (Process, error) {
68+
func (l LocalExecer) Start(ctx context.Context, c Command) (Process, error) {
7069
var (
7170
process localProcess
7271
err error

server.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ func Serve(ctx context.Context, c *websocket.Conn, execer Execer) error {
6161
if err != nil {
6262
return xerrors.Errorf("unmarshal start header: %w", err)
6363
}
64-
process, err = execer.Start(ctx, header.Command)
64+
process, err = execer.Start(ctx, mapToClientCmd(header.Command))
6565
if err != nil {
6666
return err
6767
}

0 commit comments

Comments
 (0)