(app core.App)
| 70 | } |
| 71 | |
| 72 | func 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 | |
| 108 | func superuserUpdateCommand(app core.App) *cobra.Command { |
| 109 | command := &cobra.Command{ |
no test coverage detected
searching dependent graphs…