@@ -2,15 +2,12 @@ package cli
2
2
3
3
import (
4
4
"fmt"
5
- "slices"
6
5
"strings"
7
6
8
7
"golang.org/x/xerrors"
9
8
10
9
"github.com/coder/coder/v2/cli/cliui"
11
- "github.com/coder/coder/v2/cli/config"
12
10
"github.com/coder/coder/v2/codersdk"
13
- "github.com/coder/pretty"
14
11
"github.com/coder/serpent"
15
12
)
16
13
@@ -37,76 +34,6 @@ func (r *RootCmd) organizations() *serpent.Command {
37
34
return cmd
38
35
}
39
36
40
- // promptUserSelectOrg will prompt the user to select an organization from a list
41
- // of their organizations.
42
- func promptUserSelectOrg (inv * serpent.Invocation , conf config.Root , orgs []codersdk.Organization ) (string , error ) {
43
- // Default choice
44
- var defaultOrg string
45
- // Comes from config file
46
- if conf .Organization ().Exists () {
47
- defaultOrg , _ = conf .Organization ().Read ()
48
- }
49
-
50
- // No config? Comes from default org in the list
51
- if defaultOrg == "" {
52
- defIndex := slices .IndexFunc (orgs , func (org codersdk.Organization ) bool {
53
- return org .IsDefault
54
- })
55
- if defIndex >= 0 {
56
- defaultOrg = orgs [defIndex ].Name
57
- }
58
- }
59
-
60
- // Defer to first org
61
- if defaultOrg == "" && len (orgs ) > 0 {
62
- defaultOrg = orgs [0 ].Name
63
- }
64
-
65
- // Ensure the `defaultOrg` value is an org name, not a uuid.
66
- // If it is a uuid, change it to the org name.
67
- index := slices .IndexFunc (orgs , func (org codersdk.Organization ) bool {
68
- return org .ID .String () == defaultOrg || org .Name == defaultOrg
69
- })
70
- if index >= 0 {
71
- defaultOrg = orgs [index ].Name
72
- }
73
-
74
- // deselectOption is the option to delete the organization config file and defer
75
- // to default behavior.
76
- const deselectOption = "[Default]"
77
- if defaultOrg == "" {
78
- defaultOrg = deselectOption
79
- }
80
-
81
- // Pull value from a prompt
82
- _ , _ = fmt .Fprintln (inv .Stdout , pretty .Sprint (cliui .DefaultStyles .Wrap , "Select an organization below to set the current CLI context to:" ))
83
- value , err := cliui .Select (inv , cliui.SelectOptions {
84
- Options : append ([]string {deselectOption }, orgNames (orgs )... ),
85
- Default : defaultOrg ,
86
- Size : 10 ,
87
- HideSearch : false ,
88
- })
89
- if err != nil {
90
- return "" , err
91
- }
92
- // Deselect is an alias for ""
93
- if value == deselectOption {
94
- value = ""
95
- }
96
-
97
- return value , nil
98
- }
99
-
100
- // orgNames is a helper function to turn a list of organizations into a list of
101
- // their names as strings.
102
- func orgNames (orgs []codersdk.Organization ) []string {
103
- names := make ([]string , 0 , len (orgs ))
104
- for _ , org := range orgs {
105
- names = append (names , org .Name )
106
- }
107
- return names
108
- }
109
-
110
37
func (r * RootCmd ) showOrganization (orgContext * OrganizationContext ) * serpent.Command {
111
38
var (
112
39
stringFormat func (orgs []codersdk.Organization ) (string , error )
0 commit comments