mirror of
https://github.com/coder/coder.git
synced 2025-07-12 00:14:10 +00:00
feat(codersdk): export name validators (#14551)
This commit is contained in:
@ -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."),
|
||||
|
Reference in New Issue
Block a user