MCPcopy Index your code
hub / github.com/coder/coder / newUpdateProxyResponseFormatter

Function newUpdateProxyResponseFormatter

enterprise/cli/workspaceproxy.go:433–469  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

431}
432
433func newUpdateProxyResponseFormatter() *updateProxyResponseFormatter {
434 up := &updateProxyResponseFormatter{
435 onlyToken: false,
436 }
437 up.formatter = cliui.NewOutputFormatter(
438 // Text formatter should be human readable.
439 cliui.ChangeFormatterData(cliui.TextFormat(), func(data any) (any, error) {
440 response, ok := data.(codersdk.UpdateWorkspaceProxyResponse)
441 if !ok {
442 return nil, xerrors.Errorf("unexpected type %T", data)
443 }
444
445 return fmt.Sprintf("Workspace Proxy %[1]q updated successfully.\n"+
446 pretty.Sprint(cliui.DefaultStyles.Placeholder, "—————————————————————————————————————————————————")+"\n"+
447 "Save this authentication token, it will not be shown again.\n"+
448 "Token: %[2]s\n"+
449 "\n"+
450 "Start the proxy by running:\n"+
451 cliui.Code("CODER_PROXY_SESSION_TOKEN=%[2]s coder wsproxy server --primary-access-url %[3]s --http-address=0.0.0.0:3001")+
452 // This is required to turn off the code style. Otherwise it appears in the code block until the end of the line.
453 pretty.Sprint(cliui.DefaultStyles.Placeholder, ""),
454 response.Proxy.Name, response.ProxyToken, up.primaryAccessURL), nil
455 }),
456 cliui.JSONFormat(),
457 // Table formatter expects a slice, make a slice of one.
458 cliui.ChangeFormatterData(cliui.TableFormat([]codersdk.UpdateWorkspaceProxyResponse{}, []string{"name", "url", "proxy token"}),
459 func(data any) (any, error) {
460 response, ok := data.(codersdk.UpdateWorkspaceProxyResponse)
461 if !ok {
462 return nil, xerrors.Errorf("unexpected type %T", data)
463 }
464 return []codersdk.UpdateWorkspaceProxyResponse{response}, nil
465 }),
466 )
467
468 return up
469}

Callers 2

regenerateProxyTokenMethod · 0.85
createProxyMethod · 0.85

Calls 7

NewOutputFormatterFunction · 0.92
ChangeFormatterDataFunction · 0.92
TextFormatFunction · 0.92
CodeFunction · 0.92
JSONFormatFunction · 0.92
TableFormatFunction · 0.92
ErrorfMethod · 0.45

Tested by

no test coverage detected