MCPcopy Index your code
hub / github.com/coder/coder / groupCreate

Method groupCreate

enterprise/cli/groupcreate.go:15–86  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

13)
14
15func (r *RootCmd) groupCreate() *serpent.Command {
16 var (
17 avatarURL string
18 displayName string
19 orgContext = agpl.NewOrganizationContext()
20 )
21
22 cmd := &serpent.Command{
23 Use: "create <name>",
24 Short: "Create a user group",
25 Middleware: serpent.Chain(
26 serpent.RequireNArgs(1),
27 ),
28 Handler: func(inv *serpent.Invocation) error {
29 ctx := inv.Context()
30 client, err := r.InitClient(inv)
31 if err != nil {
32 return err
33 }
34
35 org, err := orgContext.Selected(inv, client)
36 if err != nil {
37 return xerrors.Errorf("current organization: %w", err)
38 }
39
40 err = codersdk.GroupNameValid(inv.Args[0])
41 if err != nil {
42 return xerrors.Errorf("group name %q is invalid: %w", inv.Args[0], err)
43 }
44
45 group, err := client.CreateGroup(ctx, org.ID, codersdk.CreateGroupRequest{
46 Name: inv.Args[0],
47 DisplayName: displayName,
48 AvatarURL: avatarURL,
49 })
50 if err != nil {
51 return xerrors.Errorf("create group: %w", err)
52 }
53
54 _, _ = fmt.Fprintf(inv.Stdout, "Successfully created group %s!\n", pretty.Sprint(cliui.DefaultStyles.Keyword, group.Name))
55 return nil
56 },
57 }
58
59 cmd.Options = serpent.OptionSet{
60 {
61 Flag: "avatar-url",
62 Description: `Set an avatar for a group.`,
63 FlagShorthand: "u",
64 Env: "CODER_AVATAR_URL",
65 Value: serpent.StringOf(&avatarURL),
66 },
67 {
68 Flag: "display-name",
69 Description: `Optional human friendly name for the group.`,
70 Env: "CODER_DISPLAY_NAME",
71 Value: serpent.Validate(serpent.StringOf(&displayName), func(_displayName *serpent.String) error {
72 displayName := _displayName.String()

Callers 1

groupsMethod · 0.95

Calls 10

InitClientMethod · 0.95
GroupNameValidFunction · 0.92
DisplayNameValidFunction · 0.92
SelectedMethod · 0.80
CreateGroupMethod · 0.80
ContextMethod · 0.65
ValidateMethod · 0.65
AttachOptionsMethod · 0.65
ErrorfMethod · 0.45
StringMethod · 0.45

Tested by

no test coverage detected