From eefd36ecd1903e87e584257559ec56f76da7ed65 Mon Sep 17 00:00:00 2001 From: Steven Masley Date: Wed, 7 Jun 2023 12:06:34 -0500 Subject: [PATCH 1/2] chore: improve workspace proxy create cli flow --- enterprise/cli/workspaceproxy.go | 50 ++++++++++++++++++++++++++++++-- 1 file changed, 47 insertions(+), 3 deletions(-) diff --git a/enterprise/cli/workspaceproxy.go b/enterprise/cli/workspaceproxy.go index 4ab6f1aa9e051..923be3eba07a8 100644 --- a/enterprise/cli/workspaceproxy.go +++ b/enterprise/cli/workspaceproxy.go @@ -208,6 +208,7 @@ func (r *RootCmd) createProxy() *clibase.Cmd { proxyName string displayName string proxyIcon string + noPrompts bool formatter = newUpdateProxyResponseFormatter() ) @@ -221,8 +222,43 @@ func (r *RootCmd) createProxy() *clibase.Cmd { ), Handler: func(inv *clibase.Invocation) error { ctx := inv.Context() + var err error + if proxyName == "" && !noPrompts { + proxyName, err = cliui.Prompt(inv, cliui.PromptOptions{ + Text: "Proxy Name:", + }) + if err != nil { + return err + } + } + if displayName == "" && !noPrompts { + displayName, err = cliui.Prompt(inv, cliui.PromptOptions{ + Text: "Display Name:", + Default: proxyName, + }) + if err != nil { + return err + } + } + + if proxyIcon == "" && !noPrompts { + proxyIcon, err = cliui.Prompt(inv, cliui.PromptOptions{ + Text: "Icon URL:", + Default: "/emojis/1f5fa.png", + Validate: func(s string) error { + if !strings.HasPrefix(s, "/emojis/") { + return xerrors.New("icon must be a relative path to an emoji") + } + return nil + }, + }) + if err != nil { + return err + } + } + if proxyName == "" { - return xerrors.Errorf("proxy name is required") + return xerrors.New("proxy name is required") } resp, err := client.CreateWorkspaceProxy(ctx, codersdk.CreateWorkspaceProxyRequest{ @@ -260,6 +296,11 @@ func (r *RootCmd) createProxy() *clibase.Cmd { Description: "Display icon of the proxy.", Value: clibase.StringOf(&proxyIcon), }, + clibase.Option{ + Flag: "no-prompts", + Description: "Disable all input prompting, and fail if any required flags are missing.", + Value: clibase.BoolOf(&noPrompts), + }, ) return cmd } @@ -355,8 +396,11 @@ func newUpdateProxyResponseFormatter() *updateProxyResponseFormatter { if !ok { return nil, xerrors.Errorf("unexpected type %T", data) } - return fmt.Sprintf("Workspace Proxy %q created successfully. Save this token, it will not be shown again."+ - "\nToken: %s", response.Proxy.Name, response.ProxyToken), nil + + return fmt.Sprintf("Workspace Proxy %q updated successfully.\n"+ + cliui.DefaultStyles.Placeholder.Render("—————————————————————————————————————————————————")+"\n"+ + "Save this authentication token, it will not be shown again.\n"+ + "Token: %s\n", response.Proxy.Name, response.ProxyToken), nil }), cliui.JSONFormat(), // Table formatter expects a slice, make a slice of one. From b7b8515b9bacb8961c7f4929b25f28597e9cdbc6 Mon Sep 17 00:00:00 2001 From: Steven Masley Date: Thu, 8 Jun 2023 09:46:38 -0500 Subject: [PATCH 2/2] allow external images --- enterprise/cli/workspaceproxy.go | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/enterprise/cli/workspaceproxy.go b/enterprise/cli/workspaceproxy.go index 923be3eba07a8..134639231474b 100644 --- a/enterprise/cli/workspaceproxy.go +++ b/enterprise/cli/workspaceproxy.go @@ -246,8 +246,8 @@ func (r *RootCmd) createProxy() *clibase.Cmd { Text: "Icon URL:", Default: "/emojis/1f5fa.png", Validate: func(s string) error { - if !strings.HasPrefix(s, "/emojis/") { - return xerrors.New("icon must be a relative path to an emoji") + if !(strings.HasPrefix(s, "/emojis/") || strings.HasPrefix(s, "http")) { + return xerrors.New("icon must be a relative path to an emoji or a publicly hosted image URL") } return nil }, @@ -297,7 +297,7 @@ func (r *RootCmd) createProxy() *clibase.Cmd { Value: clibase.StringOf(&proxyIcon), }, clibase.Option{ - Flag: "no-prompts", + Flag: "no-prompt", Description: "Disable all input prompting, and fail if any required flags are missing.", Value: clibase.BoolOf(&noPrompts), },