Skip to content

feat: split cli roles edit command into create and update commands #17121

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 11 commits into from
Apr 4, 2025

Conversation

brettkolodny
Copy link
Contributor

@brettkolodny brettkolodny commented Mar 26, 2025

Closes #14239

@brettkolodny brettkolodny changed the title Brett 14239/refactor cli roles edit command feat: refactor the cli roles edit command into a create and update command Mar 26, 2025
@brettkolodny brettkolodny marked this pull request as ready for review April 1, 2025 18:54
@brettkolodny brettkolodny changed the title feat: refactor the cli roles edit command into a create and update command feat: split cli roles edit command into create and update commands Apr 1, 2025
Copy link
Member

@aslilac aslilac left a comment

Choose a reason for hiding this comment

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

I am not really knowledgable about this part of the codebase, but more knowledgable minds seem to be forfeiting their review jurisdiction. You added some tests, and the code seems coherent enough to me. ✅

arr := make([]json.RawMessage, 0)
err = json.Unmarshal(bytes, &arr)
if err == nil && len(arr) > 0 {
return xerrors.Errorf("the input appears to be an array, only 1 role can be sent at a time")
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
return xerrors.Errorf("the input appears to be an array, only 1 role can be sent at a time")
return xerrors.Errorf("only 1 role can be sent at a time")


var customRole codersdk.Role
if jsonInput {
// JSON Upload mode
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
// JSON Upload mode

I feel like the if already gives about as much context as this comment

interactiveRole, newRole, err := interactiveOrgRoleEdit(inv, org.ID, client)
role := existingRole(inv.Args[0], existingRoles)
if role == nil {
return xerrors.Errorf("The role %s does not exist exists. If you'd like to create this role use the create command instead", inv.Args[0])
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
return xerrors.Errorf("The role %s does not exist exists. If you'd like to create this role use the create command instead", inv.Args[0])
return xerrors.Errorf("The role %s does not exist. If you'd like to create this role use the create command instead", inv.Args[0])

}

if role := existingRole(customRole.Name, existingRoles); role == nil {
return xerrors.Errorf("The role %s does not exist exists. If you'd like to create this role use the create command instead", customRole.Name)
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
return xerrors.Errorf("The role %s does not exist exists. If you'd like to create this role use the create command instead", customRole.Name)
return xerrors.Errorf("The role %s does not exist. If you'd like to create this role use the create command instead", customRole.Name)

@brettkolodny brettkolodny requested a review from aslilac April 3, 2025 21:49
@brettkolodny brettkolodny merged commit ae7afd1 into main Apr 4, 2025
36 checks passed
@brettkolodny brettkolodny deleted the brett-14239/refactor-cli-roles-edit-command branch April 4, 2025 18:04
@github-actions github-actions bot locked and limited conversation to collaborators Apr 4, 2025
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.

Refactor cli editing custom roles to use create/update vs a singular edit
2 participants