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

Commite8ef7c5

Browse files
pawbanadeansheather
authored andcommitted
feat: add cli command to list aibridge interceptions
1 parent0376096 commite8ef7c5

File tree

2 files changed

+134
-0
lines changed

2 files changed

+134
-0
lines changed

‎cli/aibridge.go‎

Lines changed: 133 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,133 @@
1+
package cli
2+
3+
import (
4+
"encoding/json"
5+
"fmt"
6+
"math"
7+
"time"
8+
9+
"github.com/google/uuid"
10+
"golang.org/x/xerrors"
11+
12+
"github.com/coder/coder/v2/cli/cliui"
13+
"github.com/coder/coder/v2/codersdk"
14+
"github.com/coder/serpent"
15+
)
16+
17+
func (r*RootCmd)aibridge()*serpent.Command {
18+
cmd:=&serpent.Command{
19+
Use:"aibridge",
20+
Short:"Manage aibridge.",
21+
Handler:func(inv*serpent.Invocation)error {
22+
returninv.Command.HelpHandler(inv)
23+
},
24+
Children: []*serpent.Command{
25+
r.listInvocations(),
26+
},
27+
}
28+
returncmd
29+
}
30+
31+
func (r*RootCmd)listInvocations()*serpent.Command {
32+
var (
33+
formatter=cliui.NewOutputFormatter(
34+
cliui.TableFormat(
35+
[]WorkspaceListRow{},
36+
[]string{},
37+
),
38+
cliui.JSONFormat(),
39+
)
40+
startstring
41+
endstring
42+
initiatiorstring
43+
limitint64
44+
cursorstring
45+
)
46+
47+
return&serpent.Command{
48+
Use:"list-invocations",
49+
Short:"List aibridge interceptions",
50+
Options: serpent.OptionSet{
51+
{
52+
Flag:"period-start",
53+
Description:"Time .",
54+
Default: time.Time{}.Format(time.RFC3339),
55+
Value:serpent.StringOf(&start),
56+
},
57+
{
58+
Flag:"period-end",
59+
Description:"Time .",
60+
Default: time.Time{}.Format(time.RFC3339),
61+
Value:serpent.StringOf(&end),
62+
},
63+
{
64+
Flag:"limit",
65+
Description:"Limit.",
66+
Default:"100",
67+
Value:serpent.Int64Of(&limit),
68+
},
69+
{
70+
Flag:"initiator",
71+
Description:"Initiator.",
72+
Default:uuid.Nil.String(),
73+
Value:serpent.StringOf(&initiatior),
74+
},
75+
{
76+
Flag:"cursor",
77+
Description:"Cursor.",
78+
Default:"{}",
79+
Value:serpent.StringOf(&cursor),
80+
},
81+
},
82+
Handler:func(inv*serpent.Invocation)error {
83+
client,err:=r.InitClient(inv)
84+
iferr!=nil {
85+
returnerr
86+
}
87+
88+
initID,err:=uuid.Parse(initiatior)
89+
iferr!=nil {
90+
returnerr
91+
}
92+
startTime,err:=time.Parse(time.RFC3339,start)
93+
iferr!=nil {
94+
returnerr
95+
}
96+
endTime,err:=time.Parse(time.RFC3339,end)
97+
iferr!=nil {
98+
returnerr
99+
}
100+
cursorObj:=&codersdk.AIBridgeListInterceptionsCursor{}
101+
err=json.Unmarshal([]byte(cursor),cursorObj)
102+
iferr!=nil {
103+
returnerr
104+
}
105+
iflimit>math.MaxInt32 {
106+
returnxerrors.Errorf("limit value to high")
107+
}
108+
iflimit<0 {
109+
returnxerrors.Errorf("limit value negative")
110+
}
111+
112+
exCli:=codersdk.NewExperimentalClient(client)
113+
resp,err:=exCli.AIBridgeListInterceptions(inv.Context(), codersdk.AIBridgeListInterceptionsRequest{
114+
PeriodStart:startTime,
115+
PeriodEnd:endTime,
116+
InitiatorID:initID,
117+
Limit:int32(limit),
118+
Cursor:*cursorObj,
119+
})
120+
iferr!=nil {
121+
returnerr
122+
}
123+
124+
out,err:=formatter.Format(inv.Context(),resp)
125+
iferr!=nil {
126+
returnerr
127+
}
128+
129+
_,err=fmt.Fprintln(inv.Stdout,out)
130+
returnerr
131+
},
132+
}
133+
}

‎cli/root.go‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -134,6 +134,7 @@ func (r *RootCmd) CoreSubcommands() []*serpent.Command {
134134
r.vpnDaemon(),
135135
r.vscodeSSH(),
136136
workspaceAgent(),
137+
r.aibridge(),
137138
}
138139
}
139140

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp