mirror of
https://github.com/coder/coder.git
synced 2026-09-24 15:04:27 +08:00
feat(codersdk): export name validators (#14551)
This commit is contained in:
@@ -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)
|
||||
|
||||
Reference in New Issue
Block a user