Files
coder/enterprise/cli/groupcreate.go
T
Steven Masley 4c1e63aae8 feat: add display_name field to groups (#8740)
* feat: add display_name field to groups

This is a non-unique human friendly group name for display
purposes. This means a display name can be used instead of
using an environment var to remap groups with OIDC names to
Coder names. Now groups can retain the OIDC name for mapping,
and use a display name for display purposes.
2023-08-02 10:53:06 -05:00

68 lines
1.5 KiB
Go

package cli
import (
"fmt"
"golang.org/x/xerrors"
agpl "github.com/coder/coder/cli"
"github.com/coder/coder/cli/clibase"
"github.com/coder/coder/cli/cliui"
"github.com/coder/coder/codersdk"
)
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", cliui.DefaultStyles.Keyword.Render(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
}