Skip to content

Commit 5e647ba

Browse files
authored
chore: improve workspace proxy create cli flow (#7907)
* chore: improve workspace proxy create cli flow
1 parent 26f575e commit 5e647ba

File tree

1 file changed

+47
-3
lines changed

1 file changed

+47
-3
lines changed

enterprise/cli/workspaceproxy.go

+47-3
Original file line numberDiff line numberDiff line change
@@ -208,6 +208,7 @@ func (r *RootCmd) createProxy() *clibase.Cmd {
208208
proxyName string
209209
displayName string
210210
proxyIcon string
211+
noPrompts bool
211212
formatter = newUpdateProxyResponseFormatter()
212213
)
213214

@@ -221,8 +222,43 @@ func (r *RootCmd) createProxy() *clibase.Cmd {
221222
),
222223
Handler: func(inv *clibase.Invocation) error {
223224
ctx := inv.Context()
225+
var err error
226+
if proxyName == "" && !noPrompts {
227+
proxyName, err = cliui.Prompt(inv, cliui.PromptOptions{
228+
Text: "Proxy Name:",
229+
})
230+
if err != nil {
231+
return err
232+
}
233+
}
234+
if displayName == "" && !noPrompts {
235+
displayName, err = cliui.Prompt(inv, cliui.PromptOptions{
236+
Text: "Display Name:",
237+
Default: proxyName,
238+
})
239+
if err != nil {
240+
return err
241+
}
242+
}
243+
244+
if proxyIcon == "" && !noPrompts {
245+
proxyIcon, err = cliui.Prompt(inv, cliui.PromptOptions{
246+
Text: "Icon URL:",
247+
Default: "/emojis/1f5fa.png",
248+
Validate: func(s string) error {
249+
if !(strings.HasPrefix(s, "/emojis/") || strings.HasPrefix(s, "http")) {
250+
return xerrors.New("icon must be a relative path to an emoji or a publicly hosted image URL")
251+
}
252+
return nil
253+
},
254+
})
255+
if err != nil {
256+
return err
257+
}
258+
}
259+
224260
if proxyName == "" {
225-
return xerrors.Errorf("proxy name is required")
261+
return xerrors.New("proxy name is required")
226262
}
227263

228264
resp, err := client.CreateWorkspaceProxy(ctx, codersdk.CreateWorkspaceProxyRequest{
@@ -260,6 +296,11 @@ func (r *RootCmd) createProxy() *clibase.Cmd {
260296
Description: "Display icon of the proxy.",
261297
Value: clibase.StringOf(&proxyIcon),
262298
},
299+
clibase.Option{
300+
Flag: "no-prompt",
301+
Description: "Disable all input prompting, and fail if any required flags are missing.",
302+
Value: clibase.BoolOf(&noPrompts),
303+
},
263304
)
264305
return cmd
265306
}
@@ -355,8 +396,11 @@ func newUpdateProxyResponseFormatter() *updateProxyResponseFormatter {
355396
if !ok {
356397
return nil, xerrors.Errorf("unexpected type %T", data)
357398
}
358-
return fmt.Sprintf("Workspace Proxy %q created successfully. Save this token, it will not be shown again."+
359-
"\nToken: %s", response.Proxy.Name, response.ProxyToken), nil
399+
400+
return fmt.Sprintf("Workspace Proxy %q updated successfully.\n"+
401+
cliui.DefaultStyles.Placeholder.Render("—————————————————————————————————————————————————")+"\n"+
402+
"Save this authentication token, it will not be shown again.\n"+
403+
"Token: %s\n", response.Proxy.Name, response.ProxyToken), nil
360404
}),
361405
cliui.JSONFormat(),
362406
// Table formatter expects a slice, make a slice of one.

0 commit comments

Comments
 (0)