Skip to content

Commit f48843d

Browse files
committed
chore: Add run command example to wsproxy create
1 parent 4976787 commit f48843d

File tree

1 file changed

+31
-22
lines changed

1 file changed

+31
-22
lines changed

enterprise/cli/workspaceproxy.go

Lines changed: 31 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ func (r *RootCmd) regenerateProxyToken() *clibase.Cmd {
5151
),
5252
Handler: func(inv *clibase.Invocation) error {
5353
ctx := inv.Context()
54+
formatter.primaryAccessURL = client.URL.String()
5455
// This is cheeky, but you can also use a uuid string in
5556
// 'DeleteWorkspaceProxyByName' and it will work.
5657
proxy, err := client.WorkspaceProxyByName(ctx, inv.Args[0])
@@ -226,6 +227,7 @@ func (r *RootCmd) createProxy() *clibase.Cmd {
226227
),
227228
Handler: func(inv *clibase.Invocation) error {
228229
ctx := inv.Context()
230+
formatter.primaryAccessURL = client.URL.String()
229231
var err error
230232
if proxyName == "" && !noPrompts {
231233
proxyName, err = cliui.Prompt(inv, cliui.PromptOptions{
@@ -368,8 +370,9 @@ func (r *RootCmd) listProxies() *clibase.Cmd {
368370

369371
// updateProxyResponseFormatter is used for both create and regenerate proxy commands.
370372
type updateProxyResponseFormatter struct {
371-
onlyToken bool
372-
formatter *cliui.OutputFormatter
373+
onlyToken bool
374+
formatter *cliui.OutputFormatter
375+
primaryAccessURL string
373376
}
374377

375378
func (f *updateProxyResponseFormatter) Format(ctx context.Context, data codersdk.UpdateWorkspaceProxyResponse) (string, error) {
@@ -393,31 +396,37 @@ func (f *updateProxyResponseFormatter) AttachOptions(opts *clibase.OptionSet) {
393396
func newUpdateProxyResponseFormatter() *updateProxyResponseFormatter {
394397
up := &updateProxyResponseFormatter{
395398
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) {
399423
response, ok := data.(codersdk.UpdateWorkspaceProxyResponse)
400424
if !ok {
401425
return nil, xerrors.Errorf("unexpected type %T", data)
402426
}
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
408428
}),
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+
)
421430

422431
return up
423432
}

0 commit comments

Comments
 (0)