Repository navigation
Expand file tree
/
Copy pathgroupcreate.go
More file actions
68 lines (58 loc) · 1.55 KB
/
Copy pathgroupcreate.go
File metadata and controls
68 lines (58 loc) · 1.55 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
package cli
import (
"fmt"
"golang.org/x/xerrors"
agpl "github.com/coder/coder/v2/cli"
"github.com/coder/coder/v2/cli/clibase"
"github.com/coder/coder/v2/cli/cliui"
"github.com/coder/coder/v2/codersdk"
"github.com/coder/pretty"
)
func (r *RootCmd) groupCreate() *clibase.Cmd {
var (
avatarURL string
displayName string
)
client := new(codersdk.Client)
cmd := &clibase.Cmd{
Use: "create <name>",
Short: "Create a user group",
Middleware: clibase.Chain(
clibase.RequireNArgs(1),
r.InitClient(client),
),
Handler: func(inv *clibase.Invocation) error {
ctx := inv.Context()
org, err := agpl.CurrentOrganization(inv, client)
if err != nil {
return xerrors.Errorf("current organization: %w", err)
}
group, err := client.CreateGroup(ctx, org.ID, codersdk.CreateGroupRequest{
Name: inv.Args[0],
DisplayName: displayName,
AvatarURL: avatarURL,
})
if err != nil {
return xerrors.Errorf("create group: %w", err)
}
_, _ = fmt.Fprintf(inv.Stdout, "Successfully created group %s!\n", pretty.Sprint(cliui.DefaultStyles.Keyword, group.Name))
return nil
},
}
cmd.Options = clibase.OptionSet{
{
Flag: "avatar-url",
Description: `Set an avatar for a group.`,
FlagShorthand: "u",
Env: "CODER_AVATAR_URL",
Value: clibase.StringOf(&avatarURL),
},
{
Flag: "display-name",
Description: `Optional human friendly name for the group.`,
Env: "CODER_DISPLAY_NAME",
Value: clibase.StringOf(&displayName),
},
}
return cmd
}