@@ -208,6 +208,7 @@ func (r *RootCmd) createProxy() *clibase.Cmd {
208
208
proxyName string
209
209
displayName string
210
210
proxyIcon string
211
+ noPrompts bool
211
212
formatter = newUpdateProxyResponseFormatter ()
212
213
)
213
214
@@ -221,8 +222,43 @@ func (r *RootCmd) createProxy() *clibase.Cmd {
221
222
),
222
223
Handler : func (inv * clibase.Invocation ) error {
223
224
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
+
224
260
if proxyName == "" {
225
- return xerrors .Errorf ("proxy name is required" )
261
+ return xerrors .New ("proxy name is required" )
226
262
}
227
263
228
264
resp , err := client .CreateWorkspaceProxy (ctx , codersdk.CreateWorkspaceProxyRequest {
@@ -260,6 +296,11 @@ func (r *RootCmd) createProxy() *clibase.Cmd {
260
296
Description : "Display icon of the proxy." ,
261
297
Value : clibase .StringOf (& proxyIcon ),
262
298
},
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
+ },
263
304
)
264
305
return cmd
265
306
}
@@ -355,8 +396,11 @@ func newUpdateProxyResponseFormatter() *updateProxyResponseFormatter {
355
396
if ! ok {
356
397
return nil , xerrors .Errorf ("unexpected type %T" , data )
357
398
}
358
- return fmt .Sprintf ("Workspace Proxy %q created successfully. Save this token, it will not be shown again." +
359
- "\n Token: %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
360
404
}),
361
405
cliui .JSONFormat (),
362
406
// Table formatter expects a slice, make a slice of one.
0 commit comments