@@ -18,8 +18,8 @@ func (r *RootCmd) workspaceProxy() *clibase.Cmd {
18
18
Use : "workspace-proxy" ,
19
19
Short : "Workspace proxies provide low-latency experiences for geo-distributed teams." ,
20
20
Long : "Workspace proxies provide low-latency experiences for geo-distributed teams. " +
21
- "It will act as a connection gateway to your workspace providing a lower latency solution " +
22
- "to connecting to your workspace if Coder and your workspace are deployed in different regions." ,
21
+ "It will act as a connection gateway to your workspace. " +
22
+ "Best used if Coder and your workspace are deployed in different regions." ,
23
23
Aliases : []string {"wsproxy" },
24
24
Hidden : true ,
25
25
Handler : func (inv * clibase.Invocation ) error {
@@ -51,6 +51,7 @@ func (r *RootCmd) regenerateProxyToken() *clibase.Cmd {
51
51
),
52
52
Handler : func (inv * clibase.Invocation ) error {
53
53
ctx := inv .Context ()
54
+ formatter .primaryAccessURL = client .URL .String ()
54
55
// This is cheeky, but you can also use a uuid string in
55
56
// 'DeleteWorkspaceProxyByName' and it will work.
56
57
proxy , err := client .WorkspaceProxyByName (ctx , inv .Args [0 ])
@@ -120,6 +121,7 @@ func (r *RootCmd) patchProxy() *clibase.Cmd {
120
121
Handler : func (inv * clibase.Invocation ) error {
121
122
ctx := inv .Context ()
122
123
if proxyIcon == "" && displayName == "" && proxyName == "" {
124
+ _ = inv .Command .HelpHandler (inv )
123
125
return xerrors .Errorf ("specify at least one field to update" )
124
126
}
125
127
@@ -187,13 +189,32 @@ func (r *RootCmd) deleteProxy() *clibase.Cmd {
187
189
cmd := & clibase.Cmd {
188
190
Use : "delete <name|id>" ,
189
191
Short : "Delete a workspace proxy" ,
192
+ Options : clibase.OptionSet {
193
+ cliui .SkipPromptOption (),
194
+ },
190
195
Middleware : clibase .Chain (
191
196
clibase .RequireNArgs (1 ),
192
197
r .InitClient (client ),
193
198
),
194
199
Handler : func (inv * clibase.Invocation ) error {
195
200
ctx := inv .Context ()
196
- err := client .DeleteWorkspaceProxyByName (ctx , inv .Args [0 ])
201
+
202
+ wsproxy , err := client .WorkspaceProxyByName (ctx , inv .Args [0 ])
203
+ if err != nil {
204
+ return xerrors .Errorf ("fetch workspace proxy %q: %w" , inv .Args [0 ], err )
205
+ }
206
+
207
+ // Confirm deletion of the template.
208
+ _ , err = cliui .Prompt (inv , cliui.PromptOptions {
209
+ Text : fmt .Sprintf ("Delete this workspace proxy: %s?" , cliui .DefaultStyles .Code .Render (wsproxy .DisplayName )),
210
+ IsConfirm : true ,
211
+ Default : cliui .ConfirmNo ,
212
+ })
213
+ if err != nil {
214
+ return err
215
+ }
216
+
217
+ err = client .DeleteWorkspaceProxyByName (ctx , inv .Args [0 ])
197
218
if err != nil {
198
219
return xerrors .Errorf ("delete workspace proxy %q: %w" , inv .Args [0 ], err )
199
220
}
@@ -225,6 +246,7 @@ func (r *RootCmd) createProxy() *clibase.Cmd {
225
246
),
226
247
Handler : func (inv * clibase.Invocation ) error {
227
248
ctx := inv .Context ()
249
+ formatter .primaryAccessURL = client .URL .String ()
228
250
var err error
229
251
if proxyName == "" && ! noPrompts {
230
252
proxyName , err = cliui .Prompt (inv , cliui.PromptOptions {
@@ -367,8 +389,9 @@ func (r *RootCmd) listProxies() *clibase.Cmd {
367
389
368
390
// updateProxyResponseFormatter is used for both create and regenerate proxy commands.
369
391
type updateProxyResponseFormatter struct {
370
- onlyToken bool
371
- formatter * cliui.OutputFormatter
392
+ onlyToken bool
393
+ formatter * cliui.OutputFormatter
394
+ primaryAccessURL string
372
395
}
373
396
374
397
func (f * updateProxyResponseFormatter ) Format (ctx context.Context , data codersdk.UpdateWorkspaceProxyResponse ) (string , error ) {
@@ -392,31 +415,37 @@ func (f *updateProxyResponseFormatter) AttachOptions(opts *clibase.OptionSet) {
392
415
func newUpdateProxyResponseFormatter () * updateProxyResponseFormatter {
393
416
up := & updateProxyResponseFormatter {
394
417
onlyToken : false ,
395
- formatter : cliui .NewOutputFormatter (
396
- // Text formatter should be human readable.
397
- cliui .ChangeFormatterData (cliui .TextFormat (), func (data any ) (any , error ) {
418
+ }
419
+ up .formatter = cliui .NewOutputFormatter (
420
+ // Text formatter should be human readable.
421
+ cliui .ChangeFormatterData (cliui .TextFormat (), func (data any ) (any , error ) {
422
+ response , ok := data .(codersdk.UpdateWorkspaceProxyResponse )
423
+ if ! ok {
424
+ return nil , xerrors .Errorf ("unexpected type %T" , data )
425
+ }
426
+
427
+ return fmt .Sprintf ("Workspace Proxy %[1]q updated successfully.\n " +
428
+ cliui .DefaultStyles .Placeholder .Render ("—————————————————————————————————————————————————" )+ "\n " +
429
+ "Save this authentication token, it will not be shown again.\n " +
430
+ "Token: %[2]s\n " +
431
+ "\n " +
432
+ "Start the proxy by running:\n " +
433
+ cliui .DefaultStyles .Code .Render ("CODER_PROXY_SESSION_TOKEN=%[2]s coder wsproxy server --primary-access-url %[3]s --http-address=0.0.0.0:3001" )+
434
+ // This is required to turn off the code style. Otherwise it appears in the code block until the end of the line.
435
+ cliui .DefaultStyles .Placeholder .Render ("" ),
436
+ response .Proxy .Name , response .ProxyToken , up .primaryAccessURL ), nil
437
+ }),
438
+ cliui .JSONFormat (),
439
+ // Table formatter expects a slice, make a slice of one.
440
+ cliui .ChangeFormatterData (cliui .TableFormat ([]codersdk.UpdateWorkspaceProxyResponse {}, []string {"proxy name" , "proxy url" , "proxy token" }),
441
+ func (data any ) (any , error ) {
398
442
response , ok := data .(codersdk.UpdateWorkspaceProxyResponse )
399
443
if ! ok {
400
444
return nil , xerrors .Errorf ("unexpected type %T" , data )
401
445
}
402
-
403
- return fmt .Sprintf ("Workspace Proxy %q updated successfully.\n " +
404
- cliui .DefaultStyles .Placeholder .Render ("—————————————————————————————————————————————————" )+ "\n " +
405
- "Save this authentication token, it will not be shown again.\n " +
406
- "Token: %s\n " , response .Proxy .Name , response .ProxyToken ), nil
446
+ return []codersdk.UpdateWorkspaceProxyResponse {response }, nil
407
447
}),
408
- cliui .JSONFormat (),
409
- // Table formatter expects a slice, make a slice of one.
410
- cliui .ChangeFormatterData (cliui .TableFormat ([]codersdk.UpdateWorkspaceProxyResponse {}, []string {"proxy name" , "proxy url" , "proxy token" }),
411
- func (data any ) (any , error ) {
412
- response , ok := data .(codersdk.UpdateWorkspaceProxyResponse )
413
- if ! ok {
414
- return nil , xerrors .Errorf ("unexpected type %T" , data )
415
- }
416
- return []codersdk.UpdateWorkspaceProxyResponse {response }, nil
417
- }),
418
- ),
419
- }
448
+ )
420
449
421
450
return up
422
451
}
0 commit comments