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

This commit is contained in:
Ethan
2024-09-04 08:34:39 +00:00
committed by GitHub
parent 01a904c133
commit 8f85464fe6
6 changed files with 59 additions and 135 deletions
+15 -1
View File
@@ -35,6 +35,11 @@ func (r *RootCmd) groupCreate() *serpent.Command {
return xerrors.Errorf("current organization: %w", err)
}
err = codersdk.GroupNameValid(inv.Args[0])
if err != nil {
return xerrors.Errorf("group name %q is invalid: %w", inv.Args[0], err)
}
group, err := client.CreateGroup(ctx, org.ID, codersdk.CreateGroupRequest{
Name: inv.Args[0],
DisplayName: displayName,
@@ -61,7 +66,16 @@ func (r *RootCmd) groupCreate() *serpent.Command {
Flag: "display-name",
Description: `Optional human friendly name for the group.`,
Env: "CODER_DISPLAY_NAME",
Value: serpent.StringOf(&displayName),
Value: serpent.Validate(serpent.StringOf(&displayName), func(_displayName *serpent.String) error {
displayName := _displayName.String()
if displayName != "" {
err := codersdk.DisplayNameValid(displayName)
if err != nil {
return xerrors.Errorf("group display name %q is invalid: %w", displayName, err)
}
}
return nil
}),
},
}
orgContext.AttachOptions(cmd)