Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings
This repository was archived by the owner on Aug 30, 2024. It is now read-only.
/coder-v1-cliPublic archive

Commit38ef6de

Browse files
authored
Merge pull request#32 from cdr/wsep-sh
Migrate coder sh to wsep
2 parentsba7ea67 +925216e commit38ef6de

File tree

11 files changed

+326
-352
lines changed

11 files changed

+326
-352
lines changed

‎README.md

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,7 @@ To report bugs and request features, please [open an issue](https://github.com/c
88

99
##Installation
1010

11-
To install the latest version use:
12-
13-
```bash
14-
go get cdr.dev/coder-cli/cmd/coder
15-
```
16-
17-
To install a specific[release](https://github.com/cdr/coder-cli/releases):
11+
Install the latest release[here](https://github.com/cdr/coder-cli/releases):
1812

1913
1. Click a release and download the tar file for your operating system (ex: coder-cli-linux-amd64.tar.gz)
2014
2. Extract the`coder` binary from the tar file, ex:

‎cmd/coder/shell.go

Lines changed: 35 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,7 @@ import (
1616
"go.coder.com/cli"
1717
"go.coder.com/flog"
1818

19-
client"cdr.dev/coder-cli/internal/entclient"
20-
"cdr.dev/coder-cli/wush"
19+
"cdr.dev/wsep"
2120
)
2221

2322
typeshellCmdstruct {
@@ -45,29 +44,32 @@ func enableTerminal(fd int) (restore func(), err error) {
4544
},nil
4645
}
4746

48-
funcsendResizeEvents(termfdint,client*wush.Client) {
47+
funcsendResizeEvents(ctx context.Context,termfdint,process wsep.Process) {
4948
sigs:=make(chan os.Signal,16)
5049
signal.Notify(sigs,unix.SIGWINCH)
5150

5251
// Limit the frequency of resizes to prevent a stuttering effect.
5352
resizeLimiter:=rate.NewLimiter(rate.Every(time.Millisecond*100),1)
5453

55-
for {
54+
forctx.Err()==nil {
55+
ifctx.Err()!=nil {
56+
return
57+
}
5658
width,height,err:=terminal.GetSize(termfd)
5759
iferr!=nil {
5860
flog.Error("get term size: %v",err)
5961
return
6062
}
6163

62-
err=client.Resize(width,height)
64+
err=process.Resize(ctx,uint16(height),uint16(width))
6365
iferr!=nil {
64-
flog.Error("get term size: %v",err)
66+
flog.Error("set term size: %v",err)
6567
return
6668
}
6769

6870
// Do this last so the first resize is sent.
6971
<-sigs
70-
resizeLimiter.Wait(context.Background())
72+
resizeLimiter.Wait(ctx)
7173
}
7274
}
7375

@@ -78,6 +80,7 @@ func (cmd *shellCmd) Run(fl *pflag.FlagSet) {
7880
var (
7981
envName=fl.Arg(0)
8082
command=fl.Arg(1)
83+
ctx=context.Background()
8184
)
8285

8386
varargs []string
@@ -91,14 +94,16 @@ func (cmd *shellCmd) Run(fl *pflag.FlagSet) {
9194
args= []string{"-c","exec $(getent passwd $(whoami) | awk -F: '{ print $7 }')"}
9295
}
9396

94-
exitCode,err:=runCommand(envName,command,args)
97+
err:=runCommand(ctx,envName,command,args)
98+
ifexitErr,ok:=err.(wsep.ExitError);ok {
99+
os.Exit(exitErr.Code)
100+
}
95101
iferr!=nil {
96102
flog.Fatal("run command: %v Is it online?",err)
97103
}
98-
os.Exit(exitCode)
99104
}
100105

101-
funcrunCommand(envNamestring,commandstring,args []string)(int,error) {
106+
funcrunCommand(ctx context.Context,envNamestring,commandstring,args []string)error {
102107
var (
103108
entClient=requireAuth()
104109
env=findEnv(entClient,envName)
@@ -110,38 +115,37 @@ func runCommand(envName string, command string, args []string) (int, error) {
110115
iftty {
111116
restore,err:=enableTerminal(termfd)
112117
iferr!=nil {
113-
return-1,err
118+
returnerr
114119
}
115120
deferrestore()
116121
}
117122

118-
conn,err:=entClient.DialWush(
119-
env,
120-
&client.WushOptions{
121-
TTY:tty,
122-
Stdin:true,
123-
},command,args...)
123+
conn,err:=entClient.DialWsep(ctx,env)
124+
iferr!=nil {
125+
returnerr
126+
}
127+
128+
execer:=wsep.RemoteExecer(conn)
129+
process,err:=execer.Start(ctx, wsep.Command{
130+
Command:command,
131+
Args:args,
132+
TTY:tty,
133+
})
124134
iferr!=nil {
125-
return-1,err
135+
returnerr
126136
}
127-
ctx:=context.Background()
128137

129-
wc:=wush.NewClient(ctx,conn)
130138
iftty {
131-
gosendResizeEvents(termfd,wc)
139+
gosendResizeEvents(ctx,termfd,process)
132140
}
133141

134142
gofunc() {
135-
deferwc.Stdin.Close()
136-
io.Copy(wc.Stdin,os.Stdin)
143+
stdin:=process.Stdin()
144+
deferstdin.Close()
145+
io.Copy(stdin,os.Stdin)
137146
}()
138-
goio.Copy(os.Stdout,wc.Stdout)
139-
goio.Copy(os.Stderr,wc.Stderr)
140-
141-
exitCode,err:=wc.Wait()
142-
iferr!=nil {
143-
return-1,err
144-
}
147+
goio.Copy(os.Stdout,process.Stdout())
148+
goio.Copy(os.Stderr,process.Stderr())
145149

146-
returnint(exitCode),nil
150+
returnprocess.Wait()
147151
}

‎go.mod

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,19 +3,21 @@ module cdr.dev/coder-cli
33
go1.14
44

55
require (
6+
cdr.dev/wsepv0.0.0-20200602025116-5cbe721683df
7+
github.com/fatih/colorv1.9.0// indirect
68
github.com/gorilla/websocketv1.4.1
79
github.com/kirsle/configdirv0.0.0-20170128060238-e45d2f54772f
8-
github.com/mattn/go-colorablev0.1.2// indirect
9-
github.com/mattn/go-isattyv0.0.12// indirect
10+
github.com/klauspost/compressv1.10.7// indirect
11+
github.com/mattn/go-colorablev0.1.6// indirect
1012
github.com/pkg/browserv0.0.0-20180916011732-0a3d74bf9ce4
1113
github.com/rjeczalik/notifyv0.9.2
1214
github.com/spf13/pflagv1.0.5
1315
go.coder.com/cliv0.4.0
1416
go.coder.com/flogv0.0.0-20190906214207-47dd47ea0512
1517
golang.org/x/cryptov0.0.0-20200422194213-44a606286825
1618
golang.org/x/syncv0.0.0-20200317015054-43a5402ce75a
17-
golang.org/x/sysv0.0.0-20200413165638-669c56c373c4
19+
golang.org/x/sysv0.0.0-20200523222454-059865788121
1820
golang.org/x/timev0.0.0-20191024005414-555d28b269f0
1921
golang.org/x/xerrorsv0.0.0-20191204190536-9bdfabe68543
20-
nhooyr.io/websocketv1.8.5
22+
nhooyr.io/websocketv1.8.6
2123
)

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp