()
| 235 | } |
| 236 | |
| 237 | func (r *RootCmd) createProxy() *serpent.Command { |
| 238 | var ( |
| 239 | proxyName string |
| 240 | displayName string |
| 241 | proxyIcon string |
| 242 | noPrompts bool |
| 243 | formatter = newUpdateProxyResponseFormatter() |
| 244 | ) |
| 245 | validateIcon := func(s *serpent.String) error { |
| 246 | if !(strings.HasPrefix(s.Value(), "/emojis/") || strings.HasPrefix(s.Value(), "http")) { |
| 247 | return xerrors.New("icon must be a relative path to an emoji or a publicly hosted image URL") |
| 248 | } |
| 249 | return nil |
| 250 | } |
| 251 | |
| 252 | cmd := &serpent.Command{ |
| 253 | Use: "create", |
| 254 | Short: "Create a workspace proxy", |
| 255 | Middleware: serpent.Chain( |
| 256 | serpent.RequireNArgs(0), |
| 257 | ), |
| 258 | Handler: func(inv *serpent.Invocation) error { |
| 259 | ctx := inv.Context() |
| 260 | client, err := r.InitClient(inv) |
| 261 | if err != nil { |
| 262 | return err |
| 263 | } |
| 264 | formatter.primaryAccessURL = client.URL.String() |
| 265 | if proxyName == "" && !noPrompts { |
| 266 | proxyName, err = cliui.Prompt(inv, cliui.PromptOptions{ |
| 267 | Text: "Proxy Name:", |
| 268 | }) |
| 269 | if err != nil { |
| 270 | return err |
| 271 | } |
| 272 | } |
| 273 | if displayName == "" && !noPrompts { |
| 274 | displayName, err = cliui.Prompt(inv, cliui.PromptOptions{ |
| 275 | Text: "Display Name:", |
| 276 | Default: proxyName, |
| 277 | }) |
| 278 | if err != nil { |
| 279 | return err |
| 280 | } |
| 281 | } |
| 282 | |
| 283 | if proxyIcon == "" && !noPrompts { |
| 284 | proxyIcon, err = cliui.Prompt(inv, cliui.PromptOptions{ |
| 285 | Text: "Icon URL:", |
| 286 | Default: "/emojis/1f5fa.png", |
| 287 | Validate: func(s string) error { |
| 288 | return validateIcon(serpent.StringOf(&s)) |
| 289 | }, |
| 290 | }) |
| 291 | if err != nil { |
| 292 | return err |
| 293 | } |
| 294 | } |
no test coverage detected