MCPcopy
hub / github.com/pocketbase/pocketbase / superuserCreateCommand

Function superuserCreateCommand

cmd/superuser.go:72–106  ·  view source on GitHub ↗
(app core.App)

Source from the content-addressed store, hash-verified

70}
71
72func superuserCreateCommand(app core.App) *cobra.Command {
73 command := &cobra.Command{
74 Use: "create",
75 Example: "superuser create test@example.com 1234567890",
76 Short: "Creates a new superuser",
77 SilenceUsage: true,
78 RunE: func(command *cobra.Command, args []string) error {
79 if len(args) != 2 {
80 return errors.New("missing email and password arguments")
81 }
82
83 if args[0] == "" || is.EmailFormat.Validate(args[0]) != nil {
84 return errors.New("missing or invalid email address")
85 }
86
87 superusersCol, err := app.FindCachedCollectionByNameOrId(core.CollectionNameSuperusers)
88 if err != nil {
89 return fmt.Errorf("failed to fetch %q collection: %w", core.CollectionNameSuperusers, err)
90 }
91
92 superuser := core.NewRecord(superusersCol)
93 superuser.SetEmail(args[0])
94 superuser.SetPassword(args[1])
95
96 if err := app.Save(superuser); err != nil {
97 return fmt.Errorf("failed to create new superuser account: %w", err)
98 }
99
100 color.Green("Successfully created new superuser %q!", superuser.Email())
101 return nil
102 },
103 }
104
105 return command
106}
107
108func superuserUpdateCommand(app core.App) *cobra.Command {
109 command := &cobra.Command{

Callers 1

NewSuperuserCommandFunction · 0.85

Calls 7

SetEmailMethod · 0.95
SetPasswordMethod · 0.95
EmailMethod · 0.95
NewRecordFunction · 0.92
ValidateMethod · 0.65
SaveMethod · 0.65

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…