@@ -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 ])
@@ -226,6 +227,7 @@ func (r *RootCmd) createProxy() *clibase.Cmd {
226
227
),
227
228
Handler : func (inv * clibase.Invocation ) error {
228
229
ctx := inv .Context ()
230
+ formatter .primaryAccessURL = client .URL .String ()
229
231
var err error
230
232
if proxyName == "" && ! noPrompts {
231
233
proxyName , err = cliui .Prompt (inv , cliui.PromptOptions {
@@ -368,8 +370,9 @@ func (r *RootCmd) listProxies() *clibase.Cmd {
368
370
369
371
// updateProxyResponseFormatter is used for both create and regenerate proxy commands.
370
372
type updateProxyResponseFormatter struct {
371
- onlyToken bool
372
- formatter * cliui.OutputFormatter
373
+ onlyToken bool
374
+ formatter * cliui.OutputFormatter
375
+ primaryAccessURL string
373
376
}
374
377
375
378
func (f * updateProxyResponseFormatter ) Format (ctx context.Context , data codersdk.UpdateWorkspaceProxyResponse ) (string , error ) {
@@ -393,31 +396,37 @@ func (f *updateProxyResponseFormatter) AttachOptions(opts *clibase.OptionSet) {
393
396
func newUpdateProxyResponseFormatter () * updateProxyResponseFormatter {
394
397
up := & updateProxyResponseFormatter {
395
398
onlyToken : false ,
396
- formatter : cliui .NewOutputFormatter (
397
- // Text formatter should be human readable.
398
- cliui .ChangeFormatterData (cliui .TextFormat (), func (data any ) (any , error ) {
399
+ }
400
+ up .formatter = cliui .NewOutputFormatter (
401
+ // Text formatter should be human readable.
402
+ cliui .ChangeFormatterData (cliui .TextFormat (), func (data any ) (any , error ) {
403
+ response , ok := data .(codersdk.UpdateWorkspaceProxyResponse )
404
+ if ! ok {
405
+ return nil , xerrors .Errorf ("unexpected type %T" , data )
406
+ }
407
+
408
+ return fmt .Sprintf ("Workspace Proxy %[1]q updated successfully.\n " +
409
+ cliui .DefaultStyles .Placeholder .Render ("—————————————————————————————————————————————————" )+ "\n " +
410
+ "Save this authentication token, it will not be shown again.\n " +
411
+ "Token: %[2]s\n " +
412
+ "\n " +
413
+ "Start the proxy by running:\n " +
414
+ 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" )+
415
+ // This is required to turn off the code style. Otherwise it appears in the code block until the end of the line.
416
+ cliui .DefaultStyles .Placeholder .Render ("" ),
417
+ response .Proxy .Name , response .ProxyToken , up .primaryAccessURL ), nil
418
+ }),
419
+ cliui .JSONFormat (),
420
+ // Table formatter expects a slice, make a slice of one.
421
+ cliui .ChangeFormatterData (cliui .TableFormat ([]codersdk.UpdateWorkspaceProxyResponse {}, []string {"proxy name" , "proxy url" , "proxy token" }),
422
+ func (data any ) (any , error ) {
399
423
response , ok := data .(codersdk.UpdateWorkspaceProxyResponse )
400
424
if ! ok {
401
425
return nil , xerrors .Errorf ("unexpected type %T" , data )
402
426
}
403
-
404
- return fmt .Sprintf ("Workspace Proxy %q updated successfully.\n " +
405
- cliui .DefaultStyles .Placeholder .Render ("—————————————————————————————————————————————————" )+ "\n " +
406
- "Save this authentication token, it will not be shown again.\n " +
407
- "Token: %s\n " , response .Proxy .Name , response .ProxyToken ), nil
427
+ return []codersdk.UpdateWorkspaceProxyResponse {response }, nil
408
428
}),
409
- cliui .JSONFormat (),
410
- // Table formatter expects a slice, make a slice of one.
411
- cliui .ChangeFormatterData (cliui .TableFormat ([]codersdk.UpdateWorkspaceProxyResponse {}, []string {"proxy name" , "proxy url" , "proxy token" }),
412
- func (data any ) (any , error ) {
413
- response , ok := data .(codersdk.UpdateWorkspaceProxyResponse )
414
- if ! ok {
415
- return nil , xerrors .Errorf ("unexpected type %T" , data )
416
- }
417
- return []codersdk.UpdateWorkspaceProxyResponse {response }, nil
418
- }),
419
- ),
420
- }
429
+ )
421
430
422
431
return up
423
432
}
0 commit comments