Created
January 22, 2026 17:04
-
-
Save ikr4-m/9594b90e263d354d14526bae847b2d69 to your computer and use it in GitHub Desktop.
Ghost CLI for Add User
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // Thanks joe-blocher for the code! | |
| // Source: https://forum.ghost.org/t/commandline-tool-to-create-user/53279 | |
| require('./current/core/server/models/role'); | |
| const UserModel = require('./current/core/server/models/user'); | |
| const {Command} = require('./current/node_modules/commander'); | |
| const program = new Command(); | |
| program.command('add') | |
| .description('Add a new user') | |
| .option('--name <name>', 'Name') | |
| .option('--email <email>', 'Email') | |
| .option('--password <password>', 'Password') | |
| .option('--role <role>', 'Role', 'Editor') | |
| .action(async (options) => { | |
| const {email, name, password, role} = options; | |
| try { | |
| await UserModel.User.add( | |
| { | |
| email, | |
| name, | |
| password, | |
| roles: [role], | |
| }, | |
| {} | |
| ); | |
| console.log('User added successfully.'); | |
| } catch (err) { | |
| console.error('Error adding user:', err); | |
| } | |
| process.exit(); | |
| }); | |
| program.parse(process.argv); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment