feat(codersdk): export name validators (#14551)

This commit is contained in:
Ethan
2024-09-04 18:34:39 +10:00
committed by GitHub
parent 01a904c133
commit 8f85464fe6
6 changed files with 59 additions and 135 deletions

View File

@ -30,6 +30,11 @@ func (r *RootCmd) createOrganization() *serpent.Command {
Handler: func(inv *serpent.Invocation) error {
orgName := inv.Args[0]
err := codersdk.NameValid(orgName)
if err != nil {
return xerrors.Errorf("organization name %q is invalid: %w", orgName, err)
}
// This check is not perfect since not all users can read all organizations.
// So ignore the error and if the org already exists, prevent the user
// from creating it.
@ -38,7 +43,7 @@ func (r *RootCmd) createOrganization() *serpent.Command {
return xerrors.Errorf("organization %q already exists", orgName)
}
_, err := cliui.Prompt(inv, cliui.PromptOptions{
_, err = cliui.Prompt(inv, cliui.PromptOptions{
Text: fmt.Sprintf("Are you sure you want to create an organization with the name %s?\n%s",
pretty.Sprint(cliui.DefaultStyles.Code, orgName),
pretty.Sprint(cliui.BoldFmt(), "This action is irreversible."),