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

Method userCreate

cli/usercreate.go:18–228  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

16)
17
18func (r *RootCmd) userCreate() *serpent.Command {
19 var (
20 email string
21 username string
22 name string
23 password string
24 disableLogin bool
25 loginType string
26 serviceAccount bool
27 orgContext = NewOrganizationContext()
28 )
29 cmd := &serpent.Command{
30 Use: "create",
31 Short: "Create a new user.",
32 Middleware: serpent.Chain(
33 serpent.RequireNArgs(0),
34 ),
35 Handler: func(inv *serpent.Invocation) error {
36 if serviceAccount {
37 switch {
38 case loginType != "":
39 return xerrors.New("You cannot use --login-type with --service-account")
40 case password != "":
41 return xerrors.New("You cannot use --password with --service-account")
42 case email != "":
43 return xerrors.New("You cannot use --email with --service-account")
44 case disableLogin:
45 return xerrors.New("You cannot use --disable-login with --service-account")
46 }
47 }
48
49 if disableLogin && loginType != "" {
50 return xerrors.New("You cannot specify both --disable-login and --login-type")
51 }
52
53 client, err := r.InitClient(inv)
54 if err != nil {
55 return err
56 }
57
58 organization, err := orgContext.Selected(inv, client)
59 if err != nil {
60 return err
61 }
62 // We only prompt for the full name if both username and email have not
63 // been set. This is to avoid breaking existing non-interactive usage.
64 shouldPromptName := username == "" && email == ""
65 if username == "" {
66 username, err = cliui.Prompt(inv, cliui.PromptOptions{
67 Text: "Username:",
68 Validate: func(username string) error {
69 err = codersdk.NameValid(username)
70 if err != nil {
71 return xerrors.Errorf("username %q is invalid: %w", username, err)
72 }
73 return nil
74 },
75 })

Callers 1

usersMethod · 0.95

Calls 15

InitClientMethod · 0.95
PromptFunction · 0.92
NameValidFunction · 0.92
NormalizeRealUsernameFunction · 0.92
WarnfFunction · 0.92
LoginTypeTypeAlias · 0.92
StringCharsetFunction · 0.92
NewOrganizationContextFunction · 0.85
SelectedMethod · 0.80
CreateUserWithOrgsMethod · 0.80
NewMethod · 0.65
ContextMethod · 0.65

Tested by

no test coverage detected