|
1 | 1 | package cmd |
2 | 2 |
|
3 | 3 | import ( |
4 | | - "github.com/manifoldco/promptui" |
| 4 | + "github.com/AlecAivazis/survey/v2" |
5 | 5 | "github.com/spf13/cobra" |
6 | 6 |
|
| 7 | + "github.com/hookdeck/hookdeck-cli/pkg/hookdeck" |
7 | 8 | "github.com/hookdeck/hookdeck-cli/pkg/validators" |
8 | 9 | "github.com/hookdeck/hookdeck-cli/pkg/workspace" |
9 | 10 | ) |
@@ -37,28 +38,41 @@ func (lc *workspaceUseCmd) runWorkspaceUseCmd(cmd *cobra.Command, args []string) |
37 | 38 | return err |
38 | 39 | } |
39 | 40 |
|
40 | | - selectedTemplate := "Selecting workspace {{ .Name | green }}" |
41 | | - if lc.local { |
42 | | - selectedTemplate = "Pinning workspace {{ .Name | green }} to current directory" |
| 41 | + var currentWorkspaceName string |
| 42 | + workspaceNames := make([]string, len(workspaces)) |
| 43 | + for index, workspace := range workspaces { |
| 44 | + workspaceNames[index] = workspace.Name |
| 45 | + if workspace.Id == Config.Profile.TeamID { |
| 46 | + currentWorkspaceName = workspace.Name |
| 47 | + } |
43 | 48 | } |
44 | 49 |
|
45 | | - templates := &promptui.SelectTemplates{ |
46 | | - Active: "▸ {{ .Name | green }}", |
47 | | - Inactive: " {{ .Name }}", |
48 | | - Selected: selectedTemplate, |
| 50 | + var qs = []*survey.Question{ |
| 51 | + { |
| 52 | + Name: "workspace_name", |
| 53 | + Prompt: &survey.Select{ |
| 54 | + Message: "Select Workspace", |
| 55 | + Options: workspaceNames, |
| 56 | + Default: currentWorkspaceName, |
| 57 | + }, |
| 58 | + Validate: survey.Required, |
| 59 | + }, |
49 | 60 | } |
50 | 61 |
|
51 | | - prompt := promptui.Select{ |
52 | | - Label: "Select Workspace", |
53 | | - Items: workspaces, |
54 | | - Templates: templates, |
55 | | - } |
| 62 | + answers := struct { |
| 63 | + WorkspaceName string `survey:"workspace_name"` |
| 64 | + }{} |
56 | 65 |
|
57 | | - i, _, err := prompt.Run() |
58 | | - if err != nil { |
| 66 | + if err = survey.Ask(qs, &answers); err != nil { |
59 | 67 | return err |
60 | 68 | } |
61 | 69 |
|
62 | | - workspace := workspaces[i] |
| 70 | + var workspace hookdeck.Workspace |
| 71 | + for _, tempWorkspace := range workspaces { |
| 72 | + if answers.WorkspaceName == tempWorkspace.Name { |
| 73 | + workspace = tempWorkspace |
| 74 | + } |
| 75 | + } |
| 76 | + |
63 | 77 | return Config.UseWorkspace(lc.local, workspace.Id, workspace.Mode) |
64 | 78 | } |
0 commit comments