Skip to content

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

Merged
merged 10 commits into from
Feb 26, 2024

Conversation

Emyrk
Copy link
Member

@Emyrk Emyrk commented Feb 21, 2024

Closes #11927:

Adds a coder org set to switch the org context.

coder org set

$ coder org set "steven-org"
Current organization context set to steven-org (9616b384-38bb-4284-861b-8db4fc337d6d)

$ coder org set not-real-org
Encountered an error running "coder organizations switch"
Organization "not-real-org" not found. Is the name correct, and are you a member of it?
Valid organizations you can switch to: "admin, steven-org, other-org"

$ coder org switch
Type to search

    --Deselect--
    admin
    bia-org
  > steven-org

Copy link
Member Author

Emyrk commented Feb 21, 2024

This stack of pull requests is managed by Graphite. Learn more about stacking.

Join @Emyrk and the rest of your teammates on Graphite Graphite

@Emyrk Emyrk force-pushed the stevenmasley/org_switch branch from 3106518 to 9a7aba6 Compare February 22, 2024 14:23
@Emyrk Emyrk force-pushed the stevenmasley/select-org branch from d4d20af to 1ac16cf Compare February 22, 2024 14:57
@Emyrk Emyrk force-pushed the stevenmasley/org_switch branch 2 times, most recently from 7142630 to b8ba53e Compare February 22, 2024 17:18
@Emyrk Emyrk marked this pull request as ready for review February 22, 2024 19:37
@Emyrk Emyrk requested a review from mafredri February 22, 2024 19:37
@Emyrk Emyrk changed the title feat: add coder organizations switch to change org context feat: switch organization context in coder organizations Feb 23, 2024
@Emyrk Emyrk mentioned this pull request Feb 23, 2024
Copy link
Member

@mafredri mafredri left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wouldn't say any of my comments are blockers, so I'm approving this.

This is a set of nice additions to the CLI!

if len(inv.Args) == 0 {
// Pull switchToOrg from a prompt selector, rather than command line
// args.
switchToOrg, err = promptUserSelectOrg(inv, conf, orgs)
Copy link
Member

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? 🤔

Copy link
Member Author

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 and is_default.

If a user has nothing set, I want the reset option to be selected.

return org.Name == switchToOrg || org.ID.String() == switchToOrg
})
if index < 0 {
// Using this error for better error message formatting
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should really have one for CLI errors too. (PS. There is exitError, but you might still prefer this approach.)

Copy link
Member Author

Choose a reason for hiding this comment

The 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.

}

// Verify it worked.
current, err := CurrentOrganization(r, inv, client)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we need to do this, considering we've fetched orgs and are writing the UUID, what could go wrong?

I mostly worry about increased execution time for the CLI command by additional API roundtrip.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I mainly added it because if you delete your selection, then this finds what the default is.

defaultOrg = orgs[index].Name
}

const deselectOption = "--Deselect--"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This could also be [Default] or the default could be highlighted (kylecarbs (Default)). The latter would have a semantic difference, though, as it would never deselect. Not sure we need to teach users the concept of deselecting an org vs using the default which is essentially what we're doing 🤔

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I like [Default] better than --Deselect--. It is an annoying concept to include, but it felt wrong to not add the option of "Idc, let it choose for me".

My fear was someone runs this command to see what it does, then they are locked into a decision and unable to revert.

@Emyrk Emyrk force-pushed the stevenmasley/org_switch branch 3 times, most recently from 6b3367a to 98666fd Compare February 23, 2024 17:12
Base automatically changed from stevenmasley/select-org to main February 26, 2024 16:03
@Emyrk Emyrk force-pushed the stevenmasley/org_switch branch from 1ac5298 to b34cdfe Compare February 26, 2024 16:30
@Emyrk Emyrk merged commit 70ccefc into main Feb 26, 2024
@Emyrk Emyrk deleted the stevenmasley/org_switch branch February 26, 2024 17:39
@github-actions github-actions bot locked and limited conversation to collaborators Feb 26, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

CLI Org support
2 participants