-
Notifications
You must be signed in to change notification settings - Fork 894
feat: switch organization context in coder organizations #12265
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 1 commit
0c2cf56
c65ec35
ec35cf5
255bbe5
6244193
81d6a1e
b07765c
48947ec
887bcae
b34cdfe
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
- Loading branch information
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -66,21 +66,21 @@ func (r *RootCmd) switchOrganization() *clibase.Cmd { | |
return strings.Compare(a.Name, b.Name) | ||
}) | ||
|
||
var orgArg string | ||
var switchToOrg string | ||
if len(inv.Args) == 0 { | ||
// Pull orgArg from a prompt selector, rather than command line | ||
// Pull switchToOrg from a prompt selector, rather than command line | ||
// args. | ||
orgArg, err = promptUserSelectOrg(inv, conf, orgs) | ||
switchToOrg, err = promptUserSelectOrg(inv, conf, orgs) | ||
if err != nil { | ||
return err | ||
} | ||
} else { | ||
orgArg = inv.Args[0] | ||
switchToOrg = inv.Args[0] | ||
} | ||
|
||
// If the user passes an empty string, we want to remove the organization | ||
// from the config file. This will defer to default behavior. | ||
if orgArg == "" { | ||
if switchToOrg == "" { | ||
err := conf.Organization().Delete() | ||
if err != nil && !errors.Is(err, os.ErrNotExist) { | ||
return fmt.Errorf("failed to unset organization: %w", err) | ||
|
@@ -89,13 +89,13 @@ func (r *RootCmd) switchOrganization() *clibase.Cmd { | |
} else { | ||
// Find the selected org in our list. | ||
index := slices.IndexFunc(orgs, func(org codersdk.Organization) bool { | ||
return org.Name == orgArg || org.ID.String() == orgArg | ||
return org.Name == switchToOrg || org.ID.String() == switchToOrg | ||
}) | ||
if index < 0 { | ||
// Using this error for better error message formatting | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We should really have one for CLI errors too. (PS. There is There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yea we really should. I did not want to make a new one for this. exitError is a single line, this error format will display the helper text on a new line. |
||
err := &codersdk.Error{ | ||
Response: codersdk.Response{ | ||
Message: fmt.Sprintf("Organization %q not found. Is the name correct, and are you a member of it?", orgArg), | ||
Message: fmt.Sprintf("Organization %q not found. Is the name correct, and are you a member of it?", switchToOrg), | ||
Detail: "Ensure the organization argument is correct and you are a member of it.", | ||
}, | ||
Helper: fmt.Sprintf("Valid organizations you can switch to: %q", strings.Join(orgNames(orgs), ", ")), | ||
Emyrk marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It'd be nice if the currently selected one is highlighted in the list, perhaps? 🤔
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It is! But I read it only from the config file. I ignore the
CurrentOrganization
because that takes into account the-z
flag andis_default
.If a user has nothing set, I want the reset option to be selected.